aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-01-14 10:32:37 +0100
committerGitHub Enterprise <[email protected]>2026-01-14 10:32:37 +0100
commitf99a4687ff78e2823332e09d0e35cb16f361ff93 (patch)
tree58020dafaad9e1c9664698e3d36884667cb5c465 /src/zenserver
parent5.7.16-pre2 (diff)
downloadzen-f99a4687ff78e2823332e09d0e35cb16f361ff93.tar.xz
zen-f99a4687ff78e2823332e09d0e35cb16f361ff93.zip
asio/http optimizations (#449)
This change primarily introduces improved logic for dealing with sending data from file references. This is intended to reduce the amount of memory-mapping we end up doing when sending data from files. Windows now uses `TransmitFile` to send file data more efficiently using kernel-side I/O, but Linux/Mac basically behaves as before since they don't offer any true async file I/O support via asio. This should be implemented separately using a background I/O thread pool. This PR also includes improved memory management for http/asio with reduced allocation counts, and a fix for a potential use-after-free in very high load scenarios.
Diffstat (limited to 'src/zenserver')
-rw-r--r--src/zenserver/diag/diagsvcs.cpp29
1 files changed, 2 insertions, 27 deletions
diff --git a/src/zenserver/diag/diagsvcs.cpp b/src/zenserver/diag/diagsvcs.cpp
index 8abf6e8a3..d8d53b0e3 100644
--- a/src/zenserver/diag/diagsvcs.cpp
+++ b/src/zenserver/diag/diagsvcs.cpp
@@ -28,30 +28,6 @@ GetHealthTag()
using namespace std::literals;
-static bool
-ReadLogFile(const std::string& Path, StringBuilderBase& Out)
-{
- try
- {
- constexpr auto ReadSize = std::size_t{4096};
- auto FileStream = std::ifstream{Path};
-
- std::string Buf(ReadSize, '\0');
- while (FileStream.read(&Buf[0], ReadSize))
- {
- Out.Append(std::string_view(&Buf[0], FileStream.gcount()));
- }
- Out.Append(std::string_view(&Buf[0], FileStream.gcount()));
-
- return true;
- }
- catch (const std::exception&)
- {
- Out.Reset();
- return false;
- }
-}
-
HttpHealthService::HttpHealthService()
{
ZEN_MEMSCOPE(GetHealthTag());
@@ -95,10 +71,9 @@ HttpHealthService::HttpHealthService()
return m_HealthInfo.AbsLogPath.empty() ? m_HealthInfo.DataRoot / "logs/zenserver.log" : m_HealthInfo.AbsLogPath;
}();
- ExtendableStringBuilder<4096> Sb;
- if (ReadLogFile(Path.string(), Sb) && Sb.Size() > 0)
+ if (IoBuffer LogBuffer = IoBufferBuilder::MakeFromFile(Path))
{
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, Sb.ToView());
+ HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, LogBuffer);
}
else
{