| 340 | } |
| 341 | |
| 342 | size_t RateLimiter::throttle(int64_t delta) { |
| 343 | if (rateOfChange_ < 0 || windowSize_ < 2) { |
| 344 | return delta; // No throttling |
| 345 | } |
| 346 | // Fully throttled when we either have insufficient number of samples or |
| 347 | // rate of change is faster than proposed delta change. |
| 348 | if (values_.size() < windowSize_ || delta < rateOfChange_) { |
| 349 | return 0; |
| 350 | } |
| 351 | // Throttle down delta by rate of change. The greater the rate of change, the |
| 352 | // more the delta is throttled. |
| 353 | return delta - rateOfChange_; |
| 354 | } |
| 355 | |
| 356 | } // namespace facebook::cachelib |