Token bucket rate limiting algorithm.
More...
#include <rate_limiter.h>
|
bool | jumpedBack (const ::ros::Time &stamp, const ::ros::Time &previousStamp) const |
| Decide whether the newly coming message should be treated as a backwards jump in time. More...
|
|
Token bucket rate limiting algorithm.
- Note
- Generally, it should be quite good at achieving the desired rate.
-
The limiter has a bucket of a given capacity. It is refilled over time by a constant number of tokens per second. To publish a message, there has to be at least one token in the bucket. If more tokens should be put in the bucket than is its capacity, they are ignored.
-
The bucket capacity basically specifies the size of the burst that can happen after some period of inactivity when tokens are just collected and not consumed.
Definition at line 103 of file rate_limiter.h.
◆ TokenBucketLimiter() [1/2]
cras::TokenBucketLimiter::TokenBucketLimiter |
( |
const ::ros::Rate & |
rate, |
|
|
size_t |
bucketCapacity = 2 , |
|
|
double |
initialTokensAvailable = 1.0 |
|
) |
| |
|
explicit |
Create the rate-limiter limiting to the desired rate.
- Parameters
-
[in] | rate | Desired rate. |
[in] | bucketCapacity | Capacity of the bucket (in tokens). |
[in] | initialTokensAvailable | Number of tokens available in the bucket at the beginning. Set to 1 to always let the first packet through. This number should not be higher than bucketCapacity . |
◆ TokenBucketLimiter() [2/2]
cras::TokenBucketLimiter::TokenBucketLimiter |
( |
const ::ros::Duration & |
period, |
|
|
size_t |
bucketCapacity = 2 , |
|
|
double |
initialTokensAvailable = 1.0 |
|
) |
| |
|
explicit |
Create rate-limiter with rate corresponding to the given period.
- Parameters
-
[in] | period | Average delay between two desired output messages. |
[in] | bucketCapacity | Capacity of the bucket (in tokens). |
[in] | initialTokensAvailable | Number of tokens available in the bucket at the beginning. Set to 1 to always let the first packet through. This number should not be higher than bucketCapacity . |
◆ reset()
void cras::TokenBucketLimiter::reset |
( |
| ) |
|
|
overridevirtual |
Reset the rate-limiter as if it were newly created with the same parameters.
Implements cras::RateLimiter.
◆ shouldPublish()
bool cras::TokenBucketLimiter::shouldPublish |
( |
const ::ros::Time & |
stamp | ) |
|
|
overridevirtual |
Call this function whenever a message is received. It tells whether the message has passed the rate-limiting and should be published, or whether it should be skipped.
- Parameters
-
[in] | stamp | Time when the message should be sent (usually not header.stamp!). |
- Returns
- Whether to continue publishing the message.
Implements cras::RateLimiter.
◆ bucketCapacity
size_t cras::TokenBucketLimiter::bucketCapacity |
|
protected |
Number of tokens that can fit into the bucket. This influences the maximum burst size.
Definition at line 135 of file rate_limiter.h.
◆ initialTokensAvailable
double cras::TokenBucketLimiter::initialTokensAvailable |
|
protected |
The number of tokens that are initially in the buffer (and after reset).
Definition at line 142 of file rate_limiter.h.
◆ lastCheckTime
::ros::Time cras::TokenBucketLimiter::lastCheckTime {0, 0} |
|
protected |
Stamp of the last incoming message. Zero at the beginning.
Definition at line 132 of file rate_limiter.h.
◆ tokensAvailable
The number of currently available tokens. This units of this number are actually not seconds, but Duration is used here to achieve higher decimal point accuracy.
Definition at line 139 of file rate_limiter.h.
The documentation for this class was generated from the following file: