a3kov
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 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
Links
Trending in Announcing
Other Trending 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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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!
PJUllrich
TIL that :atomics exists
great library and very interesting implementation! How did you learn about atomics and how did it lead to this library?
a3kov
You have much more experience in Elixir than me so that is indeed strange.
In fact I’ve learned a lot from your blog posts in my Elixir journey.
It’s used in many libraries. Perhaps it’s a new trend to build stuff on top of it
PJUllrich
Haha, thank you! I must now write a little blog post about atomics and will have to name you in it! That’s what you’re getting for sharing your good work online! Take that
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).
jsm
This is really cool
a3kov
v0.1.3 fixes a stupid but nonetheless serious bug. Please update if you are using the library for anything important.
a3kov
Version 0.2.0 comes with new advanced features via
raw_request/5:Unless some new ideas appear the library seems feature-complete at this point.
a3kov
Version 0.3 is out with benchmarking improvements and perf. optimizations:
Overall I think it’s a good trade-off - for now I don’t want to maintain 2 code paths and runtime checks would defeat the purpose. 64 bit and buckets typical for rate limiters is what most people use. This was a good case for me to learn about big integers on BEAM