Skip to content

Commit

Permalink
fix: Allows users to customize the KeysLimit value at server start (D…
Browse files Browse the repository at this point in the history
…iceDB#888)

Co-authored-by: Jyotinder Singh <[email protected]>
  • Loading branch information
vpsinghg and JyotinderSingh authored Oct 5, 2024
1 parent 5cd547b commit 66fe347
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
EvictAllKeysRandom = "allkeys-random"
EvictAllKeysLRU = "allkeys-lru"
EvictAllKeysLFU = "allkeys-lfu"

DefaultKeysLimit int = 200000000
)

var (
Expand All @@ -44,6 +46,8 @@ var (
FileLocation = utils.EmptyStr

InitConfigCmd = false

KeysLimit = DefaultKeysLimit
)

type Config struct {
Expand Down Expand Up @@ -114,7 +118,7 @@ var baseConfig = Config{
MaxMemory: 0,
EvictionPolicy: EvictAllKeysLFU,
EvictionRatio: 0.9,
KeysLimit: 200000000,
KeysLimit: DefaultKeysLimit,
AOFFile: "./dice-master.aof",
PersistenceEnabled: true,
WriteAOFOnCleanup: false,
Expand Down Expand Up @@ -293,6 +297,10 @@ func mergeFlagsWithConfig() {
if Port != DefaultPort {
DiceConfig.Server.Port = Port
}

if KeysLimit != DefaultKeysLimit {
DiceConfig.Server.KeysLimit = KeysLimit
}
}

// This function checks if the config file is present or not at ConfigFileLocation
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func init() {
flag.StringVar(&config.CustomConfigFilePath, "o", config.CustomConfigFilePath, "dir path to create the config file")
flag.StringVar(&config.FileLocation, "c", config.FileLocation, "file path of the config file")
flag.BoolVar(&config.InitConfigCmd, "init-config", false, "initialize a new config file")
flag.IntVar(&config.KeysLimit, "keys-limit", config.KeysLimit, "keys limit for the dice server. "+
"This flag controls the number of keys each shard holds at startup. You can multiply this number with the "+
"total number of shard threads to estimate how much memory will be required at system start up.")
flag.Parse()

config.SetupConfig()
Expand Down

0 comments on commit 66fe347

Please sign in to comment.