diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 6cba4f23..457445d5 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -13,6 +13,7 @@ nano::request_aggregator::request_aggregator (nano::network_constants const & ne max_delay (network_constants_a.is_test_network () ? 50 : 300), small_delay (network_constants_a.is_test_network () ? 10 : 50), max_channel_requests (config_a.max_queued_requests), +max_consecutive_requests (network_constants_a.is_test_network () ? 1 : 10), stats (stats_a), votes_cache (cache_a), store (store_a), @@ -70,6 +71,7 @@ void nano::request_aggregator::run () lock.unlock (); condition.notify_all (); lock.lock (); + unsigned consecutive_requests = 0; while (!stopped) { if (!requests.empty ()) @@ -91,17 +93,26 @@ void nano::request_aggregator::run () lock.unlock (); // Generate votes for the remaining hashes generate (transaction, std::move (remaining), channel); + consecutive_requests = 0; + lock.lock (); + } + else if (++consecutive_requests == max_consecutive_requests) + { + lock.unlock (); + consecutive_requests = 0; lock.lock (); } } else { + consecutive_requests = 0; auto deadline = front->deadline; condition.wait_until (lock, deadline, [this, &deadline]() { return this->stopped || deadline < std::chrono::steady_clock::now (); }); } } else { + consecutive_requests = 0; condition.wait_for (lock, small_delay, [this]() { return this->stopped || !this->requests.empty (); }); } } diff --git a/nano/node/request_aggregator.hpp b/nano/node/request_aggregator.hpp index 471355fe..6c7b90aa 100644 --- a/nano/node/request_aggregator.hpp +++ b/nano/node/request_aggregator.hpp @@ -78,6 +78,8 @@ private: /** Generate and send votes from \p hashes_a to \p channel_a, does not need a lock on the mutex **/ void generate (nano::transaction const &, std::vector const hashes_a, std::shared_ptr & channel_a) const; + unsigned const max_consecutive_requests; + nano::stat & stats; nano::votes_cache & votes_cache; nano::block_store & store;