From e647ca924d892d365ec51b98571032716c0743f1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 30 Jun 2025 21:47:52 +0300 Subject: [PATCH] server: make index log back-off a bit more concise --- lib/mu-server.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/mu-server.cc b/lib/mu-server.cc index affacd59..13fb63c9 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -828,18 +829,15 @@ Server::Private::do_index(const Indexer::Config& conf) { StopWatch sw{"indexing"}; indexer().start(conf); - std::chrono::milliseconds sleep_duration(125); // initial 125ms + + using namespace std::chrono_literals; + auto sleep_duration{125ms}; while (indexer().is_running()) { std::this_thread::sleep_for(sleep_duration); output_sexp(get_stats(indexer().progress(), "running"), Server::OutputFlags::Flush); // Exponential backoff: doubling sleep duration up to 2s - if (sleep_duration < std::chrono::milliseconds(2000)) { - sleep_duration *= 2; - if (sleep_duration > std::chrono::milliseconds(2000)) { - sleep_duration = std::chrono::milliseconds(2000); - } - } + sleep_duration = std::min(sleep_duration * 2, 2000ms); } output_sexp(get_stats(indexer().progress(), "complete"), Server::OutputFlags::Flush);