Skip to content

Commit

Permalink
Start/stop schedulers within nano::scheduler::component.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 12, 2023
1 parent afa344e commit 3ae56fb
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 28 deletions.
10 changes: 3 additions & 7 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ std::unique_ptr<nano::container_info_component> 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"));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ();
Expand Down
35 changes: 32 additions & 3 deletions nano/node/scheduler/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,40 @@
#include <nano/node/scheduler/priority.hpp>

nano::scheduler::component::component (nano::node & node) :
hinted_impl{ std::make_unique<nano::scheduler::hinted> (nano::scheduler::hinted::config{ node.config }, node, node.inactive_vote_cache, node.active, node.online_reps, node.stats) },
optimistic_impl{ std::make_unique<nano::scheduler::optimistic> (node.config.optimistic_scheduler, node, node.ledger, node.active, node.network_params.network, node.stats) },
priority_impl{ std::make_unique<nano::scheduler::priority> (node, node.stats) },
hinted_impl{ std::make_unique<nano::scheduler::hinted> (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::container_info_component> nano::scheduler::component::collect_container_info (std::string const & name)
{
nano::unique_lock<nano::mutex> lock{ mutex };

auto composite = std::make_unique<container_info_composite> (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;
}
17 changes: 15 additions & 2 deletions nano/node/scheduler/component.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once

#include <nano/lib/locks.hpp>

#include <memory>
#include <string>

namespace nano
{
class container_info_component;
class node;
}
namespace nano::scheduler
Expand All @@ -14,15 +18,24 @@ class priority;

class component
{
std::unique_ptr<nano::scheduler::hinted> hinted_impl;
std::unique_ptr<nano::scheduler::optimistic> optimistic_impl;
std::unique_ptr<nano::scheduler::priority> priority_impl;
std::unique_ptr<nano::scheduler::hinted> 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<container_info_component> collect_container_info (std::string const & name);

nano::scheduler::priority & priority;
nano::scheduler::hinted & hinted;
nano::scheduler::optimistic & optimistic;
nano::scheduler::priority & priority;
};
}
7 changes: 4 additions & 3 deletions nano/node/scheduler/hinted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace nano::scheduler
*/
class hinted final
{
friend class component;
void start ();
void stop ();

public: // Config
struct config final
{
Expand All @@ -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
*/
Expand Down
6 changes: 3 additions & 3 deletions nano/node/scheduler/optimistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 0 additions & 5 deletions nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
12 changes: 7 additions & 5 deletions nano/node/scheduler/priority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
#include <condition_variable>
#include <deque>
#include <memory>
#include <string>
#include <thread>

namespace nano
{
class block;
class container_info_component;
class node;
}

Expand All @@ -21,13 +23,15 @@ namespace nano::scheduler
class buckets;
class priority final
{
friend class component;
void start ();
void stop ();
std::unique_ptr<container_info_component> 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<nano::block> const &, boost::optional<nano::uint128_t> const & = boost::none, nano::election_behavior = nano::election_behavior::normal);
Expand All @@ -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<container_info_component> collect_container_info (std::string const &);

private: // Dependencies
nano::node & node;
Expand Down

0 comments on commit 3ae56fb

Please sign in to comment.