server: make index log back-off a bit more concise
This commit is contained in:
@ -29,6 +29,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -828,18 +829,15 @@ 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
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
auto sleep_duration{125ms};
|
||||||
while (indexer().is_running()) {
|
while (indexer().is_running()) {
|
||||||
std::this_thread::sleep_for(sleep_duration);
|
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
|
// Exponential backoff: doubling sleep duration up to 2s
|
||||||
if (sleep_duration < std::chrono::milliseconds(2000)) {
|
sleep_duration = std::min(sleep_duration * 2, 2000ms);
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user