Skip to content

Commit 20dd898

Browse files
guptaskvinser52
authored andcommitted
added per tier pool class rolling average latency (based on upstream PR)
1 parent 654578c commit 20dd898

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

388388
// TODO: per-tier
389389
(*stats_.allocAttempts)[pid][cid].inc();
@@ -481,8 +481,10 @@ CacheAllocator<CacheTrait>::allocateChainedItemInternal(
481481
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
482482

483483
util::RollingLatencyTracker rollTracker{
484-
(*stats_.classAllocLatency)[pid][cid]};
485-
484+
(*stats_.classAllocLatency)[tid][pid][cid]};
485+
486+
// TODO: per-tier? Right now stats_ are not used in any public periodic
487+
// worker
486488
(*stats_.allocAttempts)[pid][cid].inc();
487489

488490
void* memory = allocator_[tid]->allocate(pid, requiredSize);
@@ -2473,7 +2475,7 @@ ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
24732475
const auto& ac = pool.getAllocationClass(classId);
24742476

24752477
auto stats = ac.getStats();
2476-
stats.allocLatencyNs = (*stats_.classAllocLatency)[poolId][classId];
2478+
stats.allocLatencyNs = (*stats_.classAllocLatency)[tid][poolId][classId];
24772479
return stats;
24782480
}
24792481

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
@@ -164,18 +164,11 @@ struct Stats {
164164
}
165165
};
166166

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

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

186179
out << folly::sformat(
187180
"tid{:2} pid{:2} cid{:4} {:8.2f}{} usageFraction: {:4.2f} "
181+
"memorySize: {:8.2f}{} "
188182
"rollingAvgAllocLatency: {:8.2f}ns",
189183
tid, pid, cid, allocSize, allocSizeSuffix, acUsageFraction,
184+
memorySize, memorySizeSuffix,
190185
stats.allocLatencyNs.estimate())
191186
<< std::endl;
192187
});

0 commit comments

Comments
 (0)