Skip to content

Commit b99f2b3

Browse files
authored
Merge pull request #91 from guptask/tier_eviction_latency
Track latency of per item eviction/promotion between memory tiers
2 parents 09d7bab + 8d2c390 commit b99f2b3

File tree

14 files changed

+36
-14
lines changed

14 files changed

+36
-14
lines changed

cachelib/allocator/Cache.cpp

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

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

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,16 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
426426
uint32_t expiryTime,
427427
bool fromBgThread,
428428
bool evict) {
429-
util::LatencyTracker tracker{stats().allocateLatency_};
430-
429+
util::LatencyTracker tracker{stats().allocateLatency_, static_cast<size_t>(!fromBgThread)};
431430
SCOPE_FAIL { stats_.invalidAllocs.inc(); };
432431

433432
// number of bytes required for this item
434433
const auto requiredSize = Item::getRequiredSize(key, size);
435434

436435
// the allocation class in our memory allocator.
437436
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
438-
util::RollingLatencyTracker rollTracker{
439-
(*stats_.classAllocLatency)[tid][pid][cid]};
437+
438+
util::RollingLatencyTracker rollTracker{(*stats_.classAllocLatency)[tid][pid][cid]};
440439

441440
(*stats_.allocAttempts)[tid][pid][cid].inc();
442441

cachelib/allocator/CacheAllocator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,8 @@ class CacheAllocator : public CacheBase {
20162016
// exposed for the background evictor to iterate through the memory and evict
20172017
// in batch. This should improve insertion path for tiered memory config
20182018
size_t traverseAndEvictItems(unsigned int tid, unsigned int pid, unsigned int cid, size_t batch) {
2019-
auto& mmContainer = getMMContainer(tid, pid, cid);
2019+
util::LatencyTracker tracker{stats().bgEvictLatency_, batch};
2020+
auto& mmContainer = getMMContainer(tid, pid, cid);
20202021
size_t evictions = 0;
20212022
size_t evictionCandidates = 0;
20222023
std::vector<Item*> candidates;
@@ -2089,6 +2090,7 @@ auto& mmContainer = getMMContainer(tid, pid, cid);
20892090
}
20902091

20912092
size_t traverseAndPromoteItems(unsigned int tid, unsigned int pid, unsigned int cid, 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;

cachelib/allocator/CacheStats.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ void Stats::populateGlobalCacheStats(GlobalCacheStats& ret) const {
106106
ret.numNvmItemDestructorAllocErrors = numNvmItemDestructorAllocErrors.get();
107107

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

cachelib/allocator/CacheStats.h

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

511511
// latency and percentile stats of various cachelib operations
512512
util::PercentileStats::Estimates allocateLatencyNs{};
513+
util::PercentileStats::Estimates bgEvictLatencyNs{};
514+
util::PercentileStats::Estimates bgPromoteLatencyNs{};
513515
util::PercentileStats::Estimates moveChainedLatencyNs{};
514516
util::PercentileStats::Estimates moveRegularLatencyNs{};
515517
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-inl.h

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

745745
ret.cacheAllocateLatencyNs = cacheStats.allocateLatencyNs;
746+
ret.cacheBgEvictLatencyNs = cacheStats.bgEvictLatencyNs;
747+
ret.cacheBgPromoteLatencyNs = cacheStats.bgPromoteLatencyNs;
746748
ret.cacheFindLatencyNs = cacheFindLatency_.estimate();
747749

748750
// Populate counters.

cachelib/cachebench/cache/CacheStats.h

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

9393
util::PercentileStats::Estimates cacheAllocateLatencyNs;
94+
util::PercentileStats::Estimates cacheBgEvictLatencyNs;
95+
util::PercentileStats::Estimates cacheBgPromoteLatencyNs;
9496
util::PercentileStats::Estimates cacheFindLatencyNs;
9597

9698
double nvmReadLatencyMicrosP50{0};
@@ -282,6 +284,8 @@ struct Stats {
282284

283285
printLatencies("Cache Find API latency", cacheFindLatencyNs);
284286
printLatencies("Cache Allocate API latency", cacheAllocateLatencyNs);
287+
printLatencies("Cache Background Eviction API latency", cacheBgEvictLatencyNs);
288+
printLatencies("Cache Background Promotion API latency", cacheBgPromoteLatencyNs);
285289
}
286290
}
287291

@@ -510,6 +514,8 @@ struct Stats {
510514

511515
counters["find_latency_p99"] = cacheFindLatencyNs.p99;
512516
counters["alloc_latency_p99"] = cacheAllocateLatencyNs.p99;
517+
counters["bg_evict_latency_p99"] = cacheBgEvictLatencyNs.p99;
518+
counters["bg_promote_latency_p99"] = cacheBgPromoteLatencyNs.p99;
513519

514520
counters["ram_hit_rate"] = calcInvertPctFn(numCacheGetMiss, numCacheGets);
515521
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

cachelib/external/fbthrift

Submodule fbthrift updated 4984 files

0 commit comments

Comments
 (0)