Config option for disabling hinted scheduler (#4512)

This commit is contained in:
Piotr Wójcik 2024-03-21 17:55:22 +01:00 committed by GitHub
commit 1ebcec3ce2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View file

@ -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 ());
@ -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
@ -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 ());

View file

@ -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 ();
@ -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");
@ -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 ();

View file

@ -36,6 +36,7 @@ public:
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 };

View file

@ -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 ();