diff --git a/sei-db/config/ss_config.go b/sei-db/config/ss_config.go index 3fe94e750d..8092a75831 100644 --- a/sei-db/config/ss_config.go +++ b/sei-db/config/ss_config.go @@ -4,13 +4,14 @@ package config type DBBackend string const ( - DefaultSSKeepRecent = 100000 - DefaultSSPruneInterval = 600 - DefaultSSImportWorkers = 1 - DefaultSSAsyncBuffer = 100 - PebbleDBBackend = "pebbledb" - RocksDBBackend = "rocksdb" - DefaultSSBackend = PebbleDBBackend + DefaultSSKeepRecent = 100000 + DefaultSSPruneInterval = 600 + DefaultSSImportWorkers = 1 + DefaultSSAsyncBuffer = 100 + PebbleDBBackend = "pebbledb" + RocksDBBackend = "rocksdb" + DefaultSSBackend = PebbleDBBackend + DefaultSSCacheSizeBytes = 32 * 1024 * 1024 ) // StateStoreConfig defines configuration for the state store (SS) layer. @@ -76,6 +77,13 @@ type StateStoreConfig struct { // When true, data is routed to separate DBs by EVM key family while // preserving the same logical store key and full key encoding inside each DB. SeparateEVMSubDBs bool `mapstructure:"evm-separate-dbs"` + + // CacheSizeBytes defines the pebbledb block cache size (in bytes) for the + // state store backend. Historical reads (e.g. eth debug_trace*, archival + // queries) are served from the SS backend rather than memIAVL, so a larger + // cache reduces disk-bound random reads. Set <= 0 to use the default. + // defaults to 32 MiB + CacheSizeBytes int64 `mapstructure:"cache-size-bytes"` } // DefaultStateStoreConfig returns the default StateStoreConfig @@ -91,5 +99,6 @@ func DefaultStateStoreConfig() StateStoreConfig { UseDefaultComparer: false, EVMSplit: false, SeparateEVMSubDBs: false, + CacheSizeBytes: DefaultSSCacheSizeBytes, } } diff --git a/sei-db/config/toml.go b/sei-db/config/toml.go index 3d210108e4..b1bcfdc0b1 100644 --- a/sei-db/config/toml.go +++ b/sei-db/config/toml.go @@ -140,6 +140,12 @@ evm-ss-split = {{ .StateStore.EVMSplit }} # When false, all EVM data stays in one DB using the current unified layout. # When true, data is routed to separate DBs while preserving the same evm key prefix format. evm-ss-separate-dbs = {{ .StateStore.SeparateEVMSubDBs }} + +# CacheSizeBytes defines the pebbledb block cache size (in bytes) for the state store. +# Historical reads (e.g. eth debug_trace*, archival queries) are served from the SS +# backend rather than memIAVL, so a larger cache reduces disk-bound random reads. +# Set <= 0 to use the default. Defaults to 33554432 (32 MiB). +ss-cache-size-bytes = {{ .StateStore.CacheSizeBytes }} ` // ReceiptStoreConfigTemplate defines the configuration template for receipt-store diff --git a/sei-db/db_engine/pebbledb/mvcc/db.go b/sei-db/db_engine/pebbledb/mvcc/db.go index 95d0ebb1b2..c95005c923 100644 --- a/sei-db/db_engine/pebbledb/mvcc/db.go +++ b/sei-db/db_engine/pebbledb/mvcc/db.go @@ -23,7 +23,7 @@ import ( errorutils "github.com/sei-protocol/sei-chain/sei-db/common/errors" "github.com/sei-protocol/sei-chain/sei-db/common/utils" - "github.com/sei-protocol/sei-chain/sei-db/config" + seidbconfig "github.com/sei-protocol/sei-chain/sei-db/config" "github.com/sei-protocol/sei-chain/sei-db/db_engine/types" "github.com/sei-protocol/sei-chain/sei-db/proto" "github.com/sei-protocol/sei-chain/sei-db/wal" @@ -60,7 +60,7 @@ var ( type Database struct { storage *pebble.DB asyncWriteWG sync.WaitGroup - config config.StateStoreConfig + config seidbconfig.StateStoreConfig // Earliest version for db after pruning earliestVersion atomic.Int64 // Latest version for db @@ -92,8 +92,12 @@ type VersionedChangesets struct { Done chan struct{} // non-nil for barrier: closed when this entry is processed } -func OpenDB(dataDir string, config config.StateStoreConfig) (types.StateStore, error) { - cache := pebble.NewCache(1024 * 1024 * 32) +func OpenDB(dataDir string, config seidbconfig.StateStoreConfig) (types.StateStore, error) { + cacheSizeBytes := config.CacheSizeBytes + if cacheSizeBytes <= 0 { + cacheSizeBytes = seidbconfig.DefaultSSCacheSizeBytes + } + cache := pebble.NewCache(cacheSizeBytes) defer cache.Unref() // Select comparer based on config. Note: UseDefaultComparer is NOT backwards compatible