Moving responsibility of trimming active_transaction container in to the container itself rather than in the election scheduler. (#4235)
This commit is contained in:
parent
7772cd784c
commit
d570e645fa
4 changed files with 20 additions and 20 deletions
|
|
@ -372,6 +372,20 @@ nano::election_insertion_result nano::active_transactions::insert (const std::sh
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nano::active_transactions::trim ()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Both normal and hinted election schedulers are well-behaved, meaning they first check for AEC vacancy before inserting new elections.
|
||||||
|
* However, it is possible that AEC will be temporarily overfilled in case it's running at full capacity and election hinting or manual queue kicks in.
|
||||||
|
* That case will lead to unwanted churning of elections, so this allows for AEC to be overfilled to 125% until erasing of elections happens.
|
||||||
|
*/
|
||||||
|
while (vacancy () < -(limit () / 4))
|
||||||
|
{
|
||||||
|
node.stats.inc (nano::stat::type::active, nano::stat::detail::erase_oldest);
|
||||||
|
erase_oldest ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nano::election_insertion_result nano::active_transactions::insert_impl (nano::unique_lock<nano::mutex> & lock_a, std::shared_ptr<nano::block> const & block_a, nano::election_behavior election_behavior_a, std::function<void (std::shared_ptr<nano::block> const &)> const & confirmation_action_a)
|
nano::election_insertion_result nano::active_transactions::insert_impl (nano::unique_lock<nano::mutex> & lock_a, std::shared_ptr<nano::block> const & block_a, nano::election_behavior election_behavior_a, std::function<void (std::shared_ptr<nano::block> const &)> const & confirmation_action_a)
|
||||||
{
|
{
|
||||||
debug_assert (!mutex.try_lock ());
|
debug_assert (!mutex.try_lock ());
|
||||||
|
|
@ -425,6 +439,7 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un
|
||||||
{
|
{
|
||||||
result.election->broadcast_vote ();
|
result.election->broadcast_vote ();
|
||||||
}
|
}
|
||||||
|
trim ();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,8 @@ public:
|
||||||
void remove_election_winner_details (nano::block_hash const &);
|
void remove_election_winner_details (nano::block_hash const &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Erase elections if we're over capacity
|
||||||
|
void trim ();
|
||||||
// Call action with confirmed block, may be different than what we started with
|
// Call action with confirmed block, may be different than what we started with
|
||||||
nano::election_insertion_result insert_impl (nano::unique_lock<nano::mutex> &, std::shared_ptr<nano::block> const &, nano::election_behavior = nano::election_behavior::normal, std::function<void (std::shared_ptr<nano::block> const &)> const & = nullptr);
|
nano::election_insertion_result insert_impl (nano::unique_lock<nano::mutex> &, std::shared_ptr<nano::block> const &, nano::election_behavior = nano::election_behavior::normal, std::function<void (std::shared_ptr<nano::block> const &)> const & = nullptr);
|
||||||
void request_loop ();
|
void request_loop ();
|
||||||
|
|
|
||||||
|
|
@ -114,36 +114,20 @@ bool nano::election_scheduler::manual_queue_predicate () const
|
||||||
return !manual_queue.empty ();
|
return !manual_queue.empty ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nano::election_scheduler::overfill_predicate () const
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Both normal and hinted election schedulers are well-behaved, meaning they first check for AEC vacancy before inserting new elections.
|
|
||||||
* However, it is possible that AEC will be temporarily overfilled in case it's running at full capacity and election hinting or manual queue kicks in.
|
|
||||||
* That case will lead to unwanted churning of elections, so this allows for AEC to be overfilled to 125% until erasing of elections happens.
|
|
||||||
*/
|
|
||||||
return node.active.vacancy () < -(node.active.limit () / 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void nano::election_scheduler::run ()
|
void nano::election_scheduler::run ()
|
||||||
{
|
{
|
||||||
nano::unique_lock<nano::mutex> lock{ mutex };
|
nano::unique_lock<nano::mutex> lock{ mutex };
|
||||||
while (!stopped)
|
while (!stopped)
|
||||||
{
|
{
|
||||||
condition.wait (lock, [this] () {
|
condition.wait (lock, [this] () {
|
||||||
return stopped || priority_queue_predicate () || manual_queue_predicate () || overfill_predicate ();
|
return stopped || priority_queue_predicate () || manual_queue_predicate ();
|
||||||
});
|
});
|
||||||
debug_assert ((std::this_thread::yield (), true)); // Introduce some random delay in debug builds
|
debug_assert ((std::this_thread::yield (), true)); // Introduce some random delay in debug builds
|
||||||
if (!stopped)
|
if (!stopped)
|
||||||
{
|
{
|
||||||
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::loop);
|
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::loop);
|
||||||
|
|
||||||
if (overfill_predicate ())
|
if (manual_queue_predicate ())
|
||||||
{
|
|
||||||
lock.unlock ();
|
|
||||||
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::erase_oldest);
|
|
||||||
node.active.erase_oldest ();
|
|
||||||
}
|
|
||||||
else if (manual_queue_predicate ())
|
|
||||||
{
|
{
|
||||||
auto const [block, previous_balance, election_behavior] = manual_queue.front ();
|
auto const [block, previous_balance, election_behavior] = manual_queue.front ();
|
||||||
manual_queue.pop_front ();
|
manual_queue.pop_front ();
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ private:
|
||||||
bool empty_locked () const;
|
bool empty_locked () const;
|
||||||
bool priority_queue_predicate () const;
|
bool priority_queue_predicate () const;
|
||||||
bool manual_queue_predicate () const;
|
bool manual_queue_predicate () const;
|
||||||
bool overfill_predicate () const;
|
|
||||||
|
|
||||||
nano::prioritization priority;
|
nano::prioritization priority;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue