Skip to content

Commit 5147fa9

Browse files
authored
feat (server): add flag max_squashed_cmd_num (#4964)
Signed-off-by: adi_holden <adi@dragonflydb.io>
1 parent 707d7f0 commit 5147fa9

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/server/main_service.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ ABSL_FLAG(size_t, serialization_max_chunk_size, 64_KB,
115115
"Maximum size of a value that may be serialized at once during snapshotting or full "
116116
"sync. Values bigger than this threshold will be serialized using streaming "
117117
"serialization. 0 - to disable streaming mode");
118+
ABSL_FLAG(uint32_t, max_squashed_cmd_num, 32,
119+
"Max number of commands squashed in command squash optimizaiton");
118120

119121
namespace dfly {
120122

@@ -708,6 +710,11 @@ void SetSerializationMaxChunkSize(size_t val) {
708710
shard_set->pool()->AwaitBrief(cb);
709711
}
710712

713+
void SetMaxSquashedCmdNum(int32_t val) {
714+
auto cb = [val](unsigned, auto*) { ServerState::tlocal()->max_squash_cmd_num = val; };
715+
shard_set->pool()->AwaitBrief(cb);
716+
}
717+
711718
} // namespace
712719

713720
Service::Service(ProactorPool* pp)
@@ -787,6 +794,9 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
787794
[val](unsigned tid, auto*) { facade::Connection::SetPipelineBufferLimit(tid, val); });
788795
});
789796

797+
config_registry.RegisterSetter<uint32_t>("max_squashed_cmd_num",
798+
[](uint32_t val) { SetMaxSquashedCmdNum(val); });
799+
790800
config_registry.RegisterMutable("replica_partial_sync");
791801
config_registry.RegisterMutable("replication_timeout");
792802
config_registry.RegisterMutable("migration_finalization_timeout_ms");
@@ -857,6 +867,7 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
857867

858868
SetRssOomDenyRatioOnAllThreads(absl::GetFlag(FLAGS_rss_oom_deny_ratio));
859869
SetSerializationMaxChunkSize(absl::GetFlag(FLAGS_serialization_max_chunk_size));
870+
SetMaxSquashedCmdNum(absl::GetFlag(FLAGS_max_squashed_cmd_num));
860871

861872
// Requires that shard_set will be initialized before because server_family_.Init might
862873
// load the snapshot.
@@ -1429,9 +1440,13 @@ size_t Service::DispatchManyCommands(absl::Span<CmdArgList> args_list, SinkReply
14291440
}
14301441

14311442
dfly_cntx->transaction = dist_trans.get();
1443+
MultiCommandSquasher::Opts opts;
1444+
opts.verify_commands = true;
1445+
opts.max_squash_size = ss->max_squash_cmd_num;
1446+
14321447
size_t squashed_num = MultiCommandSquasher::Execute(absl::MakeSpan(stored_cmds),
14331448
static_cast<RedisReplyBuilder*>(builder),
1434-
dfly_cntx, this, {.verify_commands = true});
1449+
dfly_cntx, this, opts);
14351450
dfly_cntx->transaction = nullptr;
14361451

14371452
dispatched += stored_cmds.size();
@@ -1735,6 +1750,7 @@ optional<CapturingReplyBuilder::Payload> Service::FlushEvalAsyncCmds(ConnectionC
17351750
MultiCommandSquasher::Opts opts;
17361751
opts.verify_commands = true;
17371752
opts.error_abort = true;
1753+
opts.max_squash_size = ServerState::tlocal()->max_squash_cmd_num;
17381754
MultiCommandSquasher::Execute(absl::MakeSpan(info->async_cmds), &crb, cntx, this, opts);
17391755

17401756
info->async_cmds_heap_mem = 0;
@@ -2209,7 +2225,9 @@ void Service::Exec(CmdArgList args, const CommandContext& cmd_cntx) {
22092225

22102226
if (absl::GetFlag(FLAGS_multi_exec_squash) && state != ExecScriptUse::SCRIPT_RUN &&
22112227
!cntx->conn_state.tracking_info_.IsTrackingOn()) {
2212-
MultiCommandSquasher::Execute(absl::MakeSpan(exec_info.body), rb, cntx, this, {});
2228+
MultiCommandSquasher::Opts opts;
2229+
opts.max_squash_size = ServerState::tlocal()->max_squash_cmd_num;
2230+
MultiCommandSquasher::Execute(absl::MakeSpan(exec_info.body), rb, cntx, this, opts);
22132231
} else {
22142232
CmdArgVec arg_vec;
22152233
for (auto& scmd : exec_info.body) {

src/server/multi_command_squasher.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ MultiCommandSquasher::SquashResult MultiCommandSquasher::TrySquash(StoredCmd* cm
114114
if (keys->NumArgs() == 0)
115115
return SquashResult::NOT_SQUASHED;
116116

117-
// Check if all commands belong to one shard
117+
// Check if all command keys belong to one shard
118118
ShardId last_sid = kInvalidSid;
119119

120120
for (string_view key : keys->Range(args)) {

src/server/server_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class ServerState { // public struct - to allow initialization.
274274

275275
bool is_master = true;
276276
uint32_t log_slower_than_usec = UINT32_MAX;
277+
uint32_t max_squash_cmd_num = 32;
277278

278279
acl::UserRegistry* user_registry;
279280

0 commit comments

Comments
 (0)