Atomic Bucket - fast single node rate limiter implementing Token Bucket algorithm

Atomic Bucket

Fast single node rate limiter implementing Token Bucket algorithm. The goal 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 benchmarks section in the readme. 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 average rate and burst size

  • handy timeouts for retries

  • compile-time validation of arguments when possible

  • only fixed request cost is supported for now

Links

Package
Docs
Source

6 Likes

This is a great library. The implementation is much more efficient and does not contain concurrency bugs like Hammer’s leaky bucket implementation.

Definitely gonna use it in one of my projects. One request is to leave the atomics ref management to the user!

1 Like