Refresh mutex lock after some consecutive requests without generation (#2509)

This commit is contained in:
Guilherme Lawless 2020-01-24 14:28:49 +00:00 committed by GitHub
commit 48d4c4a056
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -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 (); });
}
}

View file

@ -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<nano::block_hash> const hashes_a, std::shared_ptr<nano::transport::channel> & channel_a) const;
unsigned const max_consecutive_requests;
nano::stat & stats;
nano::votes_cache & votes_cache;
nano::block_store & store;