WorkPoolConfig struct
#include <gtopt/work_pool.hpp>
Constructors, destructors, conversion operators
-
WorkPoolConfig(int max_threads_ = static_cast<int>(physical_
concurrency()), double max_cpu_threshold_ = 95.0, double min_free_memory_mb_ = 4096.0, double max_memory_percent_ = 90.0, double max_process_rss_mb_ = 0.0, std::chrono::milliseconds scheduler_interval_ = std::chrono::milliseconds(50), std::string name_ = "WorkPool", bool enable_periodic_stats_ = true, double max_process_swap_mb_ = default_ max_ process_ swap_ mb(), double max_swap_io_per_sec_ = 0.0, int max_threads_ceiling_ = 0) explicit noexcept
Public variables
- bool enable_periodic_stats
- double max_cpu_threshold
- double max_memory_percent
- Block dispatch if system usage > this (%).
- double max_process_rss_mb
- Block dispatch if process RSS > this (0=off).
- double max_process_swap_mb
- double max_swap_io_per_sec
- int max_threads
- int max_threads_ceiling
- double min_free_memory_mb
- Block dispatch if system free < this (MB).
- std::string name
- std::function<double()> process_swap_source
- std::chrono::milliseconds scheduler_interval
- double swap_growth_mb
- std::chrono::milliseconds swap_growth_window
Variable documentation
bool gtopt:: WorkPoolConfig:: enable_periodic_stats
Log periodic CPU/MEM stats
double gtopt:: WorkPoolConfig:: max_process_swap_mb
Cap on process bytes paged to swap (MB). Dispatch is blocked while VmSwap is at/above this AND still growing (see swap_growth_mb and SwapGrowthGate): a large but STATIC VmSwap — cold pages parked on swap with no I/O — never throttles. Default 2048 MB (default_max_process_swap_mb()); set to 0 to disable.
double gtopt:: WorkPoolConfig:: max_swap_io_per_sec
Soft cap on system swap I/O rate (pages/sec, sum of pswpin+pswpout). When the kernel is thrashing above this rate, dispatch is blocked. Only evaluated near thread saturation so quiescent paging (e.g. init-time swap readahead) does not stall the pool. 0 = disabled.
int gtopt:: WorkPoolConfig:: max_threads_ceiling
Absolute upper bound the pool may grow max_threads to at runtime once observed per-task RSS deltas show the initial (memory-clamped) thread count left headroom unused. 0 = no growth (ceiling equals max_threads). Typically set to the un-clamped CPU budget (cpu_factor × cores) so a conservative bootstrap clamp can recover to full parallelism when tasks turn out to be cheap.
std::function<double()> gtopt:: WorkPoolConfig:: process_swap_source
Test hook: when set, replaces the memory monitor's process-VmSwap reading (MB) used by the swap gate. Called from worker threads (under the pool's queue mutex) and from statistics readers, so it must be thread-safe, cheap, and must not call back into the pool.
double gtopt:: WorkPoolConfig:: swap_growth_mb
VmSwap growth (MB per swap_growth_window) above which the process counts as actively swapping. Default 64 MB (default_swap_growth_mb()); 0 = any net growth counts.
std::chrono::milliseconds gtopt:: WorkPoolConfig:: swap_growth_window
Observation window for swap_growth_mb. Also the release hysteresis: the gate opens after one full window without growth.