This mechanism implements a leaky bucket that allows clients to monitor whether a resource is being consumed at a particular rate. The behavior of a leak bucket is determined by two properties: the drain rate (in units/s) and capacity (in units), both of which can be specified at construction or using the setRateAndCapacity method.
Synopsis
Declared in <balb_leakybucket.h>
class LeakyBucket;
Description
Units can be added to a leaky bucket by either submitting them using the submit method or reserving them using the reserve method. Submitted units are removed from a leaky bucket at the drain rate, while reserved units stays unaffected in a leaky bucket until they are either cancelled (removed from the leaky bucket) using the cancelReserved method or submitted using the submitReserved method.
Adding units to a leaky bucket will cause it to overflow if after the units are added, the total number of units in the leaky bucket (including both submitted and reserved units) exceeds its capacity. A leaky bucket can be queried whether adding a specified number of units would cause it to overflow via the wouldOverflow method. If submitting units to a leaky bucket will cause it to overflow, the estimated amount of time to wait before 1 more units can be submitted without causing the leaky bucket to overflow can be determined using the calculateTimeToSubmit method.
The state of a leaky bucket 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 leaky bucket keeps some statistics, including the number of submitted units, that can be accessed using the getStatistics method and reset using the resetStatistics method.
The class invariants are: * capacity() > 0 * drainRate() > 0
This class: * is exception neutral (agnostic) * is const thread‐safe For terminology see bsldoc_glossary.
Member Functions
Name |
Description |
|
Create an empty leaky bucket having the specified |
|
Destroy this object. |
If 1 more unit can be submitted to this leaky bucket without causing it to overflow, then return a time interval of 0 immediately. Otherwise, first update the state of this leaky bucket to the specified |
|
Cancel the specified |
|
Return the capacity of this leaky bucket. |
|
Return the drain rate of this leaky bucket. |
|
Load, into the specified |
|
Return the time interval when this leaky bucket was last updated. |
|
Reserve the specified |
|
Reset the following statistic counters for this leaky bucket to 0: |
|
Reset the statics collected for this leaky bucket by setting the number of units used and the number of units submitted to 0, and set the |
|
Set the drain rate of this leaky bucket to the specified |
|
Return the time interval when the collection of the statistics (as returned by |
|
Submit the specified |
|
Submit the specified |
|
Return the number of submitted units in this leaky bucket. |
|
Return the number of reserved units in this leaky bucket. |
|
Set the |
|
Update the state of this this leaky bucket to the specified |
Static Member Functions
Name |
Description |
Return the capacity of a leaky bucket as the rounded‐down product of the specified |
|
Return the time interval required to drain the specified |
|
Return the time interval over which a leaky bucket approximates a moving‐total of submitted units, as the rounded‐down ratio between the specified |
Created with MrDocs