fair::mq::tools::RateLimiter Class Reference

`#include <RateLimit.h>`

## Public Member Functions

| RateLimiter (float rate)
void | maybe_sleep ()

## Detailed Description

Objects of type RateLimiter can be used to limit a loop to a given rate of iterations per second.

Example:

RateLimiter limit(100); // 100 Hz
while (do_more_work()) {
work();
limit.maybe_sleep(); // this needs to be at the end of the loop for a
// correct time measurement of the first iterations
}

## Constructor & Destructor Documentation

## RateLimiter()

fair::mq::tools::RateLimiter::RateLimiter | ( | float | rate | ) |

inline

Constructs a rate limiter.

Parameters

  rate | Work rate in Hz (calls to maybe_sleep per second). Values less than/equal to 0 set the rate to 1 GHz (which is impossible to achieve, even with a loop that only calls RateLimiter::maybe_sleep).

## Member Function Documentation

## maybe_sleep()

void fair::mq::tools::RateLimiter::maybe_sleep | ( |  | ) |

inline

Call this function at the end of the iteration rate limited loop.

This function might use `std::this_thread::sleep_for` to limit the iteration rate. If no sleeps are necessary, the function will back off checking for the time to further allow increased iteration rates (until the requested rate or 1s between rechecks is reached).

The documentation for this class was generated from the following file:

- fairmq/tools/RateLimit.h

privacy