Skip to content

Commit 5ab6ea1

Browse files
guptaskbyrnedj
authored andcommitted
added per tier pool class rolling average latency (based on upstream PR)
1 parent 28fd271 commit 5ab6ea1

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
@@ -385,7 +385,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
385385
// the allocation class in our memory allocator.
386386
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
387387
util::RollingLatencyTracker rollTracker{
388-
(*stats_.classAllocLatency)[pid][cid]};
388+
(*stats_.classAllocLatency)[tid][pid][cid]};
389389

390390
// TODO: per-tier
391391
(*stats_.allocAttempts)[pid][cid].inc();
@@ -483,8 +483,10 @@ CacheAllocator<CacheTrait>::allocateChainedItemInternal(
483483
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
484484

485485
util::RollingLatencyTracker rollTracker{
486-
(*stats_.classAllocLatency)[pid][cid]};
487-
486+
(*stats_.classAllocLatency)[tid][pid][cid]};
487+
488+
// TODO: per-tier? Right now stats_ are not used in any public periodic
489+
// worker
488490
(*stats_.allocAttempts)[pid][cid].inc();
489491

490492
void* memory = allocator_[tid]->allocate(pid, requiredSize);
@@ -2450,7 +2452,7 @@ ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
24502452
const auto& ac = pool.getAllocationClass(classId);
24512453

24522454
auto stats = ac.getStats();
2453-
stats.allocLatencyNs = (*stats_.classAllocLatency)[poolId][classId];
2455+
stats.allocLatencyNs = (*stats_.classAllocLatency)[tid][poolId][classId];
24542456
return stats;
24552457
}
24562458

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)