Skip to content

Commit

Permalink
remove pruning (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker authored Jun 24, 2020
1 parent a41a83e commit bb7cd9c
Show file tree
Hide file tree
Showing 36 changed files with 179 additions and 3,395 deletions.
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ fullbench:
go test $(LDFLAGS) -timeout=60m -bench=LevelDB .
.PHONY: fullbench

benchprune:
cd benchmarks && \
go test -bench=PruningStrategies -timeout=24h
.PHONY: benchprune

# note that this just profiles the in-memory version, not persistence
profile:
cd benchmarks && \
Expand Down
74 changes: 36 additions & 38 deletions benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
db "github.com/tendermint/tm-db"
)

const historySize = 20

func randBytes(length int) []byte {
key := make([]byte, length)
// math.rand.Read always returns err=nil
Expand All @@ -22,8 +24,8 @@ func randBytes(length int) []byte {
return key
}

func prepareTree(b *testing.B, snapdb db.DB, memdb db.DB, keepEvery int64, keepRecent int64, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
t, err := iavl.NewMutableTreeWithOpts(snapdb, memdb, size, iavl.PruningOptions(keepEvery, keepRecent))
func prepareTree(b *testing.B, db db.DB, size, keyLen, dataLen int) (*iavl.MutableTree, [][]byte) {
t, err := iavl.NewMutableTreeWithOpts(db, size, nil)
require.NoError(b, err)
keys := make([][]byte, size)

Expand All @@ -37,15 +39,22 @@ func prepareTree(b *testing.B, snapdb db.DB, memdb db.DB, keepEvery int64, keepR
return t, keys
}

// commit tree saves a new version according to pruning strategy passed into IAVL
// commit tree saves a new version and deletes old ones according to historySize
func commitTree(b *testing.B, t *iavl.MutableTree) {
t.Hash()

_, _, err := t.SaveVersion() //this will flush for us every so often
_, version, err := t.SaveVersion()

if err != nil {
b.Errorf("Can't save: %v", err)
}

if version > historySize {
err = t.DeleteVersion(version - historySize)
if err != nil {
b.Errorf("Can't delete: %v", err)
}
}
}

func runQueries(b *testing.B, t *iavl.MutableTree, keyLen int) {
Expand Down Expand Up @@ -217,40 +226,29 @@ func BenchmarkLevelDBLargeData(b *testing.B) {

func runBenchmarks(b *testing.B, benchmarks []benchmark) {
fmt.Printf("%s\n", iavl.GetVersionInfo())
pruningStrategies := []pruningstrat{
{1, 0}, // default pruning strategy
{0, 1}, // keep single recent version
{100, 5}, // simple pruning
{1000, 10}, // average pruning
{1000, 1}, // extreme pruning
{10000, 100}, // SDK pruning
}
for _, ps := range pruningStrategies {
ps := ps
for _, bb := range benchmarks {
bb := bb
prefix := fmt.Sprintf("%s-%d-%d-%d-%d-%d-%d", bb.dbType, ps.keepEvery, ps.keepRecent,
bb.initSize, bb.blockSize, bb.keyLen, bb.dataLen)

// prepare a dir for the db and cleanup afterwards
dirName := fmt.Sprintf("./%s-db", prefix)
defer func() {
err := os.RemoveAll(dirName)
if err != nil {
b.Errorf("%+v\n", err)
}
}()

// note that "" leads to nil backing db!
var d db.DB
if bb.dbType != "nodb" {
d = db.NewDB("test", bb.dbType, dirName)
defer d.Close()
for _, bb := range benchmarks {
bb := bb
prefix := fmt.Sprintf("%s-%d-%d-%d-%d", bb.dbType,
bb.initSize, bb.blockSize, bb.keyLen, bb.dataLen)

// prepare a dir for the db and cleanup afterwards
dirName := fmt.Sprintf("./%s-db", prefix)
defer func() {
err := os.RemoveAll(dirName)
if err != nil {
b.Errorf("%+v\n", err)
}
b.Run(prefix, func(sub *testing.B) {
runSuite(sub, d, ps.keepEvery, ps.keepRecent, bb.initSize, bb.blockSize, bb.keyLen, bb.dataLen)
})
}()

// note that "" leads to nil backing db!
var d db.DB
if bb.dbType != "nodb" {
d = db.NewDB("test", bb.dbType, dirName)
defer d.Close()
}
b.Run(prefix, func(sub *testing.B) {
runSuite(sub, d, bb.initSize, bb.blockSize, bb.keyLen, bb.dataLen)
})
}
}

Expand All @@ -263,12 +261,12 @@ func memUseMB() float64 {
return mb
}

func runSuite(b *testing.B, d db.DB, keepEvery int64, keepRecent int64, initSize, blockSize, keyLen, dataLen int) {
func runSuite(b *testing.B, d db.DB, initSize, blockSize, keyLen, dataLen int) {
// measure mem usage
runtime.GC()
init := memUseMB()

t, keys := prepareTree(b, d, db.NewMemDB(), keepEvery, keepRecent, initSize, keyLen, dataLen)
t, keys := prepareTree(b, d, initSize, keyLen, dataLen)
used := memUseMB() - init
fmt.Printf("Init Tree took %0.2f MB\n", used)

Expand Down
98 changes: 0 additions & 98 deletions benchmarks/prune_test.go

This file was deleted.

This file was deleted.

147 changes: 0 additions & 147 deletions benchmarks/results/158-pruning/Adityas-MBP-results.txt

This file was deleted.

Loading

0 comments on commit bb7cd9c

Please sign in to comment.