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);Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BurstyRateLimiter(
primary,burst):BurstyRateLimiter
Defined in: src/bursty-rate-limiter.ts:25
Parameters
Section titled “Parameters”primary
Section titled “primary”Returns
Section titled “Returns”BurstyRateLimiter
Properties
Section titled “Properties”
readonlyburst:RateLimiterAlgorithm
Defined in: src/bursty-rate-limiter.ts:23
permitLimit
Section titled “permitLimit”
readonlypermitLimit: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.
Implementation of
Section titled “Implementation of”RateLimiterAlgorithm.permitLimit
primary
Section titled “primary”
readonlyprimary:RateLimiterAlgorithm
Defined in: src/bursty-rate-limiter.ts:22
Methods
Section titled “Methods”acquire()
Section titled “acquire()”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.
Parameters
Section titled “Parameters”permits
Section titled “permits”number
number
Returns
Section titled “Returns”Promise<AcquireResult>
Implementation of
Section titled “Implementation of”adjust()
Section titled “adjust()”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.
Parameters
Section titled “Parameters”points
Section titled “points”number
number
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”restore()
Section titled “restore()”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.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”snapshot()
Section titled “snapshot()”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.
Parameters
Section titled “Parameters”number