aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-09-14 03:54:57 -0400
committerGitHub <[email protected]>2023-09-14 09:54:57 +0200
commite0da430c424192c24f5089ceb97f37062349e9ef (patch)
tree2d83811f16839c1133a38b8a05c5ef1074a3701f /src/zenhttp
parentdisable access logging on shared instances (#403) (diff)
downloadzen-e0da430c424192c24f5089ceb97f37062349e9ef.tar.xz
zen-e0da430c424192c24f5089ceb97f37062349e9ef.zip
http and httpsys config options (#401)
* Added `--http-threads`, `--httpsys-async-work-threads`, `--httpsys-enable-request-logging` and `--httpsys-enable-async-response` command line options to zenserver * remove unused CreateHttpSysServer
Diffstat (limited to 'src/zenhttp')
-rw-r--r--src/zenhttp/httpasio.cpp6
-rw-r--r--src/zenhttp/httpasio.h7
-rw-r--r--src/zenhttp/httpserver.cpp18
-rw-r--r--src/zenhttp/httpsys.cpp16
-rw-r--r--src/zenhttp/httpsys.h9
-rw-r--r--src/zenhttp/include/zenhttp/httpserver.h15
6 files changed, 45 insertions, 26 deletions
diff --git a/src/zenhttp/httpasio.cpp b/src/zenhttp/httpasio.cpp
index e12125bcc..4d1f35c2b 100644
--- a/src/zenhttp/httpasio.cpp
+++ b/src/zenhttp/httpasio.cpp
@@ -1339,7 +1339,9 @@ HttpAsioServerImpl::RouteRequest(std::string_view Url)
//////////////////////////////////////////////////////////////////////////
namespace zen {
-HttpAsioServer::HttpAsioServer() : m_Impl(std::make_unique<asio_http::HttpAsioServerImpl>())
+HttpAsioServer::HttpAsioServer(unsigned int ThreadCount)
+: m_ThreadCount(ThreadCount != 0 ? ThreadCount : Max(std::thread::hardware_concurrency(), 8u))
+, m_Impl(std::make_unique<asio_http::HttpAsioServerImpl>())
{
ZEN_DEBUG("Request object size: {} ({:#x})", sizeof(asio_http::HttpRequest), sizeof(asio_http::HttpRequest));
}
@@ -1375,7 +1377,7 @@ HttpAsioServer::RegisterService(HttpService& Service)
int
HttpAsioServer::Initialize(int BasePort)
{
- m_BasePort = m_Impl->Start(gsl::narrow<uint16_t>(BasePort), Max(std::thread::hardware_concurrency(), 8u));
+ m_BasePort = m_Impl->Start(gsl::narrow<uint16_t>(BasePort), m_ThreadCount);
return m_BasePort;
}
diff --git a/src/zenhttp/httpasio.h b/src/zenhttp/httpasio.h
index de25c538f..81aadfc23 100644
--- a/src/zenhttp/httpasio.h
+++ b/src/zenhttp/httpasio.h
@@ -18,7 +18,7 @@ namespace asio_http {
class HttpAsioServer : public HttpServer
{
public:
- HttpAsioServer();
+ HttpAsioServer(unsigned int ThreadCount);
~HttpAsioServer();
virtual void RegisterService(HttpService& Service) override;
@@ -28,8 +28,9 @@ public:
virtual void Close() override;
private:
- Event m_ShutdownEvent;
- int m_BasePort = 0;
+ Event m_ShutdownEvent;
+ int m_BasePort = 0;
+ unsigned int m_ThreadCount = 0;
std::unique_ptr<asio_http::HttpAsioServerImpl> m_Impl;
};
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp
index 5312e80a2..a98a3c9bb 100644
--- a/src/zenhttp/httpserver.cpp
+++ b/src/zenhttp/httpserver.cpp
@@ -714,11 +714,8 @@ enum class HttpServerClass
kHttpNull
};
-// Implemented in httpsys.cpp
-Ref<HttpServer> CreateHttpSysServer(int Concurrency, int BackgroundWorkerThreads);
-
Ref<HttpServer>
-CreateHttpServer(std::string_view ServerClass)
+CreateHttpServer(const HttpServerConfig& Config)
{
using namespace std::literals;
@@ -730,15 +727,15 @@ CreateHttpServer(std::string_view ServerClass)
Class = HttpServerClass::kHttpAsio;
#endif
- if (ServerClass == "asio"sv)
+ if (Config.ServerClass == "asio"sv)
{
Class = HttpServerClass::kHttpAsio;
}
- else if (ServerClass == "httpsys"sv)
+ else if (Config.ServerClass == "httpsys"sv)
{
Class = HttpServerClass::kHttpSys;
}
- else if (ServerClass == "null"sv)
+ else if (Config.ServerClass == "null"sv)
{
Class = HttpServerClass::kHttpNull;
}
@@ -748,12 +745,15 @@ CreateHttpServer(std::string_view ServerClass)
default:
case HttpServerClass::kHttpAsio:
ZEN_INFO("using asio HTTP server implementation");
- return Ref<HttpServer>(new HttpAsioServer());
+ return Ref<HttpServer>(new HttpAsioServer(Config.ThreadCount));
#if ZEN_WITH_HTTPSYS
case HttpServerClass::kHttpSys:
ZEN_INFO("using http.sys server implementation");
- return Ref<HttpServer>(new HttpSysServer(std::thread::hardware_concurrency(), /* background worker threads */ 16));
+ return Ref<HttpServer>(new HttpSysServer({.ThreadCount = Config.ThreadCount,
+ .AsyncWorkThreadCount = Config.HttpSys.AsyncWorkThreadCount,
+ .IsAsyncResponseEnabled = Config.HttpSys.IsAsyncResponseEnabled,
+ .IsRequestLoggingEnabled = Config.HttpSys.IsRequestLoggingEnabled}));
#endif
case HttpServerClass::kHttpNull:
diff --git a/src/zenhttp/httpsys.cpp b/src/zenhttp/httpsys.cpp
index 0b06f0558..2f8e0a898 100644
--- a/src/zenhttp/httpsys.cpp
+++ b/src/zenhttp/httpsys.cpp
@@ -721,11 +721,13 @@ HttpAsyncWorkRequest::AsyncWorkItem::Execute()
\/ \/ \/
*/
-HttpSysServer::HttpSysServer(unsigned int ThreadCount, unsigned int AsyncWorkThreadCount)
+HttpSysServer::HttpSysServer(const Config& Config)
: m_Log(logging::Get("http"))
, m_RequestLog(logging::Get("http_requests"))
-, m_ThreadPool(ThreadCount)
-, m_AsyncWorkPool(AsyncWorkThreadCount, "http_async")
+, 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")
{
ULONG Result = HttpInitialize(HTTPAPI_VERSION_2, HTTP_INITIALIZE_SERVER, nullptr);
@@ -737,7 +739,7 @@ HttpSysServer::HttpSysServer(unsigned int ThreadCount, unsigned int AsyncWorkThr
m_IsHttpInitialized = true;
m_IsOk = true;
- ZEN_INFO("http.sys server started, using {} I/O threads and {} async worker threads", ThreadCount, AsyncWorkThreadCount);
+ ZEN_INFO("http.sys server started, using {} I/O threads and {} async worker threads", Config.ThreadCount, Config.AsyncWorkThreadCount);
}
HttpSysServer::~HttpSysServer()
@@ -1697,11 +1699,5 @@ HttpSysServer::RegisterService(HttpService& Service)
RegisterService(Service.BaseUri(), Service);
}
-Ref<HttpServer>
-CreateHttpSysServer(int Concurrency, int BackgroundWorkerThreads)
-{
- return Ref<HttpServer>(new HttpSysServer(Concurrency, BackgroundWorkerThreads));
-}
-
} // namespace zen
#endif
diff --git a/src/zenhttp/httpsys.h b/src/zenhttp/httpsys.h
index cf16042d7..3a2a6065d 100644
--- a/src/zenhttp/httpsys.h
+++ b/src/zenhttp/httpsys.h
@@ -36,7 +36,14 @@ class HttpSysServer : public HttpServer
friend class HttpSysTransaction;
public:
- explicit HttpSysServer(unsigned int ThreadCount, unsigned int AsyncWorkThreadCount);
+ struct Config
+ {
+ unsigned int ThreadCount = 0;
+ unsigned int AsyncWorkThreadCount = 0;
+ bool IsAsyncResponseEnabled = true;
+ bool IsRequestLoggingEnabled = false;
+ };
+ explicit HttpSysServer(const Config& Config);
~HttpSysServer();
// HttpServer interface implementation
diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h
index d1a562ee4..c233075be 100644
--- a/src/zenhttp/include/zenhttp/httpserver.h
+++ b/src/zenhttp/include/zenhttp/httpserver.h
@@ -182,7 +182,20 @@ public:
virtual void Close() = 0;
};
-Ref<HttpServer> CreateHttpServer(std::string_view ServerClass);
+struct HttpServerConfig
+{
+ std::string ServerClass; // Choice of HTTP server implementation
+ unsigned int ThreadCount = 0;
+
+ struct
+ {
+ unsigned int AsyncWorkThreadCount = 0;
+ bool IsAsyncResponseEnabled = true;
+ bool IsRequestLoggingEnabled = false;
+ } HttpSys;
+};
+
+Ref<HttpServer> CreateHttpServer(const HttpServerConfig& Config);
//////////////////////////////////////////////////////////////////////////