This mechanism implements a leaky bucket that allows clients to monitor whether a resource is being consumed at a particular rate.
Synopsis
Declared in <balb_leakybucket.h>
class LeakyBucket;
Description
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.
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 with the specified rate and capacity. |
|
Destroy this object. |
Return the estimated wait before one more unit can be submitted. |
|
Cancel the specified |
|
Return the capacity of this leaky bucket. |
|
Return the drain rate of this leaky bucket. |
|
Load submitted and unused unit statistics for this leaky bucket. |
|
Return the time interval when this leaky bucket was last updated. |
|
Reserve the specified |
|
Reset the counters and update times for this leaky bucket. |
|
Reset the statistics collected for this leaky bucket. |
|
Set the drain rate and capacity of this leaky bucket. |
|
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. |
|
Update this leaky bucket's state to the specified |
|
Return whether submitting one more unit would exceed capacity. |
Static Member Functions
Name |
Description |
Return the capacity for a leaky bucket with the given rate and window. |
|
Return the time interval required to drain the specified units. |
|
Return the time window approximated by a leaky bucket of given size. |
Created with MrDocs