BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
Data Structures | Public Types | Public Member Functions | Protected Member Functions
BeeeOn::ExponentialBackOff Class Reference

ExponentialBackOff implements the computation of delay when retrying an operation. It is usually used to lower load of a server. More...

#include <ExponentialBackOff.h>

Inheritance diagram for BeeeOn::ExponentialBackOff:
BeeeOn::BackOff

Data Structures

class  Config
 

Public Types

typedef Poco::SharedPtr
< ExponentialBackOff
Ptr
 
- Public Types inherited from BeeeOn::BackOff
typedef Poco::SharedPtr< BackOffPtr
 

Public Member Functions

void applyConfig (const Config &config)
 
const Configconfig () 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
 

Detailed Description

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.

See Also
https://en.wikipedia.org/wiki/Exponential_backoff
google-http-java-client: com.google.api.client.util.ExponentialBackOff

Member Function Documentation

Timespan ExponentialBackOff::elapsed ( ) const

Time elapsed from the last reset or from the initial creation of the ExponentialBackOff instance.

Timespan ExponentialBackOff::next ( )
overridevirtual
Returns
next timeout generated by the back-off algorithm.

Implements BeeeOn::BackOff.

Timespan ExponentialBackOff::nextInterval ( ) const

Return next interval for the next computation.

void ExponentialBackOff::reset ( )
overridevirtual

Reset state of the back-off algorithm.

Implements BeeeOn::BackOff.


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