Skip to content

Commit 5d61e8a

Browse files
guptaskbyrnedj
authored andcommitted
Rolling average class latency
Part 2. (multi-tier support) -------------------------------------- There is also an introduction to kMaxTiers in Cache.h - this should probably be split from this commit. added per tier pool class rolling average latency (based on upstream PR)
1 parent f060e08 commit 5d61e8a

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
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.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
27832783
// the allocation class in our memory allocator.
27842784
const auto cid = allocator_[tid]->getAllocationClassId(pid, requiredSize);
27852785
util::RollingLatencyTracker rollTracker{
2786-
(*stats_.classAllocLatency)[pid][cid]};
2786+
(*stats_.classAllocLatency)[tid][pid][cid]};
27872787

27882788
// TODO: per-tier
27892789
(*stats_.allocAttempts)[pid][cid].inc();
@@ -2895,7 +2895,7 @@ CacheAllocator<CacheTrait>::allocateChainedItemInternal(const Item& parent,
28952895
// TODO: per-tier? Right now stats_ are not used in any public periodic
28962896
// worker
28972897
util::RollingLatencyTracker rollTracker{
2898-
(*stats_.classAllocLatency)[pid][cid]};
2898+
(*stats_.classAllocLatency)[tid][pid][cid]};
28992899

29002900
(*stats_.allocAttempts)[pid][cid].inc();
29012901

@@ -4919,7 +4919,7 @@ ACStats CacheAllocator<CacheTrait>::getACStats(TierId tid,
49194919
const auto& pool = allocator_[tid]->getPool(poolId);
49204920
const auto& ac = pool.getAllocationClass(classId);
49214921
auto stats = ac.getStats();
4922-
stats.allocLatencyNs = (*stats_.classAllocLatency)[poolId][classId];
4922+
stats.allocLatencyNs = (*stats_.classAllocLatency)[tid][poolId][classId];
49234923
return stats;
49244924
}
49254925

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)