cds  2.3.2
cds::backoff::exponential< Traits > Class Template Reference

Exponential back-off. More...

#include <cds/algo/backoff_strategy.h>

Public Types

typedef Traits traits
 Traits.
 
typedef traits::fast_path_backoff spin_backoff
 spin (fast-path) back-off strategy
 
typedef traits::slow_path_backoff yield_backoff
 yield (slow-path) back-off strategy
 

Public Member Functions

 exponential () noexcept
 Default ctor.
 

Protected Attributes

size_t m_nExpCur
 Current spin counter in range [traits::s_nExpMin, traits::s_nExpMax].
 
spin_backoff m_bkSpin
 Spinning (fast-path) phase back-off strategy.
 
yield_backoff m_bkYield
 Yield phase back-off strategy.
 

Detailed Description

template<typename Traits = exponential_const_traits>
class cds::backoff::exponential< Traits >

Exponential back-off.

This back-off strategy is composite. It consists of SpinBkoff and YieldBkoff back-off strategy. In first, the strategy tries to apply repeatedly SpinBkoff (spinning phase) until internal counter of failed attempts reaches its maximum spinning value. Then, the strategy transits to high-contention phase where it applies YieldBkoff until reset() is called. On each spinning iteration the internal spinning counter is doubled.

Selecting the best value for maximum spinning limit is platform and application specific task. The limits are described by Traits template parameter. There are two types of Traits:

  • constant traits exponential_const_traits - specifies the lower and upper limits as a compile-time constants; to change the limits you should recompile your application
  • runtime traits exponential_runtime_traits - specifies the limits as s_nExpMin and s_nExpMax variables which can be changed at runtime to tune back-off strategy.

The traits class must declare two data member:

  • lower_bound - the lower bound of spinning loop
  • upper_bound - the upper boudn of spinning loop

You may use Traits template parameter to separate back-off implementations. For example, you may define two exponential back-offs that is the best for your task A and B:

#include <cds/algo/backoff_strategy.h>
namespace bkoff = cds::backoff;
// the best bounds for task A
struct traits_A: public bkoff::exponential_const_traits
{
static size_t lower_bound;
static size_t upper_bound;
};
size_t traits_A::lower_bound = 1024;
size_t traits_A::upper_bound = 8 * 1024;
// the best bounds for task B
struct traits_B: public bkoff::exponential_const_traits
{
static size_t lower_bound;
static size_t upper_bound;
};
size_t traits_A::lower_bound = 16;
size_t traits_A::upper_bound = 1024;
// // define your back-off specialization
typedef bkoff::exponential<traits_A> expBackOffA;
typedef bkoff::exponential<traits_B> expBackOffB;

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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:16 by Doxygen 1.8.13