Skip to content

Commit ea33665

Browse files
guptaskvinser52
authored andcommitted
added per tier pool class rolling average latency (based on upstream PR)
1 parent c33686e commit ea33665

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
@@ -404,7 +404,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
404404
// the allocation class in our memory allocator.
405405
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
406406
util::RollingLatencyTracker rollTracker{
407-
(*stats_.classAllocLatency)[pid][cid]};
407+
(*stats_.classAllocLatency)[tid][pid][cid]};
408408

409409
// TODO: per-tier
410410
(*stats_.allocAttempts)[pid][cid].inc();
@@ -511,8 +511,10 @@ CacheAllocator<CacheTrait>::allocateChainedItemInternal(const Item& parent,
511511
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
512512

513513
util::RollingLatencyTracker rollTracker{
514-
(*stats_.classAllocLatency)[pid][cid]};
515-
514+
(*stats_.classAllocLatency)[tid][pid][cid]};
515+
516+
// TODO: per-tier? Right now stats_ are not used in any public periodic
517+
// worker
516518
(*stats_.allocAttempts)[pid][cid].inc();
517519

518520
void* memory = allocator_[tid]->allocate(pid, requiredSize);
@@ -2536,7 +2538,7 @@ ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
25362538
const auto& ac = pool.getAllocationClass(classId);
25372539

25382540
auto stats = ac.getStats();
2539-
stats.allocLatencyNs = (*stats_.classAllocLatency)[poolId][classId];
2541+
stats.allocLatencyNs = (*stats_.classAllocLatency)[tid][poolId][classId];
25402542
return stats;
25412543
}
25422544

cachelib/allocator/CacheStats.cpp

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

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

5050
template <int>

cachelib/allocator/CacheStats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "cachelib/allocator/memory/Slab.h"
2828
#include "cachelib/common/FastStats.h"
2929
#include "cachelib/common/PercentileStats.h"
30+
#include "cachelib/common/RollingStats.h"
3031
#include "cachelib/common/Time.h"
3132

3233
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
@@ -203,18 +203,11 @@ struct Stats {
203203
}
204204
};
205205

206+
206207
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
207208
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
208209
auto [memorySizeSuffix, memorySize] =
209210
formatMemory(stats.totalAllocatedSize());
210-
out << folly::sformat("tid{:2} pid{:2} cid{:4} {:8.2f}{} memorySize: {:8.2f}{}",
211-
tid, pid, cid, allocSize, allocSizeSuffix, memorySize,
212-
memorySizeSuffix)
213-
<< std::endl;
214-
});
215-
216-
foreachAC([&](auto tid, auto pid, auto cid, auto stats) {
217-
auto [allocSizeSuffix, allocSize] = formatMemory(stats.allocSize);
218211

219212
// If the pool is not full, extrapolate usageFraction for AC assuming it
220213
// will grow at the same rate. This value will be the same for all ACs.
@@ -224,8 +217,10 @@ struct Stats {
224217

225218
out << folly::sformat(
226219
"tid{:2} pid{:2} cid{:4} {:8.2f}{} usageFraction: {:4.2f} "
220+
"memorySize: {:8.2f}{} "
227221
"rollingAvgAllocLatency: {:8.2f}ns",
228222
tid, pid, cid, allocSize, allocSizeSuffix, acUsageFraction,
223+
memorySize, memorySizeSuffix,
229224
stats.allocLatencyNs.estimate())
230225
<< std::endl;
231226
});

0 commit comments

Comments
 (0)