From a10745cf0e4f21931bf7e441cd3b83cc12d96d35 Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Mon, 21 Sep 2015 13:30:35 +0200 Subject: [PATCH] Commitlog: Delay timer by period/ncpus for each cpu To avoid having all shards doing sync at the same time. --- db/commitlog/commitlog.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index 1c782dfba1..a58a371ad6 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -217,8 +217,8 @@ public: const replay_position& pos); void on_timer(); void sync(); - void arm() { - _timer.arm(std::chrono::milliseconds(cfg.commitlog_sync_period_in_ms)); + void arm(uint32_t extra = 0) { + _timer.arm(std::chrono::milliseconds(cfg.commitlog_sync_period_in_ms + extra)); } std::vector get_active_names() const; @@ -704,7 +704,9 @@ future<> db::commitlog::segment_manager::init() { _ids = replay_position(engine().cpu_id(), id).id; // always run the timer now, since we need to handle segment pre-alloc etc as well. _timer.set_callback(std::bind(&segment_manager::on_timer, this)); - this->arm(); + auto delay = engine().cpu_id() * std::ceil(double(cfg.commitlog_sync_period_in_ms) / smp::count); + logger.trace("Delaying timer loop {} ms", delay); + this->arm(delay); }); }