a3kov

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

Package
Docs
Source

Showing Posts 1 to 9

Asd

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

PJUllrich

Author of Building Table Views with Phoenix LiveView

TIL that :atomics exists :smiley: great library and very interesting implementation! How did you learn about atomics and how did it lead to this library?

a3kov

a3kov OP

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 :rofl:

PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

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 :winking_face_with_tongue:

jsm

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

jsm

This is really cool :slight_smile:

a3kov

a3kov OP

v0.1.3 fixes a stupid but nonetheless serious bug. Please update if you are using the library for anything important.

a3kov

a3kov OP

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.

a3kov

a3kov OP

Version 0.3 is out with benchmarking improvements and perf. optimizations:

  • 20-30% faster for buckets of normal size on 64bit
  • extremely big buckets and 32bit architectures will take a hit

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 :blush:

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
lawik
I was thinking since Goatmire Elixir turned out pretty good I should maybe do another one. 30th of Sep - 2nd of Oct this year./ The firs...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews