cds
2.3.2
|
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. | |
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:
exponential_const_traits
- specifies the lower and upper limits as a compile-time constants; to change the limits you should recompile your applicationexponential_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 loopupper_bound
- the upper boudn of spinning loopYou 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: