Skip to content
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

WIP: Introduce Pruning to IAVL #151

Closed
wants to merge 24 commits into from

Conversation

AdityaSripal
Copy link
Member

@AdityaSripal AdityaSripal commented Jul 10, 2019

Introduces notion of pruning to IAVL. MutableTree has keepRecent and keepEvery fields. Recent versions get saved in memDB while snapshot versions get saved to levelDB. For more details see:
#144 (comment)

Based off Loom PR (#150).

mattkanwisher and others added 8 commits July 2, 2019 16:22
Storing intermidiary IAVL versions in memory and not to disk

Motivation: Both Cosmos and Loom Network save an IAVL version per block, then go back and delete these versions. So you have constant churn on the IAVL and underlying Leveldb database. When realistically what you want is to only store every X Blocks.

At Berlin Tendermint Conference, Zaki and I surmised a plan where new versions are in memory, while still pointing back to nodes on disk to prevent needing to load entire IAVL into main memory. Loom IAVL tree is around 256gb so this is not feasible otherwise.


Usage

OLD Code would be like

```go
hash, version, err := s.tree.SaveVersion()
```

New Caller code would look like

```go
	oldVersion := s.Version()
  	var version int64
 	var hash []byte
 	//Every X versions we should persist to disk
 	if s.flushInterval == 0 || ((oldVersion+1)%s.flushInterval == 0) {
 		if s.flushInterval != 0 {
 			log.Error(fmt.Sprintf("Flushing mem to disk at version %d\n", oldVersion+1))
 			hash, version, err = s.tree.FlushMemVersionDisk()
 		} else {
 			hash, version, err = s.tree.SaveVersion()
 		}
 	} else {
 		hash, version, err = s.tree.SaveVersionMem()
 	}
```

FlushMemVersionDisk:
Flushes the current memory version to disk

SaveVersionMem:
Saves the current tree to memory instead of disk and gives you back an apphash

This is an opt in feature, you have to call new apis to get it. 
We also have a PR that demonstrates its usage https://github.com/loomnetwork/loomchain/pull/1232/files

We are now commiting every 1000 blocks, so we store 1000x less. Also we have signficant improves in IO at least double from not having to Prune old versions of the IAVL Tree
@AdityaSripal
Copy link
Member Author

TODO: Move all pruning logic out of mutableTree and into nodedb

@AdityaSripal AdityaSripal changed the title Introduce Pruning to IAVL WIP: Introduce Pruning to IAVL Jul 11, 2019
@tac0turtle tac0turtle changed the base branch from master to develop July 11, 2019 06:42
@tac0turtle
Copy link
Member

Had to change base branch to develop as we haven't nuked develop yet on this repo. Once we get this done, then will move base back to master

@tac0turtle tac0turtle changed the base branch from develop to master July 12, 2019 09:50
@AdityaSripal
Copy link
Member Author

AdityaSripal commented Jul 12, 2019

TODO:

  • Write up doc explaining design choices and expected behaviour
  • Fix any incorrect godocs. Explain how pruning affects each function
  • Lots more testing on nodeDB functionality, pruning tests in general (nodeDB, mutable_tree)
  • Benchmarks for various pruning strategy (Default: {keepEvery: 1, keepRecent: 0}, NoSnapshot: {keepEvery: 0, keepRecent: 100}, Snapshotting: {keepEvery: 10000, keepRecent: 100}, RandomPruning)

@AdityaSripal
Copy link
Member Author

Closing to create in-org branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants