Skip to content

Commit

Permalink
Merge pull request #4281 from clemahieu/manual_scheduler
Browse files Browse the repository at this point in the history
Separate manual scheduler in to its own class
  • Loading branch information
clemahieu authored Sep 13, 2023
2 parents afa344e + cc7b18b commit 9bbbc08
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 95 deletions.
5 changes: 3 additions & 2 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/election.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/manual.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/test_common/chains.hpp>
Expand Down Expand Up @@ -1393,11 +1394,11 @@ TEST (active_transactions, fifo)
ASSERT_EQ (nano::process_result::progress, node.process (*receive2).code);

// Ensure first transaction becomes active
node.scheduler.priority.manual (receive1);
node.scheduler.manual.push (receive1);
ASSERT_TIMELY (5s, node.active.election (receive1->qualified_root ()) != nullptr);

// Ensure second transaction becomes active
node.scheduler.priority.manual (receive2);
node.scheduler.manual.push (receive2);
ASSERT_TIMELY (5s, node.active.election (receive2->qualified_root ()) != nullptr);

// Ensure excess transactions get trimmed
Expand Down
5 changes: 3 additions & 2 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/lib/config.hpp>
#include <nano/node/election.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/manual.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/fake.hpp>
#include <nano/node/transport/inproc.hpp>
Expand Down Expand Up @@ -987,7 +988,7 @@ TEST (node, fork_open_flip)
// give block open1 to node1, manually trigger an election for open1 and ensure it is in the ledger
node1.process_active (open1);
ASSERT_TIMELY (5s, node1.block (open1->hash ()) != nullptr);
node1.scheduler.priority.manual (open1);
node1.scheduler.manual.push (open1);
ASSERT_TIMELY (5s, (election = node1.active.election (open1->qualified_root ())) != nullptr);
election->transition_active ();

Expand All @@ -1000,7 +1001,7 @@ TEST (node, fork_open_flip)

// ensure open2 is in node2 ledger (and therefore has sideband) and manually trigger an election for open2
ASSERT_TIMELY (5s, node2.block (open2->hash ()) != nullptr);
node2.scheduler.priority.manual (open2);
node2.scheduler.manual.push (open2);
ASSERT_TIMELY (5s, (election = node2.active.election (open2->qualified_root ())) != nullptr);
election->transition_active ();

Expand Down
21 changes: 12 additions & 9 deletions nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,12 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::db_parallel_traversal:
thread_role_name_string = "DB par traversl";
break;
case nano::thread_role::name::election_scheduler:
thread_role_name_string = "Election Sched";
break;
case nano::thread_role::name::unchecked:
thread_role_name_string = "Unchecked";
break;
case nano::thread_role::name::backlog_population:
thread_role_name_string = "Backlog";
break;
case nano::thread_role::name::election_hinting:
thread_role_name_string = "Hinting";
break;
case nano::thread_role::name::vote_generator_queue:
thread_role_name_string = "Voting que";
break;
Expand All @@ -94,8 +88,17 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::telemetry:
thread_role_name_string = "Telemetry";
break;
case nano::thread_role::name::optimistic_scheduler:
thread_role_name_string = "Optimistic";
case nano::thread_role::name::scheduler_hinted:
thread_role_name_string = "Sched Hinted";
break;
case nano::thread_role::name::scheduler_manual:
thread_role_name_string = "Sched Manual";
break;
case nano::thread_role::name::scheduler_optimistic:
thread_role_name_string = "Sched Opt";
break;
case nano::thread_role::name::scheduler_priority:
thread_role_name_string = "Sched Priority";
break;
default:
debug_assert (false && "nano::thread_role::get_string unhandled thread role");
Expand Down Expand Up @@ -133,4 +136,4 @@ void nano::thread_role::set (nano::thread_role::name role)
nano::thread_role::set_os_name (thread_role_name_string);

current_thread_role = role;
}
}
9 changes: 5 additions & 4 deletions nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ enum class name
state_block_signature_verification,
epoch_upgrader,
db_parallel_traversal,
election_scheduler,
unchecked,
backlog_population,
election_hinting,
vote_generator_queue,
bootstrap_server,
telemetry,
optimistic_scheduler,
ascending_bootstrap,
bootstrap_server_requests,
bootstrap_server_responses,
scheduler_hinted,
scheduler_manual,
scheduler_optimistic,
scheduler_priority,
};

/*
Expand All @@ -63,4 +64,4 @@ std::string get_string ();
* Internal only, should not be called directly
*/
void set_os_name (std::string const &);
}
}
2 changes: 2 additions & 0 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ add_library(
scheduler/component.cpp
scheduler/hinted.hpp
scheduler/hinted.cpp
scheduler/manual.hpp
scheduler/manual.cpp
scheduler/optimistic.hpp
scheduler/optimistic.cpp
scheduler/priority.hpp
Expand Down
13 changes: 5 additions & 8 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <nano/node/rocksdb/rocksdb.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/hinted.hpp>
#include <nano/node/scheduler/manual.hpp>
#include <nano/node/scheduler/optimistic.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/telemetry.hpp>
Expand Down Expand Up @@ -576,7 +577,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 +689,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 +722,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 Expand Up @@ -1265,7 +1262,7 @@ void nano::node::add_initial_peers ()

void nano::node::start_election (std::shared_ptr<nano::block> const & block)
{
scheduler.priority.manual (block);
scheduler.manual.push (block);
}

bool nano::node::block_confirmed (nano::block_hash const & hash_a)
Expand Down
41 changes: 38 additions & 3 deletions nano/node/scheduler/component.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
#include <nano/node/node.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/hinted.hpp>
#include <nano/node/scheduler/manual.hpp>
#include <nano/node/scheduler/optimistic.hpp>
#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) },
manual_impl{ std::make_unique<nano::scheduler::manual> (node) },
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 }
manual{ *manual_impl },
optimistic{ *optimistic_impl },
priority{ *priority_impl }
{
}

nano::scheduler::component::~component ()
{
}

void nano::scheduler::component::start ()
{
hinted.start ();
manual.start ();
optimistic.start ();
priority.start ();
}

void nano::scheduler::component::stop ()
{
hinted.stop ();
manual.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 (manual.collect_container_info ("manual"));
//composite->add_component (optimistic.collect_container_info ("optimistic"));
composite->add_component (priority.collect_container_info ("priority"));
return composite;
}
22 changes: 19 additions & 3 deletions nano/node/scheduler/component.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
#pragma once

#include <nano/lib/locks.hpp>

#include <memory>
#include <string>

namespace nano
{
class container_info_component;
class node;
}
namespace nano::scheduler
{
class hinted;
class manual;
class optimistic;
class priority;

class component
class component final
{
std::unique_ptr<nano::scheduler::hinted> hinted_impl;
std::unique_ptr<nano::scheduler::manual> manual_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::manual & manual;
nano::scheduler::optimistic & optimistic;
nano::scheduler::priority & priority;
};
}
2 changes: 1 addition & 1 deletion nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void nano::scheduler::hinted::start ()
debug_assert (!thread.joinable ());

thread = std::thread{ [this] () {
nano::thread_role::set (nano::thread_role::name::election_hinting);
nano::thread_role::set (nano::thread_role::name::scheduler_hinted);
run ();
} };
}
Expand Down
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
Loading

0 comments on commit 9bbbc08

Please sign in to comment.