Skip to content

Commit

Permalink
Config option for disabling hinted scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 21, 2024
1 parent e8beaa8 commit 435493c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions nano/core_test/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ TEST (toml, daemon_config_deserialize_defaults)
ASSERT_EQ (conf.node.optimistic_scheduler.gap_threshold, defaults.node.optimistic_scheduler.gap_threshold);
ASSERT_EQ (conf.node.optimistic_scheduler.max_size, defaults.node.optimistic_scheduler.max_size);

ASSERT_EQ (conf.node.hinted_scheduler.enabled, defaults.node.hinted_scheduler.enabled);
ASSERT_EQ (conf.node.hinted_scheduler.hinting_threshold_percent, defaults.node.hinted_scheduler.hinting_threshold_percent);
ASSERT_EQ (conf.node.hinted_scheduler.check_interval.count (), defaults.node.hinted_scheduler.check_interval.count ());
ASSERT_EQ (conf.node.hinted_scheduler.block_cooldown.count (), defaults.node.hinted_scheduler.block_cooldown.count ());
Expand Down Expand Up @@ -516,6 +517,7 @@ TEST (toml, daemon_config_deserialize_no_defaults)
max_size = 999
[node.hinted_scheduler]
enabled = false
hinting_threshold = 99
check_interval = 999
block_cooldown = 999
Expand Down Expand Up @@ -667,6 +669,7 @@ TEST (toml, daemon_config_deserialize_no_defaults)
ASSERT_NE (conf.node.optimistic_scheduler.gap_threshold, defaults.node.optimistic_scheduler.gap_threshold);
ASSERT_NE (conf.node.optimistic_scheduler.max_size, defaults.node.optimistic_scheduler.max_size);

ASSERT_NE (conf.node.hinted_scheduler.enabled, defaults.node.hinted_scheduler.enabled);
ASSERT_NE (conf.node.hinted_scheduler.hinting_threshold_percent, defaults.node.hinted_scheduler.hinting_threshold_percent);
ASSERT_NE (conf.node.hinted_scheduler.check_interval.count (), defaults.node.hinted_scheduler.check_interval.count ());
ASSERT_NE (conf.node.hinted_scheduler.block_cooldown.count (), defaults.node.hinted_scheduler.block_cooldown.count ());
Expand Down
7 changes: 7 additions & 0 deletions nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ void nano::scheduler::hinted::start ()
{
debug_assert (!thread.joinable ());

if (!config.enabled)
{
return;
}

thread = std::thread{ [this] () {
nano::thread_role::set (nano::thread_role::name::scheduler_hinted);
run ();
Expand Down Expand Up @@ -254,6 +259,7 @@ nano::scheduler::hinted_config::hinted_config (nano::network_constants const & n

nano::error nano::scheduler::hinted_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("enable", enabled, "Enable or disable hinted elections\ntype:bool");
toml.put ("hinting_threshold", hinting_threshold_percent, "Percentage of online weight needed to start a hinted election. \ntype:uint32,[0,100]");
toml.put ("check_interval", check_interval.count (), "Interval between scans of the vote cache for possible hinted elections. \ntype:milliseconds");
toml.put ("block_cooldown", block_cooldown.count (), "Cooldown period for blocks that failed to start an election. \ntype:milliseconds");
Expand All @@ -264,6 +270,7 @@ nano::error nano::scheduler::hinted_config::serialize (nano::tomlconfig & toml)

nano::error nano::scheduler::hinted_config::deserialize (nano::tomlconfig & toml)
{
toml.get ("enabled", enabled);
toml.get ("hinting_threshold", hinting_threshold_percent);

auto check_interval_l = check_interval.count ();
Expand Down
1 change: 1 addition & 0 deletions nano/node/scheduler/hinted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class hinted_config final
nano::error serialize (nano::tomlconfig & toml) const;

public:
bool enabled{ true };
std::chrono::milliseconds check_interval{ 1000 };
std::chrono::milliseconds block_cooldown{ 10000 };
unsigned hinting_threshold_percent{ 10 };
Expand Down
4 changes: 2 additions & 2 deletions nano/node/scheduler/optimistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ nano::scheduler::optimistic::~optimistic ()

void nano::scheduler::optimistic::start ()
{
debug_assert (!thread.joinable ());

if (!config.enabled)
{
return;
}

debug_assert (!thread.joinable ());

thread = std::thread{ [this] () {
nano::thread_role::set (nano::thread_role::name::scheduler_optimistic);
run ();
Expand Down

0 comments on commit 435493c

Please sign in to comment.