From f99a4687ff78e2823332e09d0e35cb16f361ff93 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Wed, 14 Jan 2026 10:32:37 +0100 Subject: 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. --- src/zenserver/diag/diagsvcs.cpp | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'src/zenserver') 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 { -- cgit v1.2.3