Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::config_builder Class Reference

Builder for thread_system_config. More...

#include <thread_system_config.h>

Collaboration diagram for kcenon::thread::config_builder:
Collaboration graph

Public Member Functions

 config_builder ()=default
 
auto with_worker_count (std::size_t count) -> config_builder &
 Sets the number of worker threads.
 
auto with_queue_capacity (std::size_t capacity) -> config_builder &
 Sets the queue capacity.
 
auto enable_backpressure () -> config_builder &
 Enables backpressure with default settings.
 
auto with_backpressure_policy (backpressure_policy policy) -> config_builder &
 Sets the backpressure policy.
 
auto with_watermarks (double low, double high) -> config_builder &
 Sets backpressure watermarks.
 
auto enable_circuit_breaker () -> config_builder &
 Enables circuit breaker with default settings.
 
auto with_failure_threshold (std::size_t threshold) -> config_builder &
 Sets circuit breaker failure threshold.
 
auto with_open_duration (std::chrono::seconds duration) -> config_builder &
 Sets circuit breaker open duration.
 
auto enable_work_stealing () -> config_builder &
 Enables work stealing.
 
auto with_work_stealing_params (std::size_t max_attempts, std::chrono::microseconds backoff) -> config_builder &
 Sets work stealing parameters.
 
auto enable_priority_aging () -> config_builder &
 Enables priority aging with default settings.
 
auto with_priority_aging_params (std::chrono::milliseconds interval, int boost, int max_boost) -> config_builder &
 Sets priority aging parameters.
 
auto enable_auto_scaling () -> config_builder &
 Enables auto-scaling.
 
auto with_dag_failure_policy (dag_failure_policy policy) -> config_builder &
 Sets DAG failure policy.
 
auto with_dag_retry_params (std::size_t max_retries, std::chrono::milliseconds delay) -> config_builder &
 Sets DAG retry parameters.
 
auto build () -> thread_system_config
 Builds the final configuration.
 

Private Attributes

thread_system_config config_
 

Detailed Description

Builder for thread_system_config.

Provides a fluent interface for constructing thread_system_config with sensible defaults.

Example Usage

.with_worker_count(8)
.with_queue_capacity(5000)
.enable_backpressure()
.with_backpressure_policy(backpressure_policy::adaptive)
.enable_circuit_breaker()
.with_failure_threshold(5)
.enable_priority_aging()
.build();
@ adaptive
Automatically adjust based on load conditions.
static auto builder() -> config_builder
Creates a builder for fluent configuration.

Definition at line 249 of file thread_system_config.h.

Constructor & Destructor Documentation

◆ config_builder()

kcenon::thread::config_builder::config_builder ( )
default

Member Function Documentation

◆ build()

auto kcenon::thread::config_builder::build ( ) -> thread_system_config
inline

Builds the final configuration.

Validates the configuration and returns it.

Returns
The constructed configuration
Exceptions
std::invalid_argumentif configuration is invalid

Definition at line 437 of file thread_system_config.h.

438 {
439 if (!config_.is_valid())
440 {
441 throw std::invalid_argument("Invalid thread_system_config");
442 }
443 return config_;
444 }
auto is_valid() const -> bool
Validates the entire configuration.

References config_, and kcenon::thread::thread_system_config::is_valid().

Here is the call graph for this function:

◆ enable_auto_scaling()

auto kcenon::thread::config_builder::enable_auto_scaling ( ) -> config_builder&
inline

Enables auto-scaling.

Returns
Reference to this builder

Definition at line 398 of file thread_system_config.h.

399 {
401 return *this;
402 }
bool auto_scaling_enabled
Enable automatic scaling based on load.
struct kcenon::thread::thread_system_config::scaling_config scaling

References kcenon::thread::thread_system_config::scaling_config::auto_scaling_enabled, config_, and kcenon::thread::thread_system_config::scaling.

◆ enable_backpressure()

auto kcenon::thread::config_builder::enable_backpressure ( ) -> config_builder&
inline

Enables backpressure with default settings.

Returns
Reference to this builder

Definition at line 280 of file thread_system_config.h.

281 {
283 return *this;
284 }
@ block
Block until space is available (with timeout)
backpressure_policy policy
The backpressure policy to use.
backpressure_config backpressure
Backpressure configuration.
struct kcenon::thread::thread_system_config::pool_config pool

