Skip to content

Commit bab780a

Browse files
guptaskbyrnedj
authored andcommitted
added per tier pool class rolling average latency (based on upstream PR)
1 parent e74fa40 commit bab780a

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
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};

cachelib/cachebench/cache/CacheStats.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,11 @@ struct Stats {
165165
}
166166
};
167167

168+
168169
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
169170
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
170171
auto [memorySizeSuffix, memorySize] =
171172
formatMemory(stats.totalAllocatedSize());
172-
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8.2f}{} memorySize: {:8.2f}{}",
173-
tid, pid, cid, allocSize, allocSizeSuffix, memorySize,
174-
memorySizeSuffix)
175-
<< std::endl;
176-
});
177-
178-
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
179-
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
180173

181174
// If the pool is not full, extrapolate usageFraction for AC assuming it
182175
// will grow at the same rate. This value will be the same for all ACs.
@@ -186,8 +179,10 @@ struct Stats {
186179

187180
out << folly::sformat(
188181
"tid{:2} pid{:2} cid{:4} {:8.2f}{} usageFraction: {:4.2f} "
182+
"memorySize: {:8.2f}{} "
189183
"rollingAvgAllocLatency: {:8.2f}ns",
190184
tid, pid, cid, allocSize, allocSizeSuffix, acUsageFraction,
185+
memorySize, memorySizeSuffix,
191186
stats.allocLatencyNs.estimate())
192187
<< std::endl;
193188
});

0 commit comments

Comments
 (0)