Documentation
¶
Overview ¶
Package tokenbucket implements a token-bucket rate limiter for QPS control. Tokens are refilled at a fixed rate (rate per second) up to a maximum burst size.
Two variants are provided:
- New(rate, burst) — non-blocking, returns ErrLimitExceeded
- NewBlocking(rate, burst) — blocks until a token is available or ctx is done
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a non-blocking token-bucket rate limiter.
- rate: sustained tokens per second (QPS)
- burst: maximum burst size (initial token count)
Acquire returns limiter.ErrLimitExceeded immediately when no token is available.
func NewAtomic ¶
NewAtomic creates a high-throughput non-blocking token-bucket using atomic operations. It is designed for scenarios with very high QPS where lock contention on the mutex variant becomes a bottleneck.
func NewBlocking ¶
NewBlocking creates a blocking token-bucket rate limiter. Acquire blocks until a token is available or ctx is cancelled.
Types ¶
This section is empty.