Skip to content

Commit

Permalink
Add election_scheduler stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 22, 2023
1 parent f98193c commit 327806b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
7 changes: 7 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class type : uint8_t
active_timeout,
backlog,
unchecked,
election_scheduler,

_last // Must be the last enum
};
Expand Down Expand Up @@ -262,6 +263,12 @@ enum class detail : uint8_t
satisfied,
trigger,

// election scheduler
insert_manual,
insert_priority,
insert_priority_success,
erase_oldest,

_last // Must be the last enum
};

Expand Down
21 changes: 16 additions & 5 deletions nano/node/election_scheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <nano/node/election_scheduler.hpp>
#include <nano/node/node.hpp>

nano::election_scheduler::election_scheduler (nano::node & node) :
node{ node }
nano::election_scheduler::election_scheduler (nano::node & node_a, nano::stats & stats_a) :
node{ node_a },
stats{ stats_a }
{
}

Expand Down Expand Up @@ -55,6 +56,7 @@ bool nano::election_scheduler::activate (nano::account const & account_a, nano::
debug_assert (block != nullptr);
if (node.ledger.dependents_confirmed (transaction, *block))
{
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated);
auto balance = node.ledger.balance (transaction, hash);
auto previous_balance = node.ledger.balance (transaction, conf_info.frontier);
nano::lock_guard<nano::mutex> lock{ mutex };
Expand Down Expand Up @@ -133,16 +135,20 @@ void nano::election_scheduler::run ()
debug_assert ((std::this_thread::yield (), true)); // Introduce some random delay in debug builds
if (!stopped)
{
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::loop);

if (overfill_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 ();
manual_queue.pop_front ();
lock.unlock ();
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual);
nano::unique_lock<nano::mutex> lock2 (node.active.mutex);
node.active.insert_impl (lock2, block, election_behavior);
}
Expand All @@ -152,11 +158,16 @@ void nano::election_scheduler::run ()
priority.pop ();
lock.unlock ();
std::shared_ptr<nano::election> election;
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority);
nano::unique_lock<nano::mutex> lock2 (node.active.mutex);
election = node.active.insert_impl (lock2, block).election;
if (election != nullptr)
auto result = node.active.insert_impl (lock2, block);
if (result.inserted)
{
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success);
}
if (result.election != nullptr)
{
election->transition_active ();
result.election->transition_active ();
}
}
else
Expand Down
3 changes: 2 additions & 1 deletion nano/node/election_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class node;
class election_scheduler final
{
public:
election_scheduler (nano::node &);
election_scheduler (nano::node &, nano::stats &);
~election_scheduler ();

void start ();
Expand All @@ -43,6 +43,7 @@ class election_scheduler final

private: // Dependencies
nano::node & node;
nano::stats & stats;

private:
void run ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path co
generator{ config, ledger, wallets, vote_processor, history, network, stats, /* non-final */ false },
final_generator{ config, ledger, wallets, vote_processor, history, network, stats, /* final */ true },
active (*this, confirmation_height_processor),
scheduler{ *this },
scheduler{ *this, stats },
hinting{ nano::nodeconfig_to_hinted_scheduler_config (config), *this, inactive_vote_cache, active, online_reps, stats },
aggregator (config, stats, generator, final_generator, history, ledger, wallets, active),
wallets (wallets_store.init_error (), *this),
Expand Down

0 comments on commit 327806b

Please sign in to comment.