C# Class Bert.RateLimiters.RollingWindowThrottler

Used to control the rate of occurrences of an action per unit of time.
The algorithm uses a rolling time window so that precise control over the rate is achieved (without any bursts)
Show file Open project: robertmircea/RateLimiters

Public Methods

Method Description
RollingWindowThrottler ( int occurrences, System.TimeSpan timeUnit ) : System

Constructs an instance of the throttler.

ShouldThrottle ( int tokens, long &waitTimeMillis ) : bool

Tries to reserve tokens in the configured time unit.

ShouldThrottle ( long &waitTimeMillis ) : bool

Tries to reserve one token in the configured time unit.

Private Methods

Method Description
CheckExitTimeQueue ( ) : void

Method Details

RollingWindowThrottler() public method

Constructs an instance of the throttler.
public RollingWindowThrottler ( int occurrences, System.TimeSpan timeUnit ) : System
occurrences int Maximum number of occurences per time unit allowed.
timeUnit System.TimeSpan The time unit in which the occurences are constrained.
return System

ShouldThrottle() public method

Tries to reserve tokens in the configured time unit.
public ShouldThrottle ( int tokens, long &waitTimeMillis ) : bool
tokens int total number of reservations
waitTimeMillis long total suggested wait time in milliseconds till tokens will become available for reservation
return bool

ShouldThrottle() public method

Tries to reserve one token in the configured time unit.
public ShouldThrottle ( long &waitTimeMillis ) : bool
waitTimeMillis long total suggested wait time in milliseconds till tokens will become available for reservation
return bool