Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration and environment variable improvements #4613

Merged
merged 13 commits into from
May 13, 2024
1 change: 1 addition & 0 deletions nano/lib/threading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ unsigned nano::hardware_concurrency ()
}
return std::thread::hardware_concurrency ();
}();
release_assert (concurrency > 0, "configured hardware concurrency must be non zero");
return concurrency;
}

Expand Down
10 changes: 10 additions & 0 deletions nano/lib/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,14 @@ std::string to_str (T const & val)
{
return boost::lexical_cast<std::string> (val);
}
}

namespace nano
{
template <typename T>
T min_max (T min, T max, T value)
{
debug_assert (min <= max);
return std::min (max, std::max (min, value));
}
}
2 changes: 1 addition & 1 deletion nano/node/message_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class message_processor_config final
nano::error serialize (nano::tomlconfig & toml) const;

public:
size_t threads{ std::min (nano::hardware_concurrency () / 4, 2u) };
size_t threads{ min_max (1u, 2u, nano::hardware_concurrency () / 4) };
size_t max_queue{ 64 };
};

Expand Down
2 changes: 1 addition & 1 deletion nano/node/request_aggregator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class request_aggregator_config final
nano::error serialize (nano::tomlconfig &) const;

public:
size_t threads{ std::min (nano::hardware_concurrency (), 4u) };
size_t threads{ min_max (1u, 4u, nano::hardware_concurrency () / 2) };
size_t max_queue{ 128 };
size_t batch_size{ 16 };
};
Expand Down
2 changes: 1 addition & 1 deletion nano/node/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class vote_processor_config final
size_t max_pr_queue{ 256 };
size_t max_non_pr_queue{ 32 };
size_t pr_priority{ 3 };
size_t threads{ std::min (4u, nano::hardware_concurrency () / 2) };
size_t threads{ min_max (1u, 4u, nano::hardware_concurrency () / 2) };
size_t batch_size{ 1024 };
};

Expand Down
Loading