Skip to content

alexpyattaev/atomic_token_bucket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

Lock-free token bucket implementation in rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages