CppCommon
1.0.4.1
C++ Common Library
|
Token bucket rate limit algorithm. More...
#include <token_bucket.h>
Public Member Functions | |
TokenBucket (uint64_t rate, uint64_t burst) | |
Initialize the token bucket. More... | |
TokenBucket (const TokenBucket &tb) | |
TokenBucket (TokenBucket &&)=delete | |
~TokenBucket ()=default | |
TokenBucket & | operator= (const TokenBucket &tb) |
TokenBucket & | operator= (TokenBucket &&)=delete |
bool | Consume (uint64_t tokens=1) |
Try to consume the given count of tokens. More... | |
Token bucket rate limit algorithm.
Lock-free implementation of the token bucket rate limit algorithm.
The token bucket is an algorithm used in packet switched computer networks and telecommunications networks. It can be used to check that data transmissions, in the form of packets, conform to defined limits on bandwidth and burstiness (a measure of the unevenness or variations in the traffic flow).
Thread-safe.
https://en.wikipedia.org/wiki/Token_bucket
Definition at line 33 of file token_bucket.h.
|
inline |
Initialize the token bucket.
Initializes the token bucket to accumulate the given count of tokens per second, with a maximum of burst tokens.
rate | - Rate of tokens per second to accumulate in the token bucket |
burst | - Maximum of burst tokens in the token bucket |
Definition at line 11 of file token_bucket.inl.
|
inline |
Definition at line 19 of file token_bucket.inl.
|
delete |
|
default |
bool CppCommon::TokenBucket::Consume | ( | uint64_t | tokens = 1 | ) |
Try to consume the given count of tokens.
tokens | - Tokens to consume (default is 1) |
Definition at line 15 of file token_bucket.cpp.
|
inline |
Definition at line 26 of file token_bucket.inl.
|
delete |