Skip to content

Commit 188081d

Browse files
authored
feat: improve target node latency during migration (#5715)
* feat: improve target node latency during migration
1 parent 0447ccc commit 188081d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/server/cluster/incoming_slot_migration.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "util/fibers/synchronization.h"
2020

2121
ABSL_DECLARE_FLAG(int, migration_finalization_timeout_ms);
22+
ABSL_FLAG(uint32_t, slot_migration_throttle_us, 0,
23+
"Incoming migration throttle time in us, we throttle every 100us of migration commands "
24+
"processing, 0 to disable. Recommended value is 20. Values more than 50 can "
25+
"significantly reduce migration speed.");
2226

2327
namespace dfly::cluster {
2428

@@ -60,6 +64,9 @@ class ClusterShardMigration {
6064
});
6165
JournalReader reader{source, 0};
6266
TransactionReader tx_reader;
67+
uint64_t last_sleep = fb2::ProactorBase::GetMonotonicTimeNs();
68+
69+
const uint64_t throttle_us = absl::GetFlag(FLAGS_slot_migration_throttle_us);
6370

6471
while (cntx->IsRunning()) {
6572
if (pause_) {
@@ -112,6 +119,13 @@ class ClusterShardMigration {
112119
break;
113120
}
114121
}
122+
if (throttle_us > 0) {
123+
// every 100us we do sleep for 20us to allow other commands to be processed
124+
if (uint64_t now = fb2::ProactorBase::GetMonotonicTimeNs(); now - last_sleep > 100000) {
125+
ThisFiber::SleepFor(std::chrono::microseconds(throttle_us));
126+
last_sleep = now;
127+
}
128+
}
115129
}
116130

117131
VLOG(2) << "Flow " << source_shard_id_ << " canceled";

src/server/main_service.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
886886
config_registry.RegisterMutable("replica_partial_sync");
887887
config_registry.RegisterMutable("replication_timeout");
888888
config_registry.RegisterMutable("migration_finalization_timeout_ms");
889+
config_registry.RegisterMutable("slot_migration_throttle_us");
889890
config_registry.RegisterMutable("table_growth_margin");
890891
config_registry.RegisterMutable("tcp_keepalive");
891892
config_registry.RegisterMutable("timeout");

0 commit comments

Comments
 (0)