proxygen
|
#include <TokenBucket.h>
Public Member Functions | |
BasicTokenBucket (double genRate, double burstSize, double zeroTime=0) noexcept | |
BasicTokenBucket (const BasicTokenBucket &other) noexcept=default | |
BasicTokenBucket & | operator= (const BasicTokenBucket &other) noexcept=default |
void | reset (double genRate, double burstSize, double nowInSeconds=defaultClockNow()) noexcept |
void | setCapacity (double tokens, double nowInSeconds) noexcept |
bool | consume (double toConsume, double nowInSeconds=defaultClockNow()) |
double | consumeOrDrain (double toConsume, double nowInSeconds=defaultClockNow()) |
double | available (double nowInSeconds=defaultClockNow()) const |
double | rate () const noexcept |
double | burst () const noexcept |
Static Public Member Functions | |
static double | defaultClockNow () noexcept(noexcept(Impl::defaultClockNow())) |
Private Types | |
using | Impl = BasicDynamicTokenBucket< Clock > |
Private Attributes | |
Impl | tokenBucket_ |
double | rate_ |
double | burstSize_ |
Specialization of BasicDynamicTokenBucket with a fixed token generation rate and a fixed maximum burst size.
Definition at line 221 of file TokenBucket.h.
|
private |
Definition at line 225 of file TokenBucket.h.
|
inlinenoexcept |
Construct a token bucket with a specific maximum rate and burst size.
genRate | Number of tokens to generate per second. |
burstSize | Maximum burst size. Must be greater than 0. |
zeroTime | Initial time at which to consider the token bucket starting to fill. Defaults to 0, so by default token bucket is "full" after construction. |
Definition at line 237 of file TokenBucket.h.
References folly::pushmi::__adl::noexcept(), and folly::BasicDynamicTokenBucket< Clock >::operator=().
|
defaultnoexcept |
Copy constructor.
Warning: not thread safe!
|
inline |
Returns the number of tokens currently available.
Thread-safe (but returned value may immediately be outdated).
Definition at line 347 of file TokenBucket.h.
Referenced by TEST().
|
inlinenoexcept |
Returns the maximum burst size.
Thread-safe (but returned value may immediately be outdated).
Definition at line 365 of file TokenBucket.h.
|
inline |
Attempts to consume some number of tokens. Tokens are first added to the bucket based on the time elapsed since the last attempt to consume tokens. Note: Attempts to consume more tokens than the burst size will always fail.
Thread-safe.
toConsume | The number of tokens to consume. |
nowInSeconds | Current time in seconds. Should be monotonically increasing from the nowInSeconds specified in this token bucket's constructor. |
Definition at line 318 of file TokenBucket.h.
Referenced by doTokenBucketTest(), TEST(), and TEST_P().
|
inline |
Similar to consume, but always consumes some number of tokens. If the bucket contains enough tokens - consumes toConsume tokens. Otherwise the bucket is drained.
Thread-safe.
toConsume | The number of tokens to consume. |
nowInSeconds | Current time in seconds. Should be monotonically increasing from the nowInSeconds specified in this token bucket's constructor. |
Definition at line 335 of file TokenBucket.h.
|
inlinestaticnoexcept |
Returns the current time in seconds since Epoch.
Definition at line 263 of file TokenBucket.h.
|
defaultnoexcept |
Copy-assignment operator.
Warning: not thread safe!
|
inlinenoexcept |
Returns the number of tokens generated per second.
Thread-safe (but returned value may immediately be outdated).
Definition at line 356 of file TokenBucket.h.
|
inlinenoexcept |
Change rate and burst size.
Warning: not thread safe!
genRate | Number of tokens to generate per second. |
burstSize | Maximum burst size. Must be greater than 0. |
nowInSeconds | Current time in seconds. Should be monotonically increasing from the nowInSeconds specified in this token bucket's constructor. |
Definition at line 278 of file TokenBucket.h.
References folly::BasicDynamicTokenBucket< Clock >::available().
Referenced by folly::BasicTokenBucket< Clock >::setCapacity().
|
inlinenoexcept |
Change number of tokens in bucket.
Warning: not thread safe!
tokens | Desired number of tokens in bucket after the call. |
nowInSeconds | Current time in seconds. Should be monotonically increasing from the nowInSeconds specified in this token bucket's constructor. |
Definition at line 300 of file TokenBucket.h.
References folly::BasicTokenBucket< Clock >::reset(), and tokens.
|
private |
Definition at line 372 of file TokenBucket.h.
|
private |
Definition at line 371 of file TokenBucket.h.
|
private |
Definition at line 370 of file TokenBucket.h.