Merge branch 'index-sleep-exp-backoff'

This commit is contained in:
Dirk-Jan C. Binnema
2025-06-30 21:49:48 +03:00

View File

@ -828,10 +828,18 @@ Server::Private::do_index(const Indexer::Config& conf)
{ {
StopWatch sw{"indexing"}; StopWatch sw{"indexing"};
indexer().start(conf); indexer().start(conf);
std::chrono::milliseconds sleep_duration(125); // initial 125ms
while (indexer().is_running()) { while (indexer().is_running()) {
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); std::this_thread::sleep_for(sleep_duration);
output_sexp(get_stats(indexer().progress(), "running"), output_sexp(get_stats(indexer().progress(), "running"),
Server::OutputFlags::Flush); 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);
}
}
} }
output_sexp(get_stats(indexer().progress(), "complete"), output_sexp(get_stats(indexer().progress(), "complete"),
Server::OutputFlags::Flush); Server::OutputFlags::Flush);