|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Calculates backoff delays for work-stealing operations. More...
#include <steal_backoff_strategy.h>

Public Member Functions | |
| backoff_calculator (steal_backoff_config config={}) | |
| Construct a backoff calculator with given configuration. | |
| auto | calculate (std::size_t attempt) -> std::chrono::microseconds |
| Calculate backoff delay for a given attempt number. | |
| auto | get_config () const -> const steal_backoff_config & |
| Get the current configuration. | |
| void | set_config (steal_backoff_config config) |
| Update the configuration. | |
Private Member Functions | |
| auto | calculate_base_delay (std::size_t attempt) const -> std::chrono::microseconds |
| Calculate base delay without jitter or capping. | |
| auto | apply_jitter (std::chrono::microseconds delay) -> std::chrono::microseconds |
| Apply random jitter to a delay. | |
| auto | cap_delay (std::chrono::microseconds delay) const -> std::chrono::microseconds |
| Cap delay at maximum. | |
Private Attributes | |
| steal_backoff_config | config_ |
| std::mt19937_64 | rng_ |
Calculates backoff delays for work-stealing operations.
This class provides thread-safe backoff delay calculation using various strategies. It is designed to be used by workers when steal attempts fail.
Each worker should have its own backoff_calculator instance to avoid contention on the random number generator. All methods are thread-safe when used with separate instances.
Definition at line 90 of file steal_backoff_strategy.h.
|
inlineexplicit |
Construct a backoff calculator with given configuration.
| config | Backoff configuration |
Definition at line 97 of file steal_backoff_strategy.h.
|
inlinenodiscardprivate |
Apply random jitter to a delay.
Definition at line 186 of file steal_backoff_strategy.h.
References config_, kcenon::thread::delay, kcenon::thread::steal_backoff_config::jitter_factor, and rng_.
Referenced by calculate().

|
inlinenodiscard |
Calculate backoff delay for a given attempt number.
| attempt | The attempt number (0-indexed) |
The delay is calculated based on the configured strategy and capped at max_backoff.
Definition at line 111 of file steal_backoff_strategy.h.
References kcenon::thread::adaptive_jitter, apply_jitter(), calculate_base_delay(), cap_delay(), config_, kcenon::thread::delay, and kcenon::thread::steal_backoff_config::strategy.

|
inlinenodiscardprivate |
Calculate base delay without jitter or capping.
Definition at line 145 of file steal_backoff_strategy.h.
References kcenon::thread::adaptive_jitter, config_, kcenon::thread::exponential, kcenon::thread::fixed, kcenon::thread::steal_backoff_config::initial_backoff, kcenon::thread::linear, kcenon::thread::steal_backoff_config::max_backoff, kcenon::thread::steal_backoff_config::multiplier, and kcenon::thread::steal_backoff_config::strategy.
Referenced by calculate().

|
inlinenodiscardprivate |
Cap delay at maximum.
Definition at line 209 of file steal_backoff_strategy.h.
References config_, kcenon::thread::delay, and kcenon::thread::steal_backoff_config::max_backoff.
Referenced by calculate().

|
inlinenodiscard |
Get the current configuration.
Definition at line 127 of file steal_backoff_strategy.h.
References config_.
|
inline |
Update the configuration.
| config | New configuration to use |
Definition at line 136 of file steal_backoff_strategy.h.
References config_.
|
private |
Definition at line 215 of file steal_backoff_strategy.h.
Referenced by apply_jitter(), calculate(), calculate_base_delay(), cap_delay(), get_config(), and set_config().
|
private |
Definition at line 216 of file steal_backoff_strategy.h.
Referenced by apply_jitter().