BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
ExponentialBackOff implements the computation of delay when retrying an operation. It is usually used to lower load of a server. More...
#include <ExponentialBackOff.h>
Data Structures | |
class | Config |
Public Types | |
typedef Poco::SharedPtr < ExponentialBackOff > | Ptr |
Public Types inherited from BeeeOn::BackOff | |
typedef Poco::SharedPtr< BackOff > | Ptr |
Public Member Functions | |
void | applyConfig (const Config &config) |
const Config & | config () const |
Poco::Timespan | initialInterval () const |
Poco::Timespan | maxInterval () const |
Poco::Timespan | maxElapsedTime () const |
double | randomizationFactor () const |
double | multiplier () const |
Poco::Timespan | nextInterval () const |
Poco::Timespan | elapsed () const |
Poco::Timespan | next () override |
void | reset () override |
Protected Member Functions | |
Poco::Timespan | nextRandom () |
Additional Inherited Members | |
Static Public Attributes inherited from BeeeOn::BackOff | |
static const Poco::Timespan | STOP = -1 |
ExponentialBackOff implements the computation of delay when retrying an operation. It is usually used to lower load of a server.
The instance manages a time interval (e.g. 5 seconds) suitable for random generation of the delay (example random delayes: 1 second, 3,5 seconds). The time interval changes in each iteration by applying the multiplier (configures the expenential grow speed).
The time interval is in fact represented as <min, max>. The min and max are computed from the current time interval and the randomization factor. Than, the min is computed as min = current_interval * (1 - factor) and the max is computed as max = = current_interval * (1 + factor). This way, the initial time interval boundaries grow over time and gives lower probability to generate a time delay colliding with some other client.
The interval grows until the max interval limit is reached or until a given (real) time has elapsed. Thus, we are not generate delays indefinitely.
Timespan ExponentialBackOff::elapsed | ( | ) | const |
Time elapsed from the last reset or from the initial creation of the ExponentialBackOff instance.
|
overridevirtual |
Implements BeeeOn::BackOff.
Timespan ExponentialBackOff::nextInterval | ( | ) | const |
Return next interval for the next computation.
|
overridevirtual |
Reset state of the back-off algorithm.
Implements BeeeOn::BackOff.