
▲ 26 r/elixir
Atomic Bucket - fast single node rate limiter implementing Token Bucket algorithm
In case someone missed the forum post I'm providing a copy here.
I was tired of bugs in Hammer so I wrote efficient and fast rate limiting library. Token Bucket supports flexible bursts and IMO is fit to serve as the main rate limiting algorithm for most cases.
The goal of the library is to provide dependable solution that JustWorks™ with a focus on performance, correctness and ease of use. Bucket data is stored using :atomics module. Bucket references are stored in ETS and optionally cached as persistent terms.
Features
- lock-free and race-free with compare-and-swap operations
- BlazingFast™ performance, see provided benchmarks. Req/s go brrrrrr
- monotonic timer for correct calculations
- millisecond tick supporting wider range of parameters and preventing request starvation
- automatic calculation of bucket parameters based on target rate and burst size (for fixed cost requests)
- handy timeouts for retries
- support for token "refunds" and variable cost requests
- compile-time validation of arguments when possible
u/a3kov — 2 days ago