From c9e43e1ad5ea3f41e1f7df876460ede167d76351 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Wed, 27 Sep 2023 16:25:15 +0200 Subject: prefer to handle cache RPC requests synchronously (#428) * only handle RPC requests in a worker thread if we have an upstream. we may as well handle the request inline on the http_io thread if we're only dealing with local data since the response times should be pretty consistent in that case * http.sys: don't create async worker thread pool until it's needed (typically only if we have an upstream) --- src/zenhttp/httpsys.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/zenhttp/httpsys.cpp') diff --git a/src/zenhttp/httpsys.cpp b/src/zenhttp/httpsys.cpp index f95a31914..886d53143 100644 --- a/src/zenhttp/httpsys.cpp +++ b/src/zenhttp/httpsys.cpp @@ -747,7 +747,7 @@ HttpSysServer::HttpSysServer(const Config& Config) , m_IsRequestLoggingEnabled(Config.IsRequestLoggingEnabled) , m_IsAsyncResponseEnabled(Config.IsAsyncResponseEnabled) , m_ThreadPool(Config.ThreadCount != 0 ? Config.ThreadCount : std::thread::hardware_concurrency()) -, m_AsyncWorkPool(Config.AsyncWorkThreadCount != 0 ? Config.AsyncWorkThreadCount : 16, "http_async") +, m_InitialConfig(Config) { ULONG Result = HttpInitialize(HTTPAPI_VERSION_2, HTTP_INITIALIZE_SERVER, nullptr); @@ -768,6 +768,9 @@ HttpSysServer::~HttpSysServer() { ZEN_ERROR("~HttpSysServer() called without calling Close() first"); } + + delete m_AsyncWorkPool; + m_AsyncWorkPool = nullptr; } void @@ -977,6 +980,24 @@ HttpSysServer::Cleanup() } } +WorkerThreadPool& +HttpSysServer::WorkPool() +{ + if (!m_AsyncWorkPool) + { + RwLock::ExclusiveLockScope _(m_AsyncWorkPoolInitLock); + + if (!m_AsyncWorkPool) + { + unsigned int WorkerThreadCount = m_InitialConfig.AsyncWorkThreadCount != 0 ? m_InitialConfig.AsyncWorkThreadCount : 16; + + m_AsyncWorkPool = new WorkerThreadPool(WorkerThreadCount, "http_async"); + } + } + + return *m_AsyncWorkPool; +} + void HttpSysServer::StartServer() { -- cgit v1.2.3