A basic rate limiting / traffic shaping element. Validated using shuttle.
The basic primitive is TokenBucket which provides ability to limit
rate of certain events, while allowing bursts through.
More advanced KeyedRateLimiter allows to rate-limit multiple keyed
items, such as connections.
- keyed_rate_limiter: enables the keyed rate limiter, adds dep on dashmap
- shuttle-test: needed for shuttle tests
- Is this fast enough? Yes.
- Is this safe? Verified with shuttle.
- Is this lock-free?
- TokenBucket is lock-free.
- KeyedRateLimiter uses sharded hashmap when new keys are added, and is otherwise lock-free.
cargo bench
cargo test -F shuttle-test shuttle_test_token_bucket_race