Struct diem_rate_limiter::rate_limit::Bucket [−][src]
pub struct Bucket { /* fields omitted */ }Expand description
A token bucket object that keeps track of everything related to a key
This can be used as a standalone rate limiter; however, to make it more useful
it should be wrapped in an Arc and a Mutex to be shared across threads.
Implementations
pub fn new(
label: String,
log_info: String,
key: String,
initial: usize,
size: usize,
rate: usize,
metrics: Option<HistogramVec>
) -> Self
A fully open rate limiter, to allow for ignoring rate limiting for tests
Determine if an entire batch can be passed through
This is important for message based rate limiting, where the whole message has
to make it through, or else it must be rejected. A result of None means it cannot
ever be allowed through, as it’s bigger than the size of the bucket.
Returns usize of tokens allowed. May be less than requested.
For best effort, caller should return unused tokens with add_tokens
Tells us when the next refill is
Tells us when an entire batch will make it through. Useful for Async work to wait until
all tokens are ready. Returns None if it is never possible.
Returns tokens that were unused