add badger as alternative state database #4859
Open
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.
Type of change
Description
BadgerDB was added as alternative for GolevelDB state database.
Choosing the better alternative for the GolevelDB was a goal of my research within the paper "A Journey Towards the Most Efficient State Database For Hyperledger Fabric":
This PR adds Badger because it showed better performance results in comparison with GolevelDB, Bbolt and RocksDB.
PR satisfies potential future items of the current Hyperledger Fabric Roadmap where the goal to replace the GolevelDB with faster database is mentioned.
Additional details
Detailed Hyperledger Fabric performance reports mentioned in the papers above are availiable here. They were made using Hyperledger Caliper tool. The tool was used to measure main performance metrics on HLF peer with default GolevelDB and integrated Badger, Bbolt and RocksDB. More measuring details are described in the aforementioned studies.
To demonstrate Badger's potential advantage over GolevelDB, go benchmarks were added to the packages leveldbhelper and badgerdbhelper respectively. The results measured locally show that Badger has better performance for "put" operations than GolevelDB. The output is:
GolevelDB
go test -benchmem -run=^$ -bench ^BenchmarkLevelDBHelper$ github.com/hyperledger/fabric/common/ledger/util/leveldbhelper goos: darwin goarch: arm64 pkg: github.com/hyperledger/fabric/common/ledger/util/leveldbhelper BenchmarkLevelDBHelper/get-leveldb-little-data-10 5452860 189.3 ns/op 108 B/op 4 allocs/op BenchmarkLevelDBHelper/put-leveldb-10 673 2768479 ns/op 248 B/op 3 allocs/op BenchmarkLevelDBHelper/put-leveldb-type-2-10 415 2560133 ns/op 204 B/op 3 allocs/op PASS ok github.com/hyperledger/fabric/common/ledger/util/leveldbhelper 7.145s
Badger
go test -benchmem -run=^$ -bench ^BenchmarkBadgerDBHelper$ github.com/hyperledger/fabric/common/ledger/util/badgerdbhelper goos: darwin goarch: arm64 pkg: github.com/hyperledger/fabric/common/ledger/util/badgerdbhelper BenchmarkBadgerDBHelper/get-badgerdb-little-data-10 1388515 727.7 ns/op 410 B/op 8 allocs/op BenchmarkBadgerDBHelper/put-badgerdb-10 207873 5808 ns/op 1408 B/op 37 allocs/op BenchmarkBadgerDBHelper/put-badgerdb-type-2-10 171474 7206 ns/op 1477 B/op 37 allocs/op PASS ok github.com/hyperledger/fabric/common/ledger/util/badgerdbhelper 13.984s
The changes were tested locally and with GitHub CI/CD.