Skip to content

BurstyRateLimiter

Defined in: src/bursty-rate-limiter.ts:19

A steady limit plus a burst allowance: burst is only consulted when primary rejects, e.g. 10/s that may spill into 20 extra per minute. Any algorithms work, sync or async (in-memory, Redis):

const now = s.timeProvider.now();
new RateLimiterStrategy(new BurstyRateLimiter(new WindowCounter(10, 1000, 1, now), new WindowCounter(20, 60_000, 1, now)), { queueTimeout: '1s' }, s);

new BurstyRateLimiter(primary, burst): BurstyRateLimiter

Defined in: src/bursty-rate-limiter.ts:25

RateLimiterAlgorithm

RateLimiterAlgorithm

BurstyRateLimiter

readonly burst: RateLimiterAlgorithm

Defined in: src/bursty-rate-limiter.ts:23


readonly permitLimit: number

Defined in: src/bursty-rate-limiter.ts:21

The larger of the two: a weight only the burst pool can hold still gets in through it.

RateLimiterAlgorithm.permitLimit


readonly primary: RateLimiterAlgorithm

Defined in: src/bursty-rate-limiter.ts:22

acquire(permits, now): Promise<AcquireResult>

Defined in: src/bursty-rate-limiter.ts:32

Granted by primary: its remaining (the burst pool is not read). Granted by burst: the pool’s remaining.

number

number

Promise<AcquireResult>

RateLimiterAlgorithm.acquire


adjust(points, now): Promise<void>

Defined in: src/bursty-rate-limiter.ts:42

Penalty / reward hit primary; a full reset (-Infinity, e.g. control.delete()) also refills the burst pool.

number

number

Promise<void>

RateLimiterAlgorithm.adjust


restore(state, now): void

Defined in: src/bursty-rate-limiter.ts:54

Loads a snapshot, aging it by the time passed since it was taken. Optional.

BurstyRateLimiterState

number

void

RateLimiterAlgorithm.restore


snapshot(now): BurstyRateLimiterState

Defined in: src/bursty-rate-limiter.ts:48

JSON-serializable state as of now, for restore (e.g. after a restart). Optional.

number

BurstyRateLimiterState

RateLimiterAlgorithm.snapshot