Skip to content

Commit

Permalink
go/storage: Make maximum in-memory storage cache size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Dec 28, 2019
1 parent dbb0c72 commit 7c3866a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changelog/2494.feature.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions go/storage/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
13 changes: 10 additions & 3 deletions go/storage/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 (
Expand Down Expand Up @@ -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")

Expand Down
3 changes: 3 additions & 0 deletions go/storage/mkvs/urkel/db/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions go/storage/mkvs/urkel/db/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions go/storage/mkvs/urkel/interop/cmd/protocol_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7c3866a

Please sign in to comment.