References kcenon::thread::thread_system_config::pool_config::backpressure, kcenon::thread::block, config_, kcenon::thread::backpressure_config::policy, and kcenon::thread::thread_system_config::pool.

◆ enable_circuit_breaker()

auto kcenon::thread::config_builder::enable_circuit_breaker ( ) -> config_builder&
inline

Enables circuit breaker with default settings.

Returns
Reference to this builder

Definition at line 314 of file thread_system_config.h.

315 {
316 config_.resilience.circuit_breaker.failure_threshold = 5;
317 return *this;
318 }
circuit_breaker_config circuit_breaker
Circuit breaker configuration.
struct kcenon::thread::thread_system_config::resilience_config resilience

References kcenon::thread::thread_system_config::resilience_config::circuit_breaker, config_, and kcenon::thread::thread_system_config::resilience.

◆ enable_priority_aging()

auto kcenon::thread::config_builder::enable_priority_aging ( ) -> config_builder&
inline

Enables priority aging with default settings.

Returns
Reference to this builder

Definition at line 371 of file thread_system_config.h.

372 {
374 return *this;
375 }
bool enabled
Whether priority aging is enabled.
priority_aging_config priority_aging
Priority aging configuration.

References config_, kcenon::thread::priority_aging_config::enabled, kcenon::thread::thread_system_config::scaling_config::priority_aging, and kcenon::thread::thread_system_config::scaling.

◆ enable_work_stealing()

auto kcenon::thread::config_builder::enable_work_stealing ( ) -> config_builder&
inline

Enables work stealing.

Returns
Reference to this builder

Definition at line 347 of file thread_system_config.h.

348 {
350 return *this;
351 }

References config_, kcenon::thread::thread_system_config::pool_config::enable_work_stealing, and kcenon::thread::thread_system_config::pool.

◆ with_backpressure_policy()

auto kcenon::thread::config_builder::with_backpressure_policy ( backpressure_policy policy) -> config_builder&
inline

Sets the backpressure policy.

Parameters
policyThe backpressure policy to use
Returns
Reference to this builder

Definition at line 291 of file thread_system_config.h.

292 {
294 return *this;
295 }

References kcenon::thread::thread_system_config::pool_config::backpressure, config_, kcenon::thread::backpressure_config::policy, and kcenon::thread::thread_system_config::pool.

◆ with_dag_failure_policy()

auto kcenon::thread::config_builder::with_dag_failure_policy ( dag_failure_policy policy) -> config_builder&
inline

Sets DAG failure policy.

Parameters
policyThe failure policy to use
Returns
Reference to this builder

Definition at line 409 of file thread_system_config.h.

410 {
411 config_.dag.failure_policy = policy;
412 return *this;
413 }
dag_failure_policy failure_policy
How to handle job failures.
Definition dag_config.h:82
dag_config dag
DAG (Directed Acyclic Graph) configuration.

References config_, kcenon::thread::thread_system_config::dag, and kcenon::thread::dag_config::failure_policy.

◆ with_dag_retry_params()

auto kcenon::thread::config_builder::with_dag_retry_params ( std::size_t max_retries,
std::chrono::milliseconds delay ) -> config_builder&
inline

Sets DAG retry parameters.

Parameters
max_retriesMaximum retry attempts
delayDelay between retries
Returns
Reference to this builder

Definition at line 421 of file thread_system_config.h.

423 {
424 config_.dag.max_retries = max_retries;
426 return *this;
427 }
@ delay
Delay processing (attempt later)
std::size_t max_retries
Maximum number of retry attempts for failed jobs.
Definition dag_config.h:90
std::chrono::milliseconds retry_delay
Delay between retry attempts.
Definition dag_config.h:97

References config_, kcenon::thread::thread_system_config::dag, kcenon::thread::delay, kcenon::thread::dag_config::max_retries, and kcenon::thread::dag_config::retry_delay.

◆ with_failure_threshold()

auto kcenon::thread::config_builder::with_failure_threshold ( std::size_t threshold) -> config_builder&
inline

Sets circuit breaker failure threshold.

Parameters
thresholdNumber of consecutive failures to open circuit
Returns
Reference to this builder

Definition at line 325 of file thread_system_config.h.

326 {
327 config_.resilience.circuit_breaker.failure_threshold = threshold;
328 return *this;
329 }

References kcenon::thread::thread_system_config::resilience_config::circuit_breaker, config_, and kcenon::thread::thread_system_config::resilience.

◆ with_open_duration()

