diff --git a/.changelog/2494.feature.md b/.changelog/2494.feature.md new file mode 100644 index 00000000000..15ceb61af98 --- /dev/null +++ b/.changelog/2494.feature.md @@ -0,0 +1,5 @@ +Make maximum in-memory cache size for runtime storage configurable. + +Previously the value of 64mb was always used as the size of the in-memory storage cache. This adds a +new configuration parameter/command-line flag `--storage.max_cache_size` which configures the +maximum size of the in-memory runtime storage cache. diff --git a/go/storage/api/api.go b/go/storage/api/api.go index 6352753dfe9..cd7777d0b13 100644 --- a/go/storage/api/api.go +++ b/go/storage/api/api.go @@ -90,13 +90,17 @@ type Config struct { // Namespace is the namespace contained within the database. Namespace common.Namespace + + // MaxCacheSize is the maximum in-memory cache size for the database. + MaxCacheSize int64 } // ToNodeDB converts from a Config to a node DB Config. func (cfg *Config) ToNodeDB() *nodedb.Config { return &nodedb.Config{ - DB: cfg.DB, - Namespace: cfg.Namespace, + DB: cfg.DB, + Namespace: cfg.Namespace, + MaxCacheSize: cfg.MaxCacheSize, } } diff --git a/go/storage/init.go b/go/storage/init.go index 24b4e063f45..ff09b1f84dc 100644 --- a/go/storage/init.go +++ b/go/storage/init.go @@ -22,10 +22,15 @@ import ( const ( // CfgBackend configures the storage backend flag. - CfgBackend = "storage.backend" - cfgCrashEnabled = "storage.crash.enabled" + CfgBackend = "storage.backend" + // CfgLRUSlots configures the LRU apply lock slots. - CfgLRUSlots = "storage.root_cache.apply_lock_lru_slots" + CfgLRUSlots = "storage.root_cache.apply_lock_lru_slots" + + // CfgMaxCacheSize configures the maximum in-memory cache size. + CfgMaxCacheSize = "storage.max_cache_size" + + cfgCrashEnabled = "storage.crash.enabled" cfgInsecureSkipChecks = "storage.debug.insecure_skip_checks" ) @@ -48,6 +53,7 @@ func New( ApplyLockLRUSlots: uint64(viper.GetInt(CfgLRUSlots)), InsecureSkipChecks: viper.GetBool(cfgInsecureSkipChecks) && cmdFlags.DebugDontBlameOasis(), Namespace: namespace, + MaxCacheSize: int64(viper.GetSizeInBytes(CfgMaxCacheSize)), } var ( @@ -80,6 +86,7 @@ func init() { Flags.String(CfgBackend, database.BackendNameBadgerDB, "Storage backend") Flags.Bool(cfgCrashEnabled, false, "Enable the crashing storage wrapper") Flags.Int(CfgLRUSlots, 1000, "How many LRU slots to use for Apply call locks in the MKVS tree root cache") + Flags.String(CfgMaxCacheSize, "64mb", "Maximum in-memory cache size") Flags.Bool(cfgInsecureSkipChecks, false, "INSECURE: Skip known root checks") diff --git a/go/storage/mkvs/urkel/db/api/api.go b/go/storage/mkvs/urkel/db/api/api.go index 4911dcfca40..06d5183dacd 100644 --- a/go/storage/mkvs/urkel/db/api/api.go +++ b/go/storage/mkvs/urkel/db/api/api.go @@ -50,6 +50,9 @@ type Config struct { // Namespace is the namespace contained within the database. Namespace common.Namespace + + // MaxCacheSize is the maximum in-memory cache size for the database. + MaxCacheSize int64 } // NodeDB is the persistence layer used for persisting the in-memory tree. diff --git a/go/storage/mkvs/urkel/db/badger/badger.go b/go/storage/mkvs/urkel/db/badger/badger.go index e03f738057b..f88afbdeb9c 100644 --- a/go/storage/mkvs/urkel/db/badger/badger.go +++ b/go/storage/mkvs/urkel/db/badger/badger.go @@ -127,8 +127,7 @@ func New(cfg *api.Config) (api.NodeDB, error) { opts = opts.WithLogger(cmnBadger.NewLogAdapter(db.logger)) opts = opts.WithSyncWrites(!cfg.DebugNoFsync) opts = opts.WithCompression(options.None) - // Reduce cache size to 64 MiB as the default is 1 GiB. - opts = opts.WithMaxCacheSize(64 * 1024 * 1024) + opts = opts.WithMaxCacheSize(cfg.MaxCacheSize) var err error if db.db, err = badger.Open(opts); err != nil { diff --git a/go/storage/mkvs/urkel/interop/cmd/protocol_server.go b/go/storage/mkvs/urkel/interop/cmd/protocol_server.go index cc73f31c600..5aaac37af66 100644 --- a/go/storage/mkvs/urkel/interop/cmd/protocol_server.go +++ b/go/storage/mkvs/urkel/interop/cmd/protocol_server.go @@ -76,6 +76,7 @@ func doProtoServer(cmd *cobra.Command, args []string) { Signer: ident.NodeSigner, ApplyLockLRUSlots: 1, InsecureSkipChecks: false, + MaxCacheSize: 16 * 1024 * 1024, } backend, err := database.New(&storageCfg) if err != nil {