MCPcopy Create free account
hub / github.com/facebook/CacheLib / addValue

Method addValue

cachelib/allocator/MemoryMonitor.cpp:323–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321 : detectIncrease_(detectIncrease) {}
322
323void RateLimiter::addValue(int64_t value) {
324 if (windowSize_ < 2) {
325 // Window size not large enough to calculate rate of change.
326 // This effectively disables rate limiting.
327 return;
328 }
329 values_.push_back(value);
330 auto prevValue = values_.front();
331 // We may remove multiple values if window size shrinks
332 while (values_.size() > windowSize_) {
333 values_.pop_front();
334 }
335 if (detectIncrease_) {
336 rateOfChange_ = (value - prevValue) / static_cast<int64_t>(windowSize_);
337 } else {
338 rateOfChange_ = (prevValue - value) / static_cast<int64_t>(windowSize_);
339 }
340}
341
342size_t RateLimiter::throttle(int64_t delta) {
343 if (rateOfChange_ < 0 || windowSize_ < 2) {

Callers 5

checkFreeMemoryMethod · 0.80
checkResidentMemoryMethod · 0.80
TESTFunction · 0.80
trackValueMethod · 0.80
workMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by 1

TESTFunction · 0.64