From c4801320150ea0c492cf343d490a0a339432f060 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 10 Oct 2025 18:09:53 +0200 Subject: add ability to limit concurrency (#565) effective concurrency in zenserver can be limited via the `--corelimit=` option on the command line. Any value passed in here will be used instead of the return value from `std::thread::hardware_concurrency()` if it is lower. * added --corelimit option to zenserver * made sure thread pools are configured lazily and not during global init * added log output indicating effective and HW concurrency * added change log entry * removed debug logging from ZenEntryPoint::Run() also removed main thread naming on Linux since it makes the output from `top` and similar tools confusing (it shows `main` instead of `zenserver`) --- src/zencore/thread.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/zencore/thread.cpp') diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index abf282467..7bd21a229 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -45,6 +45,27 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { +static unsigned int LimitConcurrency = 0; + +void +LimitHardwareConcurrency(unsigned int Limit) +{ + LimitConcurrency = Limit; +} + +unsigned int +GetHardwareConcurrency() +{ + static unsigned int SysLimit = std::thread::hardware_concurrency(); + + if (LimitConcurrency) + { + return Min(SysLimit, LimitConcurrency); + } + + return SysLimit; +} + #if ZEN_PLATFORM_WINDOWS // The information on how to set the thread name comes from // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx -- cgit v1.2.3