Skip to content

Add ETS-backed storage backend#29

Merged
nootr merged 4 commits intonootr:mainfrom
pairshaped:ets-store
Mar 20, 2026
Merged

Add ETS-backed storage backend#29
nootr merged 4 commits intonootr:mainfrom
pairshaped:ets-store

Conversation

@rapind
Copy link
Copy Markdown
Contributor

@rapind rapind commented Mar 13, 2026

Summary

  • Adds glimit/ets_store module, an ETS-backed implementation of bucket.Store
  • ETS operations are lock-free and concurrent, avoiding the overhead of OTP actor
    messages. Suitable for single-node deployments where low latency matters.
  • Adds glimit.ets_store() builder for easy integration
  • Includes periodic sweep timer for cleaning up full and idle buckets
  • 10 new tests covering all ETS store functionality
  • README updated with ETS mode documentation

Usage

let limiter =
  glimit.new()
  |> glimit.per_second(10)
  |> glimit.ets_store()
  |> glimit.identifier(fn(request) { request.ip })
  |> glimit.on_limit_exceeded(fn(_) { "Rate limit reached" })

Test plan

  • All 10 new ETS store tests pass
  • All 67 existing tests still pass (77 total)

rapind added 2 commits March 13, 2026 08:52
ETS provides lower-latency rate limiting by using atomic table operations
directly, avoiding the overhead of OTP actor messages. Suitable for
single-node deployments where low latency is important.

- ets_store.gleam: EtsStore type implementing bucket.Store interface
- ets_store_ffi.erl: Erlang FFI for ETS operations (new/get/set/delete/sweep/size)
- glimit.ets_store() builder for easy integration
- Periodic sweep timer for cleaning up full and idle buckets
- 10 new tests covering all ETS store functionality
Document the new ETS-backed storage backend with usage example,
performance characteristics, and comparison to in-memory mode.
@nootr
Copy link
Copy Markdown
Owner

nootr commented Mar 14, 2026

Hi @rapind, thank you very much for these PR's. I'll code review them this weekend.

Would this be an option to use as the default in-memory backend? What do you think?

@rapind
Copy link
Copy Markdown
Contributor Author

rapind commented Mar 14, 2026

Would this be an option to use as the default in-memory backend? What do you think?

Yes, 100% it's an upgrade. Same behaviour without the serialization bottleneck. I can rework this PR to replace the default if you like.

@nootr
Copy link
Copy Markdown
Owner

nootr commented Mar 14, 2026

@rapind That would be great! I think there would be no use for the current in-memory backend (OTP actor), so it would be awesome if this could completely replace that.

Let me know if I could help, thank you very much for contributing!

Replace the OTP actor-based in-memory store with ETS as the default.
ETS provides lower-latency, lock-free rate limiting without actor
message overhead. Remove memory_store module entirely — custom stores
can still be plugged in via glimit.store().
@rapind
Copy link
Copy Markdown
Contributor Author

rapind commented Mar 15, 2026

All set.

Copy link
Copy Markdown
Owner

@nootr nootr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rapind,

thanks again for your time and effort. This looks great!

I have a couple of questions, but overall this is a great improvement. Also, the pipeline seems to fail due to a formatting error.

@nootr
Copy link
Copy Markdown
Owner

nootr commented Mar 20, 2026

@rapind Thank you for helping!

@nootr nootr merged commit da9e382 into nootr:main Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants