atomic_token_bucket

Crates.ioatomic_token_bucket
lib.rsatomic_token_bucket
version0.1.0
created_at2025-10-26 21:00:45.502775+00
updated_at2025-10-26 21:00:45.502775+00
descriptionLock-free Token Bucket algorithm implemented using atomics
homepagehttps://github.com/alexpyattaev/atomic_token_bucket
repositoryhttps://github.com/alexpyattaev/atomic_token_bucket
max_upload_size
id1901867
size50,796
Alex Pyattaev (alexpyattaev)

documentation

README

Atomic token bucket

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.

Cargo features

  • keyed_rate_limiter: enables the keyed rate limiter, adds dep on dashmap
  • shuttle-test: needed for shuttle tests

FAQ

  • 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.

Benches

cargo bench

Testing with shuttle

cargo test -F shuttle-test shuttle_test_token_bucket_race

Credits:

Commit count: 0

cargo fmt