-
Notifications
You must be signed in to change notification settings - Fork 273
Problem: production rocksdb configuration is not optimal #813
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
Merged
yihuang
merged 11 commits into
crypto-org-chain:release/v1.0.x
from
yihuang:tune-rocksdb-options
Jan 19, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4aef5fd
Problem: production rocksdb configuration is not optimal
892a725
Update Makefile
4eb27ae
remove rocksdb from niv
d50bbac
rocksdb options
4c090bb
update flake
ddc247b
fix build
c1bbebe
create_if_missing
67ec407
OptimizeLevelStyleCompaction and IncreaseParallelism
69cdd25
remove SetLevelCompactionDynamicLevelBytes and add BlockCache
ec5f771
fix integration test
7501c4d
comments
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 hidden or 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 hidden or 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,15 @@ | ||
//go:build !rocksdb | ||
// +build !rocksdb | ||
|
||
package cmd | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
func openDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) { | ||
dataDir := filepath.Join(rootDir, "data") | ||
return dbm.NewDB("application", backendType, dataDir) | ||
} |
This file contains hidden or 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,74 @@ | ||
//go:build rocksdb | ||
// +build rocksdb | ||
|
||
package cmd | ||
|
||
import ( | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/linxGnu/grocksdb" | ||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
func openDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) { | ||
dataDir := filepath.Join(rootDir, "data") | ||
if backendType == dbm.RocksDBBackend { | ||
// customize rocksdb options | ||
db, err := grocksdb.OpenDb(newRocksdbOptions(), filepath.Join(dataDir, "application.db")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ro := grocksdb.NewDefaultReadOptions() | ||
wo := grocksdb.NewDefaultWriteOptions() | ||
woSync := grocksdb.NewDefaultWriteOptions() | ||
woSync.SetSync(true) | ||
return dbm.NewRocksDBWithRawDB(db, ro, wo, woSync), nil | ||
} else { | ||
return dbm.NewDB("application", backendType, dataDir) | ||
} | ||
} | ||
|
||
func newRocksdbOptions() *grocksdb.Options { | ||
opts := grocksdb.NewDefaultOptions() | ||
opts.SetCreateIfMissing(true) | ||
opts.IncreaseParallelism(runtime.NumCPU()) | ||
opts.OptimizeLevelStyleCompaction(512 * 1024 * 1024) | ||
opts.SetTargetFileSizeMultiplier(2) | ||
|
||
// block based table options | ||
bbto := grocksdb.NewDefaultBlockBasedTableOptions() | ||
|
||
// 1G block cache | ||
bbto.SetBlockCache(grocksdb.NewLRUCache(1 << 30)) | ||
|
||
// larger block means smaller index and better compression ratio. | ||
bbto.SetBlockSize(32 * 1024) | ||
|
||
// http://rocksdb.org/blog/2021/12/29/ribbon-filter.html | ||
bbto.SetFilterPolicy(grocksdb.NewRibbonHybridFilterPolicy(9.9, 1)) | ||
|
||
// partition index | ||
// http://rocksdb.org/blog/2017/05/12/partitioned-index-filter.html | ||
bbto.SetIndexType(grocksdb.KTwoLevelIndexSearchIndexType) | ||
bbto.SetPartitionFilters(true) | ||
|
||
// hash index is better for iavl tree which mostly do point lookup. | ||
bbto.SetDataBlockIndexType(grocksdb.KDataBlockIndexTypeBinarySearchAndHash) | ||
|
||
opts.SetBlockBasedTableFactory(bbto) | ||
|
||
// in iavl tree, we almost always query existing keys | ||
opts.SetOptimizeFiltersForHits(true) | ||
|
||
// heavier compression option at bottommost level, | ||
// 110k dict bytes is default in zstd library, | ||
// train bytes is recommended to be set at 100x dict bytes. | ||
opts.SetBottommostCompression(grocksdb.ZSTDCompression) | ||
compressOpts := grocksdb.NewDefaultCompressionOptions() | ||
compressOpts.MaxDictBytes = 110 * 1024 | ||
compressOpts.Level = 12 | ||
opts.SetBottommostCompressionOptions(compressOpts, true) | ||
opts.SetBottommostCompressionOptionsZstdMaxTrainBytes(compressOpts.MaxDictBytes*100, true) | ||
return opts | ||
} | ||
yihuang marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.