a3kov
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
Most Liked
jsm
If you’re interested, this uses atomics as well: Once - Ecto type for globally unique 64-bits IDs generated by multiple Elixir nodes (to be precise, the underlying NoNoncense lib does).
a3kov
Version 0.2.0 comes with new advanced features via raw_request/5:
- Support for variable request cost for cases where multiple operations have different cost, but share the same budget.
- Support for negative cost (“token refunds”). Can be useful where an allowed operation failed and we don’t want it to “steal” the budget.
Unless some new ideas appear the library seems feature-complete at this point.
Asd
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!
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








