-
Notifications
You must be signed in to change notification settings - Fork 0
Performance
frosxt edited this page Jan 19, 2026
·
1 revision
BucketGuard is designed for minimal overhead.
BucketGuard does not use a "thread that adds tokens". Instead, it uses the GCRA.
GCRA is a leaky bucket variant that tracks a "Theoretical Arrival Time" (TAT).
-
Zero Allocations: State is managed in a single
long(timestamp). Checking a limit involves reading the current time and performing basic arithmetic. No objects are created on the hot path. - O(1) Complexity: The cost of a check is constant, regardless of the capacity or refill rate.
-
Atomic Buckets: A standard bucket consumes only the memory of an
AtomicLongand a reference to its spec. -
Keyed Storage: When using
EXPIRE_AFTER_ACCESS, BucketGuard uses specialized map values to track access times without checking separate "last accessed" objects, keeping heaps small even with millions of keys.
-
Lock-Free: The core
AtomicBucketis completely lock-free, usingVarHandleCAS operations. - Striping: For standard limiters, striping effectively shards the lock contention.
-
Keyed Access: Keyed limiters use
ConcurrentHashMapforNONEeviction policies, providing non-blocking reads and writes. ForLRUandEXPIREpolicies, a lightweight synchronized wrapper ensures correctness of the eviction order with minimal overhead.