Skip to content

Commit 6b41f3b

Browse files
guptaskbyrnedj
authored andcommitted
added per tier pool class rolling average latency (based on upstream PR)
1 parent 7692eba commit 6b41f3b

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

cachelib/allocator/Cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class CacheBase {
8585
CacheBase(CacheBase&&) = default;
8686
CacheBase& operator=(CacheBase&&) = default;
8787

88+
// TODO: come up with some reasonable number
89+
static constexpr unsigned kMaxTiers = 2;
90+
8891
// Get a string referring to the cache name for this cache
8992
virtual const std::string getCacheName() const = 0;
9093

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
387387
// the allocation class in our memory allocator.
388388
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
389389
util::RollingLatencyTracker rollTracker{
390-
(*stats_.classAllocLatency)[pid][cid]};
390+
(*stats_.classAllocLatency)[tid][pid][cid]};
391391

392392
// TODO: per-tier
393393
(*stats_.allocAttempts)[pid][cid].inc();
@@ -485,8 +485,10 @@ CacheAllocator<CacheTrait>::allocateChainedItemInternal(
485485
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
486486

487487
util::RollingLatencyTracker rollTracker{
488-
(*stats_.classAllocLatency)[pid][cid]};
489-
488+
(*stats_.classAllocLatency)[tid][pid][cid]};
489+
490+
// TODO: per-tier? Right now stats_ are not used in any public periodic
491+
// worker
490492
(*stats_.allocAttempts)[pid][cid].inc();
491493

492494
void* memory = allocator_[tid]->allocate(pid, requiredSize);
@@ -2663,7 +2665,7 @@ ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
26632665
const auto& ac = pool.getAllocationClass(classId);
26642666

26652667
auto stats = ac.getStats();
2666-
stats.allocLatencyNs = (*stats_.classAllocLatency)[poolId][classId];
2668+
stats.allocLatencyNs = (*stats_.classAllocLatency)[tid][poolId][classId];
26672669
return stats;
26682670
}
26692671

cachelib/allocator/CacheStats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void Stats::init() {
4545
initToZero(*chainedItemEvictions);
4646
initToZero(*regularItemEvictions);
4747

48-
classAllocLatency = std::make_unique<PerPoolClassRollingStats>();
48+
classAllocLatency = std::make_unique<PerTierPoolClassRollingStats>();
4949
}
5050

5151
template <int>

cachelib/allocator/CacheStats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "cachelib/allocator/memory/Slab.h"
2626
#include "cachelib/common/FastStats.h"
2727
#include "cachelib/common/PercentileStats.h"
28+
#include "cachelib/common/RollingStats.h"
2829
#include "cachelib/common/Time.h"
2930

3031
namespace facebook {

cachelib/allocator/CacheStatsInternal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,13 @@ struct Stats {
230230
std::unique_ptr<PerPoolClassAtomicCounters> chainedItemEvictions{};
231231
std::unique_ptr<PerPoolClassAtomicCounters> regularItemEvictions{};
232232

233-
using PerPoolClassRollingStats =
233+
using PerTierPoolClassRollingStats = std::array<
234234
std::array<std::array<util::RollingStats, MemoryAllocator::kMaxClasses>,
235-
MemoryPoolManager::kMaxPools>;
235+
MemoryPoolManager::kMaxPools>,
236+
CacheBase::kMaxTiers>;
236237

237238
// rolling latency tracking for every alloc class in every pool
238-
std::unique_ptr<PerPoolClassRollingStats> classAllocLatency{};
239+
std::unique_ptr<PerTierPoolClassRollingStats> classAllocLatency{};
239240

240241
// Eviction failures due to parent cannot be removed from access container
241242
AtomicCounter evictFailParentAC{0};

0 commit comments

Comments
 (0)