-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: production rocksdb configuration is not optimal (#813)
* Problem: production rocksdb configuration is not optimal Solution: - update related dependencies to allow customize rocksdb options. - especially using rocksdb v7. - tune rocksdb options. * Update Makefile Signed-off-by: yihuang <huang@crypto.com> * remove rocksdb from niv * rocksdb options * update flake * fix build * create_if_missing * OptimizeLevelStyleCompaction and IncreaseParallelism * remove SetLevelCompactionDynamicLevelBytes and add BlockCache * fix integration test * comments Signed-off-by: yihuang <huang@crypto.com>
- Loading branch information
Showing
13 changed files
with
220 additions
and
84 deletions.
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
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,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 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 | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.