This mechanism implements a rate limiter that allows clients to monitor and control the usage of a resource such that the rate of consumption stays within configured limits. The behavior of a rate limiter is determined by four properties: the sustained rate (in units/s), the sustained‐rate time‐window (in seconds), the peak rate (in units/s), and the peak‐rate time‐window (in seconds). All of these properties can be specified at construction or using the setRateLimits method.
Synopsis
Declared in <balb_ratelimiter.h>
class RateLimiter;
Description
Units can be indicated to a rate limiter as consumed by either submitting them using the submit method. Units can be marked as reserved, which effectively shorten the sustained‐rate time‐window and the peak‐rate time‐window, by using the reserve method.
Whether submitting 1 more unit would exceed the configured limits can be determined using the wouldExceedBandwidth method. The estimated amount of time to wait before 1 more unit will be allowed to be submitted can be determined using the calculateTimeToSubmit method.
The state of a rate limiter must be updated manually using the updateState method supplying the current time interval. The time intervals supplied should all refer to the same time origin.
A rate limiter keeps some statistics, including the number of submitted units, that can be accessed using the getStatistics and reset using the resetStatistics method.
This class: * is exception neutral (agnostic) * is const thread‐safe For terminology see bsldoc_glossary.
Member Functions
Name |
Description |
|
Create a RateLimiter object, having the specified |
|
Destroy this object. |
Update the state of this rate limiter to the specified |
|
Cancel the specified |
|
Load, into the specified |
|
Return the time when this rate limiter was last updated. |
|
Return the peak rate of this rate limiter. |
|
Return the peak‐rate time‐period of this rate limiter. Note that this period is generally significantly shorter than |
|
Reserve the specified |
|
Reset the statistics counter for this rate limiter to 0, and set the |
|
Reset the statics collected for this rate limiter by setting the number of units used and the number of units submitted to 0, and set the |
|
Set the sustained rate of this rate limiter to the specified |
|
Return the time interval when the collection of the statistics (as returned by |
|
Submit the specified |
|
Submit the specified |
|
Return the sustained rate of this rate limiter. |
|
Return the sustained‐rate time‐period of this rate limiter. Note that this period is generally significantly longer than the |
|
Return the number of reserved units for this rate limiter. |
|
Set the |
|
Update the state of this rate limiter to the specified |
Static Member Functions
Name |
Description |
Returns |
Created with MrDocs