class

MartenThrottle::SlidingWindow

Inherits MartenThrottle::Strategy < Reference < Object

Sliding-window counter (two-bucket weighted variant).

The window is divided into fixed buckets of length window. For each request we increment the current bucket and combine it with a fractional weight of the previous bucket — the fraction of the previous bucket that still falls inside the rolling window ending "now".

effective = (prev_count * weight) + curr_count where weight = 1.0 - (now_in_bucket / window_seconds).

One zero-amount counter increment + one regular increment per request. Smooths out the boundary bursts that a strict fixed-window has, at the cost of one extra counter operation.

Instance methods

check(key : String, limit : Int32, window : Time::Span) : Result
Source