Open
Conversation
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.
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().
Introduces glimit/window module with layered fixed-window counters using ETS atomic update_counter for lock-free, concurrent operation. Unlike the token bucket algorithm (which smoothly refills tokens), fixed-window counters divide time into discrete windows and count requests within each. Useful for login attempts, verification codes, and API rate limiting with clear reset boundaries. - window.gleam: WindowLimiter type with check/reset/cleanup/get_count - window_ffi.erl: Erlang FFI using ETS select_delete for cleanup - Supports layered windows (e.g. 1/min + 3/15min + 10/hour + 20/day) - 11 tests covering all window functionality
Author
|
Updated to reflect that ETS is the new default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
glimit/windowmodule with fixed-window counters and layered windowsupdate_counterfor lock-free, concurrent operationdivide time into discrete windows and count requests. Ideal for:
Note on storage
The window module uses its own dedicated ETS table with atomic
update_counteroperations. It does not go through the pluggable
bucket.Storeinterface. Thisis intentional since fixed-window counters are typically a single-node pattern
and benefit from the atomicity guarantees of ETS. A pluggable store interface
for window counters could be added in the future if there's demand for
distributed fixed-window rate limiting.
Usage
Depends on
Test plan