diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-07 22:20:35 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-12 22:20:47 +0200 |
| commit | 4e7d13b038bda5806647530ddfca9de825001a5f (patch) | |
| tree | 8fe5f4c28a7bd8c80aaeb7e914e774190e0bdc76 /zenserver/cache/structuredcachestore.cpp | |
| parent | structured cache with block store (diff) | |
| download | zen-4e7d13b038bda5806647530ddfca9de825001a5f.tar.xz zen-4e7d13b038bda5806647530ddfca9de825001a5f.zip | |
cleaner GatherReferences
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 91 |
1 files changed, 56 insertions, 35 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index c5ccef523..5c71ad7bb 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -1659,9 +1659,20 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx) { ZEN_TRACE_CPU("Z$::DiskLayer::CacheBucket::GatherReferences"); - Stopwatch Timer; - const auto Guard = MakeGuard([this, &Timer] { - ZEN_INFO("gathered references from '{}' in {}", m_BucketDir / m_BucketName, NiceTimeSpanMs(Timer.GetElapsedTimeMs())); + uint64_t WriteBlockTimeUs = 0; + uint64_t WriteBlockLongestTimeUs = 0; + uint64_t ReadBlockTimeUs = 0; + uint64_t ReadBlockLongestTimeUs = 0; + + Stopwatch TotalTimer; + const auto _ = MakeGuard([this, &TotalTimer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs, &ReadBlockTimeUs, &ReadBlockLongestTimeUs] { + ZEN_INFO("gathered references from '{}' in {} write lock: {} ({}), read lock: {} ({})", + m_BucketDir / m_BucketName, + NiceTimeSpanMs(TotalTimer.GetElapsedTimeMs()), + NiceLatencyNs(WriteBlockTimeUs), + NiceLatencyNs(WriteBlockLongestTimeUs), + NiceLatencyNs(ReadBlockTimeUs), + NiceLatencyNs(ReadBlockLongestTimeUs)); }); const GcClock::TimePoint ExpireTime = @@ -1669,60 +1680,70 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx) const GcClock::Tick ExpireTicks = ExpireTime.time_since_epoch().count(); - RwLock::SharedLockScope _(m_IndexLock); - - std::vector<IoHash> ValidKeys; - std::vector<IoHash> ExpiredKeys; - std::vector<IoHash> Cids; - std::vector<IndexMap::value_type> Entries(m_Index.begin(), m_Index.end()); - - std::sort(Entries.begin(), Entries.end(), [](const auto& LHS, const auto& RHS) { - return LHS.second.LastAccess < RHS.second.LastAccess; - }); + IndexMap Index; + { + RwLock::SharedLockScope __(m_IndexLock); + Stopwatch Timer; + const auto ___ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] { + uint64_t ElapsedUs = Timer.GetElapsedTimeUs(); + WriteBlockTimeUs += ElapsedUs; + WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs); + }); + Index = m_Index; + } - const auto ValidIt = std::lower_bound(Entries.begin(), Entries.end(), ExpireTicks, [](const auto& Kv, auto Ticks) { - const IndexEntry& Entry = Kv.second; - return Entry.LastAccess < Ticks; - }); + std::vector<IoHash> ExpiredKeys; + ExpiredKeys.reserve(1024); + for (const auto& Entry : Index) + { + if (Entry.second.LastAccess < ExpireTicks) + { + ExpiredKeys.push_back(Entry.first); + } + } + std::vector<IoHash> Cids; Cids.reserve(1024); - for (auto Kv = ValidIt; Kv != Entries.end(); ++Kv) + for (const auto& Key : ExpiredKeys) { - const IoHash& Key = Kv->first; - const DiskLocation& Loc = Kv->second.Location; + IndexEntry& Entry = Index[Key]; + const DiskLocation& Loc = Entry.Location; if (Loc.IsFlagSet(DiskLocation::kStructured)) { + if (Cids.size() > 1024) + { + GcCtx.ContributeCids(Cids); + Cids.clear(); + } + ZenCacheValue CacheValue; - if (!GetInlineCacheValue(Loc, CacheValue)) { - GetStandaloneCacheValue(Loc, Key, CacheValue); + RwLock::SharedLockScope __(m_IndexLock); + Stopwatch Timer; + const auto ___ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] { + uint64_t ElapsedUs = Timer.GetElapsedTimeUs(); + WriteBlockTimeUs += ElapsedUs; + WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs); + }); + if (!GetInlineCacheValue(Loc, CacheValue)) + { + GetStandaloneCacheValue(Loc, Key, CacheValue); + } } if (CacheValue.Value) { ZEN_ASSERT(CacheValue.Value.GetContentType() == ZenContentType::kCbObject); - if (Cids.size() > 1024) - { - GcCtx.ContributeCids(Cids); - Cids.clear(); - } CbObject Obj(SharedBuffer{CacheValue.Value}); Obj.IterateAttachments([&Cids](CbFieldView Field) { Cids.push_back(Field.AsAttachment()); }); } } } - _.ReleaseNow(); - - ValidKeys.reserve(std::distance(ValidIt, Entries.end())); - ExpiredKeys.reserve(std::distance(Entries.begin(), ValidIt)); - - std::transform(ValidIt, Entries.end(), std::back_inserter(ValidKeys), [](const auto& Kv) { return Kv.first; }); - std::transform(Entries.begin(), ValidIt, std::back_inserter(ExpiredKeys), [](const auto& Kv) { return Kv.first; }); GcCtx.ContributeCids(Cids); - GcCtx.ContributeCacheKeys(m_BucketName, std::move(ValidKeys), std::move(ExpiredKeys)); + GcCtx.ContributeCacheKeys(m_BucketName, {}, std::move(ExpiredKeys)); } void |