SlidingWindowCounter
Represents a rate limiting algorithm that divides the total time period into smaller segments or windows. Each segment has its own counter, and the rate limiter keeps track of the number of requests in each segment to provide a more accurate and smoother rate limiting mechanism. After segments * replenishmentPeriod, which emcompasses a window cycle, the oldest segment is removed, and a new segment is added. At any point, when a request arrives, the total number of requests in all segments is compared to the totalPermits limit.
Considerations
This algorithm mitigates the burstiness at the boundary of fixed window implmentations by distributing requests more evenly across time segments (e.g., if the current window is 25% through, the previous window's count is weighted by 75%).
Parameters
The duration of each time segment.
The number of segments that the time window is divided into.
See also
Properties
The maximum number of requests that can be queued when the rate limiter is exceeded. If set to 0, the rate limiter will reject requests immediately when the limit is reached.
The total number of permits that can be allowed in a given replenishmentPeriod.