diff options
| author | Stefan Boberg <[email protected]> | 2025-10-10 18:09:53 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-10-10 18:09:53 +0200 |
| commit | c4801320150ea0c492cf343d490a0a339432f060 (patch) | |
| tree | d3013ef82c1707e38db3abac94d1fec0ca352394 /src/zenserver | |
| parent | shorten thread pool names for Linux which has a limit of 15 characters (#563) (diff) | |
| download | zen-c4801320150ea0c492cf343d490a0a339432f060.tar.xz zen-c4801320150ea0c492cf343d490a0a339432f060.zip | |
add ability to limit concurrency (#565)
effective concurrency in zenserver can be limited via the `--corelimit=<N>` 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`)
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/cache/httpstructuredcache.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/config.cpp | 1 | ||||
| -rw-r--r-- | src/zenserver/config.h | 1 | ||||
| -rw-r--r-- | src/zenserver/main.cpp | 9 | ||||
| -rw-r--r-- | src/zenserver/zenserver.cpp | 2 |
5 files changed, 13 insertions, 2 deletions
diff --git a/src/zenserver/cache/httpstructuredcache.cpp b/src/zenserver/cache/httpstructuredcache.cpp index dd5bf05cb..9f87c208c 100644 --- a/src/zenserver/cache/httpstructuredcache.cpp +++ b/src/zenserver/cache/httpstructuredcache.cpp @@ -423,7 +423,7 @@ HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request) std::string RecordPath = UrlDecode(Params.GetValue("path")); - uint32_t ThreadCount = std::thread::hardware_concurrency(); + uint32_t ThreadCount = GetHardwareConcurrency(); if (auto Param = Params.GetValue("thread_count"); Param.empty() == false) { if (auto Value = ParseInt<uint64_t>(Param)) diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 0cf5a9ca3..697d44214 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -817,6 +817,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) options.add_options()("malloc", "Configure memory allocator subsystem", cxxopts::value(ServerOptions.MemoryOptions)->default_value("mimalloc")); + options.add_options()("corelimit", "Limit concurrency", cxxopts::value(ServerOptions.CoreLimit)); // clang-format off options.add_options("logging") diff --git a/src/zenserver/config.h b/src/zenserver/config.h index 8380e72e7..3f7cb149a 100644 --- a/src/zenserver/config.h +++ b/src/zenserver/config.h @@ -207,6 +207,7 @@ struct ZenServerOptions bool ObjectStoreEnabled = false; bool NoConsoleOutput = false; // Control default use of stdout for diagnostics bool QuietConsole = false; // Configure console logger output to level WARN + int CoreLimit = 0; // If set, hardware concurrency queries are capped at this number std::string Loggers[zen::logging::level::LogLevelCount]; std::string ScrubOptions; #if ZEN_WITH_TRACE diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index a91c95ffb..b4d53ec5f 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -93,8 +93,13 @@ ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions) : m_ServerOptions( int ZenEntryPoint::Run() { - ZEN_INFO("ZenEntryPoint::Run()"); + // On Linux this has the unfortunate side effect of making `top` and other tools display + // `main` as the program name since threads and processes have a closer relationship + // there. So we don't name the main thread explicitly there. + +#ifndef ZEN_PLATFORM_LINUX zen::SetCurrentThreadName("main"); +#endif #if ZEN_USE_SENTRY SentryIntegration Sentry; @@ -444,6 +449,8 @@ main(int argc, char* argv[]) #endif } + LimitHardwareConcurrency(ServerOptions.CoreLimit); + std::string_view DeleteReason; if (ServerOptions.IsCleanStart) diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index cab234165..975459e68 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -244,6 +244,8 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen m_StatusService.RegisterHandler("status", *this); + ZEN_INFO("Effective concurrency: {} (hw: {})", GetHardwareConcurrency(), std::thread::hardware_concurrency()); + // Initialize storage and services ZEN_INFO("initializing storage"); |