Skip to content

Commit

Permalink
allow reactivity features to be toggled with flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh committed Oct 21, 2024
1 parent 846cef3 commit 02466c4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (
KeysLimit = DefaultKeysLimit

EnableProfiling = false

EnableWatch = true
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion dice.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Enabled = true
Port = 8379

[Performance]
WatchChanBufSize = 20000
WatchChanBufSize = 20000000
ShardCronFrequency = 1000000000
MultiplexerPollTimeout = 100000000
MaxClients = 20000
Expand Down
13 changes: 8 additions & 5 deletions internal/server/resp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ func (s *Server) Run(ctx context.Context) (err error) {
errChan := make(chan error, 1)
wg := &sync.WaitGroup{}

wg.Add(2)
go func() {
defer wg.Done()
s.watchManager.Run(ctx, s.cmdWatchChan)
}()
if s.cmdWatchChan != nil {
wg.Add(1)
go func() {
defer wg.Done()
s.watchManager.Run(ctx, s.cmdWatchChan)
}()
}

wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
if err := s.AcceptConnectionRequests(ctx, wg); err != nil {
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func init() {
"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.BoolVar(&config.EnableProfiling, "enable-profiling", false, "enable profiling for the dicedb server")
flag.BoolVar(&config.EnableWatch, "enable-watch", false, "enable reactivity features which power the .WATCH commands")

flag.Parse()

config.SetupConfig()
Expand All @@ -60,8 +62,14 @@ func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)

queryWatchChan := make(chan dstore.QueryWatchEvent, config.DiceConfig.Performance.WatchChanBufSize)
cmdWatchChan := make(chan dstore.CmdWatchEvent, config.DiceConfig.Memory.KeysLimit)
var queryWatchChan chan dstore.QueryWatchEvent = nil
var cmdWatchChan chan dstore.CmdWatchEvent = nil

if config.EnableWatch {
queryWatchChan = make(chan dstore.QueryWatchEvent, config.DiceConfig.Performance.WatchChanBufSize)
cmdWatchChan = make(chan dstore.CmdWatchEvent, config.DiceConfig.Performance.WatchChanBufSize)
}

var serverErrCh chan error

// Get the number of available CPU cores on the machine using runtime.NumCPU().
Expand Down

0 comments on commit 02466c4

Please sign in to comment.