Struct diem_rate_limiter::rate_limit::TokenBucketRateLimiter[][src]

pub struct TokenBucketRateLimiter<Key: Eq + Hash + Clone + Debug> { /* fields omitted */ }
Expand description

A generic token bucket filter

Terms

Key

A key is an identifier of the item being rate limited

Token

A token is the smallest discrete value that we want to rate limit by. In a situation involving network requests, this may represent a request or a byte. Tokens are the counters for the rate limiting, and when there are no tokens left in a bucket, the key is throttled.

Bucket

A bucket is the tracker of the number of tokens. It has a bucket size, and any additional tokens added to it will “spill” out of the bucket. The buckets are filled at an interval with a given fill rate.

Interval

The interval at which we refill all of the buckets in the token bucket filter. Configured across the whole token bucket filter.

Fill Rate

The rate at which we fill a bucket with tokens. Configured per bucket.

Bucket Size

Maximum size of a bucket. A bucket saturates at this size. Configured per bucket.

Features

Keys

The token bucket takes any key as long as it’s hashable. This should allow it to apply to many applications that need rate limiters.

Bucket sizes and Rates

Defaults

There are defaults for bucket size and fill rate, which will apply to unknown keys.

Refill Interval

Buckets are refilled automatically at an interval. To do this synchronously, it calculates the number of intervals that have passed. This is done synchronously and in the future may be done asynchronously.

Implementations

Used for testing and to not have a rate limiter

Retrieve bucket, or create a new one

Garbage collects a single key, if we know what it is

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.