Skip to content

Commit 3c87c49

Browse files
guptaskbyrnedj
authored andcommitted
Track latency of per item eviction/promotion between memory tiers
---------------------------------------------------------------- this can go with background evictors multi-tier part 1
1 parent 3328e4e commit 3c87c49

File tree

8 files changed

+28
-7
lines changed

8 files changed

+28
-7
lines changed

cachelib/allocator/Cache.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ void CacheBase::updateGlobalCacheStats(const std::string& statPrefix) const {
477477

478478
visitEstimates(uploadStatsNanoToMicro, stats.allocateLatencyNs,
479479
statPrefix + "allocate.latency_us");
480+
visitEstimates(uploadStatsNanoToMicro, stats.bgEvictLatencyNs,
481+
statPrefix + "background.eviction.latency_us");
482+
visitEstimates(uploadStatsNanoToMicro, stats.bgPromoteLatencyNs,
483+
statPrefix + "background.promotion.latency_us");
480484
visitEstimates(uploadStatsNanoToMicro, stats.moveChainedLatencyNs,
481485
statPrefix + "move.chained.latency_us");
482486
visitEstimates(uploadStatsNanoToMicro, stats.moveRegularLatencyNs,

cachelib/allocator/CacheAllocator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,7 @@ class CacheAllocator : public CacheBase {
20132013
unsigned int pid,
20142014
unsigned int cid,
20152015
size_t batch) {
2016+
util::LatencyTracker tracker{stats().bgEvictLatency_, batch};
20162017
auto& mmContainer = getMMContainer(tid, pid, cid);
20172018
size_t evictions = 0;
20182019
size_t evictionCandidates = 0;
@@ -2089,6 +2090,7 @@ class CacheAllocator : public CacheBase {
20892090
unsigned int pid,
20902091
unsigned int cid,
20912092
size_t batch) {
2093+
util::LatencyTracker tracker{stats().bgPromoteLatency_, batch};
20922094
auto& mmContainer = getMMContainer(tid, pid, cid);
20932095
size_t promotions = 0;
20942096
std::vector<Item*> candidates;
@@ -3004,7 +3006,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
30043006
uint32_t expiryTime,
30053007
bool fromBgThread,
30063008
bool evict) {
3007-
util::LatencyTracker tracker{stats().allocateLatency_};
3009+
util::LatencyTracker tracker{stats().allocateLatency_, static_cast<size_t>(!fromBgThread)};
30083010

30093011
SCOPE_FAIL { stats_.invalidAllocs.inc(); };
30103012

cachelib/allocator/CacheStats.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct SizeVerify {};
5656

5757
void Stats::populateGlobalCacheStats(GlobalCacheStats& ret) const {
5858
#ifndef SKIP_SIZE_VERIFY
59-
SizeVerify<sizeof(Stats)> a = SizeVerify<16288>{};
59+
SizeVerify<sizeof(Stats)> a = SizeVerify<16640>{};
6060
std::ignore = a;
6161
#endif
6262
ret.numCacheGets = numCacheGets.get();
@@ -105,6 +105,8 @@ void Stats::populateGlobalCacheStats(GlobalCacheStats& ret) const {
105105
ret.numNvmItemDestructorAllocErrors = numNvmItemDestructorAllocErrors.get();
106106

107107
ret.allocateLatencyNs = this->allocateLatency_.estimate();
108+
ret.bgEvictLatencyNs = this->bgEvictLatency_.estimate();
109+
ret.bgPromoteLatencyNs = this->bgPromoteLatency_.estimate();
108110
ret.moveChainedLatencyNs = this->moveChainedLatency_.estimate();
109111
ret.moveRegularLatencyNs = this->moveRegularLatency_.estimate();
110112
ret.nvmLookupLatencyNs = this->nvmLookupLatency_.estimate();

cachelib/allocator/CacheStats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ struct GlobalCacheStats {
529529

530530
// latency and percentile stats of various cachelib operations
531531
util::PercentileStats::Estimates allocateLatencyNs{};
532+
util::PercentileStats::Estimates bgEvictLatencyNs{};
533+
util::PercentileStats::Estimates bgPromoteLatencyNs{};
532534
util::PercentileStats::Estimates moveChainedLatencyNs{};
533535
util::PercentileStats::Estimates moveRegularLatencyNs{};
534536
util::PercentileStats::Estimates nvmLookupLatencyNs{};

cachelib/allocator/CacheStatsInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ struct Stats {
189189

190190
// latency stats of various cachelib operations
191191
mutable util::PercentileStats allocateLatency_;
192+
mutable util::PercentileStats bgEvictLatency_;
193+
mutable util::PercentileStats bgPromoteLatency_;
192194
mutable util::PercentileStats moveChainedLatency_;
193195
mutable util::PercentileStats moveRegularLatency_;
194196
mutable util::PercentileStats nvmLookupLatency_;

cachelib/cachebench/cache/Cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,8 @@ Stats Cache<Allocator>::getStats() const {
12171217
static_cast<int64_t>(itemRecords_.count()) - totalDestructor_;
12181218

12191219
ret.cacheAllocateLatencyNs = cacheStats.allocateLatencyNs;
1220+
ret.cacheBgEvictLatencyNs = cacheStats.bgEvictLatencyNs;
1221+
ret.cacheBgPromoteLatencyNs = cacheStats.bgPromoteLatencyNs;
12201222
ret.cacheFindLatencyNs = cacheFindLatency_.estimate();
12211223

12221224
// Populate counters.

cachelib/cachebench/cache/CacheStats.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct Stats {
7070
uint64_t numNvmItemRemovedSetSize{0};
7171

7272
util::PercentileStats::Estimates cacheAllocateLatencyNs;
73+
util::PercentileStats::Estimates cacheBgEvictLatencyNs;
74+
util::PercentileStats::Estimates cacheBgPromoteLatencyNs;
7375
util::PercentileStats::Estimates cacheFindLatencyNs;
7476

7577
double nvmReadLatencyMicrosP50{0};
@@ -295,6 +297,8 @@ struct Stats {
295297

296298
printLatencies("Cache Find API latency", cacheFindLatencyNs);
297299
printLatencies("Cache Allocate API latency", cacheAllocateLatencyNs);
300+
printLatencies("Cache Background Eviction API latency", cacheBgEvictLatencyNs);
301+
printLatencies("Cache Background Promotion API latency", cacheBgPromoteLatencyNs);
298302
}
299303
}
300304

@@ -535,6 +539,8 @@ struct Stats {
535539

536540
counters["find_latency_p99"] = cacheFindLatencyNs.p99;
537541
counters["alloc_latency_p99"] = cacheAllocateLatencyNs.p99;
542+
counters["bg_evict_latency_p99"] = cacheBgEvictLatencyNs.p99;
543+
counters["bg_promote_latency_p99"] = cacheBgPromoteLatencyNs.p99;
538544

539545
counters["ram_hit_rate"] = calcInvertPctFn(numCacheGetMiss, numCacheGets);
540546
counters["nvm_hit_rate"] = calcInvertPctFn(numCacheGetMiss, numCacheGets);

cachelib/common/PercentileStats.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,24 @@ class PercentileStats {
107107

108108
class LatencyTracker {
109109
public:
110-
explicit LatencyTracker(PercentileStats& stats)
111-
: stats_(&stats), begin_(std::chrono::steady_clock::now()) {}
110+
explicit LatencyTracker(PercentileStats& stats, size_t nSamples = 1)
111+
: stats_(&stats), nSamples_(nSamples), begin_(std::chrono::steady_clock::now()) {}
112112
LatencyTracker() {}
113113
~LatencyTracker() {
114-
if (stats_) {
114+
if (nSamples_ > 0 && stats_) {
115115
auto tp = std::chrono::steady_clock::now();
116116
auto diffNanos =
117117
std::chrono::duration_cast<std::chrono::nanoseconds>(tp - begin_)
118118
.count();
119-
stats_->trackValue(static_cast<double>(diffNanos), tp);
119+
stats_->trackValue(static_cast<double>(diffNanos/nSamples_), tp);
120120
}
121121
}
122122

123123
LatencyTracker(const LatencyTracker&) = delete;
124124
LatencyTracker& operator=(const LatencyTracker&) = delete;
125125

126126
LatencyTracker(LatencyTracker&& rhs) noexcept
127-
: stats_(rhs.stats_), begin_(rhs.begin_) {
127+
: stats_(rhs.stats_), nSamples_(rhs.nSamples_), begin_(rhs.begin_) {
128128
rhs.stats_ = nullptr;
129129
}
130130

@@ -138,6 +138,7 @@ class LatencyTracker {
138138

139139
private:
140140
PercentileStats* stats_{nullptr};
141+
size_t nSamples_{1};
141142
std::chrono::time_point<std::chrono::steady_clock> begin_;
142143
};
143144
} // namespace util

0 commit comments

Comments
 (0)