auto kcenon::thread::config_builder::with_open_duration ( std::chrono::seconds duration) -> config_builder&
inline

Sets circuit breaker open duration.

Parameters
durationTime in open state before half-open
Returns
Reference to this builder

Definition at line 336 of file thread_system_config.h.

337 {
338 // Note: common_system uses 'timeout' instead of 'open_duration'
339 config_.resilience.circuit_breaker.timeout = duration;
340 return *this;
341 }

References kcenon::thread::thread_system_config::resilience_config::circuit_breaker, config_, and kcenon::thread::thread_system_config::resilience.

◆ with_priority_aging_params()

auto kcenon::thread::config_builder::with_priority_aging_params ( std::chrono::milliseconds interval,
int boost,
int max_boost ) -> config_builder&
inline

Sets priority aging parameters.

Parameters
intervalAging interval
boostBoost per interval
max_boostMaximum boost
Returns
Reference to this builder

Definition at line 384 of file thread_system_config.h.

387 {
391 return *this;
392 }
int priority_boost_per_interval
Amount of priority boost applied per aging interval.
int max_priority_boost
Maximum total priority boost that can be applied.
std::chrono::milliseconds aging_interval
Interval at which aging is applied.

References kcenon::thread::priority_aging_config::aging_interval, config_, kcenon::thread::priority_aging_config::max_priority_boost, kcenon::thread::thread_system_config::scaling_config::priority_aging, kcenon::thread::priority_aging_config::priority_boost_per_interval, and kcenon::thread::thread_system_config::scaling.

◆ with_queue_capacity()

auto kcenon::thread::config_builder::with_queue_capacity ( std::size_t capacity) -> config_builder&
inline

Sets the queue capacity.

Parameters
capacityMaximum queue size
Returns
Reference to this builder

Definition at line 270 of file thread_system_config.h.

271 {
272 config_.pool.queue_capacity = capacity;
273 return *this;
274 }
std::size_t queue_capacity
Maximum number of jobs in the queue.

References config_, kcenon::thread::thread_system_config::pool, and kcenon::thread::thread_system_config::pool_config::queue_capacity.

◆ with_watermarks()

auto kcenon::thread::config_builder::with_watermarks ( double low,
double high ) -> config_builder&
inline

Sets backpressure watermarks.

Parameters
lowLow watermark (0.0 to 1.0)
highHigh watermark (0.0 to 1.0)
Returns
Reference to this builder

Definition at line 303 of file thread_system_config.h.

304 {
307 return *this;
308 }
@ low
Between low and high watermark.
@ high
Above high_watermark, approaching capacity.
double low_watermark
Low watermark threshold (percentage of max_size).
double high_watermark
High watermark threshold (percentage of max_size).

References kcenon::thread::thread_system_config::pool_config::backpressure, config_, kcenon::thread::high, kcenon::thread::backpressure_config::high_watermark, kcenon::thread::low, kcenon::thread::backpressure_config::low_watermark, and kcenon::thread::thread_system_config::pool.

◆ with_work_stealing_params()

auto kcenon::thread::config_builder::with_work_stealing_params ( std::size_t max_attempts,
std::chrono::microseconds backoff ) -> config_builder&
inline

Sets work stealing parameters.

Parameters
max_attemptsMaximum steal attempts
backoffBackoff duration between attempts
Returns
Reference to this builder

Definition at line 359 of file thread_system_config.h.

361 {
362 config_.pool.max_steal_attempts = max_attempts;
363 config_.pool.steal_backoff = backoff;
364 return *this;
365 }
std::size_t max_steal_attempts
Maximum steal attempts before backing off.
std::chrono::microseconds steal_backoff
Backoff duration between steal attempts.

References config_, kcenon::thread::thread_system_config::pool_config::max_steal_attempts, kcenon::thread::thread_system_config::pool, and kcenon::thread::thread_system_config::pool_config::steal_backoff.

◆ with_worker_count()

auto kcenon::thread::config_builder::with_worker_count ( std::size_t count) -> config_builder&
inline

Sets the number of worker threads.

Parameters
countNumber of workers
Returns
Reference to this builder

Definition at line 259 of file thread_system_config.h.

260 {
261 config_.pool.worker_count = count;
262 return *this;
263 }
std::size_t worker_count
Number of worker threads in the pool.

References config_, kcenon::thread::thread_system_config::pool, and kcenon::thread::thread_system_config::pool_config::worker_count.

Member Data Documentation

◆ config_


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