Optimize full bucket case
This commit is contained in:
parent
b3c2f6de01
commit
2fb1affc58
6 changed files with 31 additions and 17 deletions
|
@ -365,6 +365,7 @@ enum class detail
|
|||
activated,
|
||||
activate_failed,
|
||||
activate_skip,
|
||||
activate_full,
|
||||
|
||||
// active
|
||||
insert,
|
||||
|
|
|
@ -34,14 +34,18 @@ void nano::scheduler::bucket::pop ()
|
|||
queue.erase (queue.begin ());
|
||||
}
|
||||
|
||||
void nano::scheduler::bucket::push (uint64_t time, std::shared_ptr<nano::block> block)
|
||||
// Returns true if the block was inserted
|
||||
bool nano::scheduler::bucket::push (uint64_t time, std::shared_ptr<nano::block> block)
|
||||
{
|
||||
queue.insert ({ time, block });
|
||||
auto [it, inserted] = queue.insert ({ time, block });
|
||||
release_assert (!queue.empty ());
|
||||
bool was_last = (it == --queue.end ());
|
||||
if (queue.size () > maximum)
|
||||
{
|
||||
debug_assert (!queue.empty ());
|
||||
queue.erase (--queue.end ());
|
||||
return inserted && !was_last;
|
||||
}
|
||||
return inserted;
|
||||
}
|
||||
|
||||
size_t nano::scheduler::bucket::size () const
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
|
||||
std::shared_ptr<nano::block> top () const;
|
||||
void pop ();
|
||||
void push (uint64_t time, std::shared_ptr<nano::block> block);
|
||||
bool push (uint64_t time, std::shared_ptr<nano::block> block);
|
||||
size_t size () const;
|
||||
bool empty () const;
|
||||
void dump () const;
|
||||
|
|
|
@ -69,15 +69,16 @@ nano::scheduler::buckets::~buckets ()
|
|||
* Push a block and its associated time into the prioritization container.
|
||||
* The time is given here because sideband might not exist in the case of state blocks.
|
||||
*/
|
||||
void nano::scheduler::buckets::push (uint64_t time, std::shared_ptr<nano::block> block, nano::amount const & priority)
|
||||
bool nano::scheduler::buckets::push (uint64_t time, std::shared_ptr<nano::block> block, nano::amount const & priority)
|
||||
{
|
||||
auto was_empty = empty ();
|
||||
auto & bucket = find_bucket (priority.number ());
|
||||
bucket.push (time, block);
|
||||
bool added = bucket.push (time, block);
|
||||
if (was_empty)
|
||||
{
|
||||
seek ();
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
/** Return the highest priority block of the current bucket */
|
||||
|
|
|
@ -42,7 +42,8 @@ class buckets final
|
|||
public:
|
||||
buckets (uint64_t maximum = 250000u);
|
||||
~buckets ();
|
||||
void push (uint64_t time, std::shared_ptr<nano::block> block, nano::amount const & priority);
|
||||
// Returns true if the block was inserted
|
||||
bool push (uint64_t time, std::shared_ptr<nano::block> block, nano::amount const & priority);
|
||||
std::shared_ptr<nano::block> top () const;
|
||||
void pop ();
|
||||
std::size_t size () const;
|
||||
|
|
|
@ -60,7 +60,6 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio
|
|||
return activate (transaction, account, *info, conf_info);
|
||||
}
|
||||
}
|
||||
|
||||
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_skip);
|
||||
return false; // Not activated
|
||||
}
|
||||
|
@ -79,18 +78,26 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio
|
|||
auto const previous_balance = node.ledger.any.block_balance (transaction, conf_info.frontier).value_or (0);
|
||||
auto const balance_priority = std::max (balance, previous_balance);
|
||||
|
||||
node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated);
|
||||
node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated,
|
||||
nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval
|
||||
nano::log::arg{ "block", block },
|
||||
nano::log::arg{ "time", account_info.modified },
|
||||
nano::log::arg{ "priority", balance_priority });
|
||||
|
||||
bool added = false;
|
||||
{
|
||||
nano::lock_guard<nano::mutex> lock{ mutex };
|
||||
buckets->push (account_info.modified, block, balance_priority);
|
||||
added = buckets->push (account_info.modified, block, balance_priority);
|
||||
}
|
||||
if (added)
|
||||
{
|
||||
node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated);
|
||||
node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated,
|
||||
nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval
|
||||
nano::log::arg{ "block", block },
|
||||
nano::log::arg{ "time", account_info.modified },
|
||||
nano::log::arg{ "priority", balance_priority });
|
||||
|
||||
notify ();
|
||||
}
|
||||
else
|
||||
{
|
||||
node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_full);
|
||||
}
|
||||
notify ();
|
||||
|
||||
return true; // Activated
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue