Skip to content

Commit

Permalink
Dedicated election workers
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed May 24, 2024
1 parent f5cf6ce commit d3df2a1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum class detail
notify,
duplicate,
confirmed,
unconfirmed,
cemented,

// processing queue
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::wallet_worker:
thread_role_name_string = "Wallet work";
break;
case nano::thread_role::name::election_worker:
thread_role_name_string = "Election work";
break;
case nano::thread_role::name::request_aggregator:
thread_role_name_string = "Req aggregator";
break;
Expand Down
1 change: 1 addition & 0 deletions nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class name
worker,
bootstrap_worker,
wallet_worker,
election_worker,
request_aggregator,
state_block_signature_verification,
epoch_upgrader,
Expand Down
1 change: 1 addition & 0 deletions nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void nano::active_elections::cleanup_election (nano::unique_lock<nano::mutex> &
roots.get<tag_root> ().erase (roots.get<tag_root> ().find (election->qualified_root));

node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::stopped);
node.stats.inc (nano::stat::type::active_elections, election->confirmed () ? nano::stat::detail::confirmed : nano::stat::detail::unconfirmed);
node.stats.inc (nano::stat::type::active_stopped, to_stat_detail (election->state ()));
node.stats.inc (to_stat_type (election->state ()), to_stat_detail (election->behavior ()));

Expand Down
2 changes: 1 addition & 1 deletion nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void nano::election::confirm_once (nano::unique_lock<nano::mutex> & lock_a)

lock_a.unlock ();

node.workers.push_task ([node_l = node.shared (), status_l, confirmation_action_l = confirmation_action] () {
node.election_workers.push_task ([node_l = node.shared (), status_l, confirmation_action_l = confirmation_action] () {
node_l->process_confirmed (status_l);

if (confirmation_action_l)
Expand Down
5 changes: 4 additions & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
workers{ config.background_threads, nano::thread_role::name::worker },
bootstrap_workers{ config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker },
wallet_workers{ 1, nano::thread_role::name::wallet_worker },
election_workers{ 1, nano::thread_role::name::election_worker },
flags (flags_a),
work (work_a),
distributed_work (*this),
Expand Down Expand Up @@ -575,6 +576,7 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (no
composite->add_component (collect_container_info (node.workers, "workers"));
composite->add_component (collect_container_info (node.bootstrap_workers, "bootstrap_workers"));
composite->add_component (collect_container_info (node.wallet_workers, "wallet_workers"));
composite->add_component (collect_container_info (node.election_workers, "election_workers"));
composite->add_component (collect_container_info (node.observers, "observers"));
composite->add_component (collect_container_info (node.wallets, "wallets"));
composite->add_component (node.vote_processor.collect_container_info ("vote_processor"));
Expand Down Expand Up @@ -733,6 +735,7 @@ void nano::node::stop ()

bootstrap_workers.stop ();
wallet_workers.stop ();
election_workers.stop ();
vote_router.stop ();
peer_history.stop ();
// Cancels ongoing work generation tasks, which may be blocking other threads
Expand Down Expand Up @@ -1248,7 +1251,7 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint
{
iteration_a++;
std::weak_ptr<nano::node> node_w (shared ());
workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [node_w, status_a, iteration_a] () {
election_workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [node_w, status_a, iteration_a] () {
if (auto node_l = node_w.lock ())
{
node_l->process_confirmed (status_a, iteration_a);
Expand Down
1 change: 1 addition & 0 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class node final : public std::enable_shared_from_this<node>
nano::thread_pool workers;
nano::thread_pool bootstrap_workers;
nano::thread_pool wallet_workers;
nano::thread_pool election_workers;
nano::node_flags flags;
nano::work_pool & work;
nano::distributed_work_factory distributed_work;
Expand Down

0 comments on commit d3df2a1

Please sign in to comment.