proxygen
|
#include <RateLimiter.h>
Public Types | |
using | clock = chrono::coarse_steady_clock |
Public Member Functions | |
constexpr | IntervalRateLimiter (uint64_t maxPerInterval, clock::duration interval) |
bool | check () |
Private Member Functions | |
bool | checkSlow () |
Private Attributes | |
const uint64_t | maxPerInterval_ |
const clock::time_point::duration | interval_ |
std::atomic< uint64_t > | count_ {std::numeric_limits<uint64_t>::max()} |
std::atomic< clock::rep > | timestamp_ {0} |
A rate limiter that can rate limit events to N events per M milliseconds.
It is intended to be fast to check when messages are not being rate limited. When messages are being rate limited it is slightly slower, as it has to check the clock each time check() is called in this case.
Definition at line 34 of file RateLimiter.h.
Definition at line 36 of file RateLimiter.h.
|
inline |
Definition at line 38 of file RateLimiter.h.
References interval_.
|
inline |
Definition at line 43 of file RateLimiter.h.
References checkSlow(), count_, and maxPerInterval_.
|
private |
Definition at line 21 of file RateLimiter.cpp.
References count_, interval_, maxPerInterval_, now(), folly::chrono::coarse_steady_clock::now(), and timestamp_.
Referenced by check().
|
private |
Definition at line 60 of file RateLimiter.h.
Referenced by check(), and checkSlow().
|
private |
Definition at line 55 of file RateLimiter.h.
Referenced by checkSlow(), and IntervalRateLimiter().
|
private |
Definition at line 54 of file RateLimiter.h.
Referenced by check(), and checkSlow().
|
private |
Definition at line 64 of file RateLimiter.h.
Referenced by checkSlow().