Skip to content

Commit 6b932f8

Browse files
committed
bug fixes - changed timer to MS for bg evict
1 parent b29b1be commit 6b932f8

File tree

8 files changed

+22
-57
lines changed

8 files changed

+22
-57
lines changed

cachelib/allocator/BackgroundEvictorStrategy.cpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

cachelib/allocator/BackgroundEvictorStrategy.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@ namespace cachelib {
3535
class BackgroundEvictorStrategy {
3636

3737
public:
38-
BackgroundEvictorStrategy() {}
3938

40-
~BackgroundEvictorStrategy() {}
41-
42-
unsigned int calculateBatchSize(const CacheBase& cache,
39+
virtual unsigned int calculateBatchSize(const CacheBase& cache,
4340
unsigned int tid,
4441
PoolId pid,
45-
ClassId cid );
42+
ClassId cid ) = 0;
4643

47-
bool shouldEvict(const CacheBase& cache,
44+
virtual bool shouldEvict(const CacheBase& cache,
4845
unsigned int tid,
4946
PoolId pid,
50-
ClassId cid );
47+
ClassId cid ) = 0;
5148

5249

5350
};

cachelib/allocator/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ add_library (cachelib_allocator
2727
${SERIALIZE_THRIFT_FILES}
2828
${DATASTRUCT_SERIALIZE_THRIFT_FILES}
2929
${MEMORY_SERIALIZE_THRIFT_FILES}
30-
BackgroundEvictorStrategy.cpp
3130
CacheAllocator.cpp
3231
Cache.cpp
3332
CacheDetails.cpp

cachelib/allocator/CacheAllocatorConfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class CacheAllocatorConfig {
270270
// to evict to the next tier
271271
CacheAllocatorConfig& enableBackgroundEvictor(
272272
std::shared_ptr<BackgroundEvictorStrategy> backgroundEvictorStrategy,
273-
std::chrono::seconds regularInterval);
273+
std::chrono::milliseconds regularInterval);
274274

275275
// This enables an optimization for Pool rebalancing and resizing.
276276
// The rough idea is to ensure only the least useful items are evicted when
@@ -440,7 +440,7 @@ class CacheAllocatorConfig {
440440
std::chrono::milliseconds poolRebalanceInterval{std::chrono::seconds{1}};
441441

442442
// time interval to sleep between runs of the background evictor
443-
std::chrono::milliseconds backgroundEvictorInterval{std::chrono::seconds{1}};
443+
std::chrono::milliseconds backgroundEvictorInterval{std::chrono::milliseconds{1000}};
444444

445445
// Free slabs pro-actively if the ratio of number of freeallocs to
446446
// the number of allocs per slab in a slab class is above this
@@ -984,7 +984,7 @@ CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::enablePoolRebalancing(
984984
template <typename T>
985985
CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::enableBackgroundEvictor(
986986
std::shared_ptr<BackgroundEvictorStrategy> strategy,
987-
std::chrono::seconds interval) {
987+
std::chrono::milliseconds interval) {
988988
backgroundEvictorStrategy = strategy;
989989
backgroundEvictorInterval = interval;
990990
return *this;

cachelib/cachebench/cache/Cache-inl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Cache<Allocator>::Cache(const CacheConfig& config,
6262

6363
allocatorConfig_.enableBackgroundEvictor(
6464
config_.getBackgroundEvictorStrategy(),
65-
std::chrono::seconds(config_.backgroundEvictorIntervalSec));
65+
std::chrono::milliseconds(config_.backgroundEvictorIntervalMilSec));
6666

6767
if (config_.moveOnSlabRelease && movingSync != nullptr) {
6868
allocatorConfig_.enableMovingOnSlabRelease(
@@ -523,6 +523,9 @@ Stats Cache<Allocator>::getStats() const {
523523
ret.numItems = aggregate.numItems();
524524
ret.allocAttempts = cacheStats.allocAttempts;
525525
ret.allocFailures = cacheStats.allocFailures;
526+
527+
ret.numBackgroundEvictions = cacheStats.backgroundEvictorStats.numEvictedItems;
528+
ret.numBackgroundEvictorRuns = cacheStats.backgroundEvictorStats.numTraversals;
526529

527530
ret.numCacheGets = cacheStats.numCacheGets;
528531
ret.numCacheGetMiss = cacheStats.numCacheGetMiss;

cachelib/cachebench/cache/CacheStats.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ struct Stats {
3232
uint64_t allocAttempts{0};
3333
uint64_t allocFailures{0};
3434

35+
uint64_t numBackgroundEvictions{0};
36+
uint64_t numBackgroundEvictorRuns{0};
37+
3538
uint64_t numCacheGets{0};
3639
uint64_t numCacheGetMiss{0};
3740
uint64_t numRamDestructorCalls{0};
@@ -114,6 +117,11 @@ struct Stats {
114117
invertPctFn(allocFailures, allocAttempts))
115118
<< std::endl;
116119
out << folly::sformat("RAM Evictions : {:,}", numEvictions) << std::endl;
120+
121+
122+
out << folly::sformat("Background Tier 0 Evictions : {:,}", numBackgroundEvictions) << std::endl;
123+
124+
out << folly::sformat("Background Tier 0 Eviction Runs : {:,}", numBackgroundEvictorRuns) << std::endl;
117125

118126
if (numCacheGets > 0) {
119127
out << folly::sformat("Cache Gets : {:,}", numCacheGets) << std::endl;

cachelib/cachebench/util/CacheConfig.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
3030
JSONSetVal(configJson, allocator);
3131
JSONSetVal(configJson, cacheSizeMB);
3232
JSONSetVal(configJson, poolRebalanceIntervalSec);
33-
JSONSetVal(configJson, backgroundEvictorIntervalSec);
33+
JSONSetVal(configJson, backgroundEvictorIntervalMilSec);
3434
JSONSetVal(configJson, moveOnSlabRelease);
3535
JSONSetVal(configJson, rebalanceStrategy);
3636
JSONSetVal(configJson, rebalanceMinSlabs);
@@ -143,7 +143,7 @@ std::shared_ptr<RebalanceStrategy> CacheConfig::getRebalanceStrategy() const {
143143
}
144144

145145
std::shared_ptr<BackgroundEvictorStrategy> CacheConfig::getBackgroundEvictorStrategy() const {
146-
if (backgroundEvictorIntervalSec == 0) {
146+
if (backgroundEvictorIntervalMilSec == 0) {
147147
return nullptr;
148148
}
149149

cachelib/cachebench/util/CacheConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct CacheConfig : public JSONConfig {
7272

7373
uint64_t cacheSizeMB{0};
7474
uint64_t poolRebalanceIntervalSec{0};
75-
uint64_t backgroundEvictorIntervalSec{0};
75+
uint64_t backgroundEvictorIntervalMilSec{0};
7676
std::string rebalanceStrategy;
7777
std::string backgroundEvictorStrategy;
7878
double freeThreshold{0.01}; //keep 1% of space free

0 commit comments

Comments
 (0)