From 3ae56fb6cdb1d68d9e886b1678449f13c443aa6d Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 12 Sep 2023 17:53:05 +0100 Subject: [PATCH] Start/stop schedulers within nano::scheduler::component. --- nano/node/node.cpp | 10 +++------ nano/node/scheduler/component.cpp | 35 +++++++++++++++++++++++++++--- nano/node/scheduler/component.hpp | 17 +++++++++++++-- nano/node/scheduler/hinted.hpp | 7 +++--- nano/node/scheduler/optimistic.hpp | 6 ++--- nano/node/scheduler/priority.cpp | 5 ----- nano/node/scheduler/priority.hpp | 12 +++++----- 7 files changed, 64 insertions(+), 28 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 35d9303458..95e9971901 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -576,7 +576,7 @@ std::unique_ptr nano::collect_container_info (no composite->add_component (collect_container_info (node.confirmation_height_processor, "confirmation_height_processor")); composite->add_component (collect_container_info (node.distributed_work, "distributed_work")); composite->add_component (collect_container_info (node.aggregator, "request_aggregator")); - composite->add_component (node.scheduler.priority.collect_container_info ("priority_scheduler")); + composite->add_component (node.scheduler.collect_container_info ("scheduler")); composite->add_component (node.inactive_vote_cache.collect_container_info ("inactive_vote_cache")); composite->add_component (collect_container_info (node.generator, "vote_generator")); composite->add_component (collect_container_info (node.final_generator, "vote_generator_final")); @@ -688,10 +688,8 @@ void nano::node::start () active.start (); generator.start (); final_generator.start (); - scheduler.optimistic.start (); - scheduler.priority.start (); + scheduler.start (); backlog.start (); - scheduler.hinted.start (); bootstrap_server.start (); if (!flags.disable_ascending_bootstrap) { @@ -723,9 +721,7 @@ void nano::node::stop () block_processor.stop (); aggregator.stop (); vote_processor.stop (); - scheduler.priority.stop (); - scheduler.optimistic.stop (); - scheduler.hinted.stop (); + scheduler.stop (); active.stop (); generator.stop (); final_generator.stop (); diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index 5303f52fa8..33fa7dc1ff 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -5,11 +5,40 @@ #include nano::scheduler::component::component (nano::node & node) : + hinted_impl{ std::make_unique (nano::scheduler::hinted::config{ node.config }, node, node.inactive_vote_cache, node.active, node.online_reps, node.stats) }, optimistic_impl{ std::make_unique (node.config.optimistic_scheduler, node, node.ledger, node.active, node.network_params.network, node.stats) }, priority_impl{ std::make_unique (node, node.stats) }, - hinted_impl{ std::make_unique (nano::scheduler::hinted::config{ node.config }, node, node.inactive_vote_cache, node.active, node.online_reps, node.stats) }, - priority{ *priority_impl }, hinted{ *hinted_impl }, - optimistic{ *optimistic_impl } + optimistic{ *optimistic_impl }, + priority{ *priority_impl } +{ +} + +nano::scheduler::component::~component () +{ +} + +void nano::scheduler::component::start () { + hinted.start (); + optimistic.start (); + priority.start (); +} + +void nano::scheduler::component::stop () +{ + hinted.stop (); + optimistic.stop (); + priority.stop (); +} + +std::unique_ptr nano::scheduler::component::collect_container_info (std::string const & name) +{ + nano::unique_lock lock{ mutex }; + + auto composite = std::make_unique (name); + //composite->add_component (hinted.collect_container_info ("hinted")); + //composite->add_component (optimistic.collect_container_info ("optimistic")); + composite->add_component (priority.collect_container_info ("priority")); + return composite; } diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 0af9b41c1c..7768fba36c 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -1,9 +1,13 @@ #pragma once +#include + #include +#include namespace nano { +class container_info_component; class node; } namespace nano::scheduler @@ -14,15 +18,24 @@ class priority; class component { + std::unique_ptr hinted_impl; std::unique_ptr optimistic_impl; std::unique_ptr priority_impl; - std::unique_ptr hinted_impl; + nano::mutex mutex; public: explicit component (nano::node & node); + ~component (); + + // Starts all schedulers + void start (); + // Stops all schedulers + void stop (); + + std::unique_ptr collect_container_info (std::string const & name); - nano::scheduler::priority & priority; nano::scheduler::hinted & hinted; nano::scheduler::optimistic & optimistic; + nano::scheduler::priority & priority; }; } diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index a35b6588e6..ba344095d2 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -22,6 +22,10 @@ namespace nano::scheduler */ class hinted final { + friend class component; + void start (); + void stop (); + public: // Config struct config final { @@ -34,9 +38,6 @@ class hinted final hinted (config const &, nano::node &, nano::vote_cache &, nano::active_transactions &, nano::online_reps &, nano::stats &); ~hinted (); - void start (); - void stop (); - /* * Notify about changes in AEC vacancy */ diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 2cc802ea43..3c16c72059 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -46,15 +46,15 @@ class optimistic_config final }; class optimistic final { + friend class component; + void start (); + void stop (); struct entry; public: optimistic (optimistic_config const &, nano::node &, nano::ledger &, nano::active_transactions &, nano::network_constants const & network_constants, nano::stats &); ~optimistic (); - void start (); - void stop (); - /** * Called from backlog population to process accounts with unconfirmed blocks */ diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index 0ee92f4643..c8e9e0f2dc 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -93,11 +93,6 @@ bool nano::scheduler::priority::empty () const return empty_locked (); } -std::size_t nano::scheduler::priority::priority_queue_size () const -{ - return buckets->size (); -} - bool nano::scheduler::priority::priority_queue_predicate () const { return node.active.vacancy () > 0 && !buckets->empty (); diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 1358286713..b798f7a400 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -8,11 +8,13 @@ #include #include #include +#include #include namespace nano { class block; +class container_info_component; class node; } @@ -21,13 +23,15 @@ namespace nano::scheduler class buckets; class priority final { + friend class component; + void start (); + void stop (); + std::unique_ptr collect_container_info (std::string const & name); + public: priority (nano::node &, nano::stats &); ~priority (); - void start (); - void stop (); - // Manualy start an election for a block // Call action with confirmed block, may be different than what we started with void manual (std::shared_ptr const &, boost::optional const & = boost::none, nano::election_behavior = nano::election_behavior::normal); @@ -39,8 +43,6 @@ class priority final void notify (); std::size_t size () const; bool empty () const; - std::size_t priority_queue_size () const; - std::unique_ptr collect_container_info (std::string const &); private: // Dependencies nano::node & node;