-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Pruning to IAVL #158
Merged
Merged
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
bed4822
Memtree (#11)
mattkanwisher 23f0b99
Add version saving to in memory, and ability to flush to disk periodi…
mattkanwisher aef79a7
Add version saving to in memory, and ability to flush to disk periodi…
mattkanwisher 43d2409
Add version saving to in memory, and ability to flush to disk periodi…
mattkanwisher c6f7eee
initial changes
AdityaSripal 099ec05
more changes to nodedb
AdityaSripal 6dc8e62
fmt and some docs
AdityaSripal 6f51bea
move some pruning logic into nodedb
AdityaSripal 0e2a954
completed changes to nodedb
AdityaSripal a840877
initial updates to mutable_tree
AdityaSripal 86e8371
update tree.versions after pruning
AdityaSripal 6b3597a
fix most build errs and allow memDB to be disabled
AdityaSripal 8ea53a0
merge master
AdityaSripal bb45bf1
fix build errors and maintain backward compatibility
AdityaSripal bb129a9
only write to db if pruning opts allow it
AdityaSripal f01c63a
debugging...
AdityaSripal 78060fe
remove print statement
AdityaSripal 2f3502a
optimize deleteOrphans and fix final test errors
AdityaSripal bce37e3
lint
AdityaSripal 46d16a0
add brief design doc and small fix
AdityaSripal d244ed3
add basic pruning tests
AdityaSripal c5af5b9
change tests to use trees with random pruning parameters
AdityaSripal 2ab4609
quick fix
AdityaSripal e50b297
add edge case tests
AdityaSripal 0dc0769
current progress in testing
AdityaSripal dacbd97
fix bugs
AdityaSripal 5cf4558
fix merge
AdityaSripal 67f9e19
address initial comments
AdityaSripal b5d09a7
add replace/remove pruning tests. improve remove efficiency
AdityaSripal f4b9941
update bench_test
AdityaSripal 0a1f25e
add some more pruning options
AdityaSripal 097f2c5
add commas
AdityaSripal 7bf79c0
add pruning benchmark tests
AdityaSripal 48e714f
slightly more reasonable pruning benchmarks
AdityaSripal 67a4131
options refactor
AdityaSripal 6ed75ff
use benching options in benchmark tests
AdityaSripal 1a5311f
Apply suggestions from fede code review
AdityaSripal 54b2dac
tidy and remove unnecessary orphan
AdityaSripal 6383f8d
Merge branch 'aditya/pruning' of github.com:tendermint/iavl into adit…
AdityaSripal f1e117d
complete fede doc comments
AdityaSripal 9df04a4
fix merge
AdityaSripal 1e9bd2c
fix linter
AdityaSripal 46785c6
fix merge
AdityaSripal 9e8fde7
replace keys pruning tests
AdityaSripal fcc92e4
fix imports
AdityaSripal 7e10d5d
Update pruning_test.go
AdityaSripal b15162c
add DO results
AdityaSripal cb05738
Merge branch 'aditya/pruning' of github.com:tendermint/iavl into adit…
AdityaSripal 6367c2f
more pruning strategies
AdityaSripal 1772b7e
fix deleteVersionsFrom
AdityaSripal 4d67ccf
merge and version benchmarks
AdityaSripal 0fe8a80
add sdk benchmark results
AdityaSripal f661c70
fix tiny bug
AdityaSripal e833cf4
Merge branch 'master' into aditya/pruning
tac0turtle 1b74253
minor linting fixes
tac0turtle 529695f
Merge branch 'master' into aditya/pruning
tac0turtle fbdde5d
fix linting issues
tac0turtle 126ac73
Update PRUNING.md
tac0turtle 59317ba
fix test
tac0turtle 8b2dc94
Merge branch 'aditya/pruning' of https://github.com/tendermint/iavl i…
tac0turtle 84deb83
Add options validation
tnachen 533652c
Fix build
tnachen c529855
Fix linter
tnachen bbb6aa3
move pruning docs
tac0turtle 72d9cdd
Update pruning docs and tests
tnachen 9b3e944
Merge branch 'master' into aditya/pruning
tac0turtle a382f71
Fix build
tnachen 3da2290
Merge branch 'master' into aditya/pruning
tac0turtle 0b86aa0
errors: add some error handling (#199)
tac0turtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,4 @@ linters-settings: | |
# enabled-tags: | ||
# - performance | ||
# - style | ||
# - experimental | ||
# - experimental |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package benchmarks | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"runtime" | ||
"testing" | ||
|
||
db "github.com/tendermint/tm-db" | ||
) | ||
|
||
type pruningstrat struct { | ||
keepEvery, keepRecent int64 | ||
} | ||
|
||
// To test effect of pruning strategy, we must measure time to execute many blocks | ||
// Execute 30000 blocks with the given IAVL tree's pruning strategy | ||
func runBlockChain(b *testing.B, prefix string, keepEvery int64, keepRecent int64, keyLen, dataLen int) { | ||
// 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) | ||
} | ||
}() | ||
|
||
runtime.GC() | ||
|
||
// always initialize tree with goleveldb as snapshotDB and memDB as recentDB | ||
snapDB := db.NewDB("test", "goleveldb", dirName) | ||
defer snapDB.Close() | ||
|
||
var mem runtime.MemStats | ||
runtime.ReadMemStats(&mem) | ||
memSize := mem.Alloc | ||
//maxVersion := 0 | ||
var keys [][]byte | ||
for i := 0; i < 100; i++ { | ||
keys = append(keys, randBytes(keyLen)) | ||
} | ||
|
||
// reset timer after initialization logic | ||
b.ResetTimer() | ||
t, _ := prepareTree(b, snapDB, db.NewMemDB(), keepEvery, keepRecent, 5, keyLen, dataLen) | ||
|
||
// create 30000 versions | ||
for i := 0; i < 5000; i++ { | ||
// set 5 keys per version | ||
for j := 0; j < 5; j++ { | ||
index := rand.Int63n(100) | ||
t.Set(keys[index], randBytes(dataLen)) | ||
} | ||
_, _, err := t.SaveVersion() | ||
if err != nil { | ||
b.Errorf("Can't save version %d: %v", i, err) | ||
} | ||
|
||
// Pause timer to garbage-collect and remeasure memory usage | ||
b.StopTimer() | ||
runtime.GC() | ||
runtime.ReadMemStats(&mem) | ||
// update memSize if it has increased after saveVersion | ||
if memSize < mem.Alloc { | ||
memSize = mem.Alloc | ||
//maxVersion = i | ||
} | ||
b.StartTimer() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment to pause timer so we don't measure db-closing time Also, remove print statement comment |
||
//fmt.Printf("Maxmimum Memory usage was %0.2f MB at height %d\n", float64(memSize)/1000000, maxVersion) | ||
b.StopTimer() | ||
} | ||
|
||
func BenchmarkPruningStrategies(b *testing.B) { | ||
ps := []pruningstrat{ | ||
{1, 0}, // default pruning strategy | ||
{1, 1}, | ||
{0, 1}, // keep single recent version | ||
{100, 1}, | ||
{100, 5}, // simple pruning | ||
{5, 1}, | ||
{5, 2}, | ||
{10, 2}, | ||
{1000, 10}, // average pruning | ||
{1000, 1}, // extreme pruning | ||
{10000, 100}, // SDK pruning | ||
} | ||
for _, ps := range ps { | ||
ps := ps | ||
prefix := fmt.Sprintf("PruningStrategy{%d-%d}-KeyLen:%d-DataLen:%d", ps.keepEvery, ps.keepRecent, 16, 40) | ||
|
||
b.Run(prefix, func(sub *testing.B) { | ||
runBlockChain(sub, prefix, ps.keepEvery, ps.keepRecent, 16, 40) | ||
}) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
benchmarks/results/158-pruning/Adityas-MBP-pruning-results.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
goos: darwin | ||
goarch: amd64 | ||
pkg: github.com/tendermint/iavl/benchmarks | ||
BenchmarkPruningStrategies/PruningStrategy{1-0}-KeyLen:16-DataLen:40-8 1 2837806322 ns/op | ||
BenchmarkPruningStrategies/PruningStrategy{0-1}-KeyLen:16-DataLen:40-8 1 1124373981 ns/op | ||
BenchmarkPruningStrategies/PruningStrategy{100-1}-KeyLen:16-DataLen:40-8 1 1255040658 ns/op | ||
BenchmarkPruningStrategies/PruningStrategy{100-5}-KeyLen:16-DataLen:40-8 1 1459752743 ns/op | ||
PASS | ||
ok github.com/tendermint/iavl/benchmarks 12.375s |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a line somewhere how to reproduce the benchmarks?