From 85c411df89737c153528c1ef0d99305bd2e060de Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 8 Dec 2022 14:44:14 +0100 Subject: Path from handle perf improvement (#206) * Read recorded requests to memory before parsing This will more accurately simulate how requests comes in from a client * Make a fast path for GetFinalPathNameByHandleW Try to get the path with a fixes size buffer first to avoid always doing two calls to GetFinalPathNameByHandleW --- zenserver/cache/structuredcache.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'zenserver/cache/structuredcache.cpp') diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index f649efa01..a7571b4c4 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -149,14 +149,15 @@ namespace cache::detail { } } uint32_t BlockCount = gsl::narrow(MaxChunkPosition / RecordedRequestBlockSize) + 1; - m_IoBuffers.resize(BlockCount); + m_BlockFiles.resize(BlockCount); for (uint32_t BlockIndex = 0; BlockIndex < BlockCount; ++BlockIndex) { - m_IoBuffers[BlockIndex] = IoBufferBuilder::MakeFromFile(m_BasePath / fmt::format("chunks{}.bin", BlockIndex)); + m_BlockFiles[BlockIndex] = std::make_unique(); + m_BlockFiles[BlockIndex]->Open(m_BasePath / fmt::format("chunks{}.bin", BlockIndex), BasicFile::Mode::kRead); } return m_Entries.size(); } - void EndRead() { m_IoBuffers.clear(); } + void EndRead() { m_BlockFiles.clear(); } ZenContentType ReadRequest(uint64_t RequestIndex, IoBuffer& OutBuffer) const { @@ -171,19 +172,22 @@ namespace cache::detail { } if (Entry.Offset != ~0ull) { - uint32_t BlockIndex = gsl::narrow((Entry.Offset + Entry.Length) / RecordedRequestBlockSize); - uint64_t ChunkOffset = Entry.Offset - (BlockIndex * RecordedRequestBlockSize); - OutBuffer = IoBuffer(m_IoBuffers[BlockIndex], ChunkOffset, Entry.Length); + uint32_t BlockIndex = gsl::narrow((Entry.Offset + Entry.Length) / RecordedRequestBlockSize); + uint64_t ChunkOffset = Entry.Offset - (BlockIndex * RecordedRequestBlockSize); + OutBuffer = IoBuffer(Entry.Length); + MutableMemoryView OutView = OutBuffer.GetMutableView(); + m_BlockFiles[BlockIndex]->Read(OutView.GetData(), OutView.GetSize(), ChunkOffset); return Entry.ContentType; } - OutBuffer = IoBufferBuilder::MakeFromFile(m_BasePath / fmt::format("request{}.bin", RequestIndex)); + BasicFile ChunkFile; + ChunkFile.Open(m_BasePath / fmt::format("request{}.bin", RequestIndex), BasicFile::Mode::kRead); + OutBuffer = ChunkFile.ReadAll(); return Entry.ContentType; } std::filesystem::path m_BasePath; std::vector m_Entries; std::vector> m_BlockFiles; - std::vector m_IoBuffers; }; class DiskRequestRecorder : public IRequestRecorder -- cgit v1.2.3