21#include <condition_variable>
125 auto start() -> void;
138 [[nodiscard]]
auto is_active() const ->
bool;
160 auto
scale_to(
std::
size_t target_workers) -> common::VoidResult;
166 auto
scale_up() -> common::VoidResult;
278 std::condition_variable
cv_;
Configuration for autoscaling behavior and thresholds.
Manages automatic scaling of thread pool workers based on load metrics.
std::mutex history_mutex_
auto collect_metrics() const -> scaling_metrics_sample
Collects current metrics from the pool.
auto can_scale_down() const -> bool
Checks if scale-down cooldown has elapsed.
auto scale_to(std::size_t target_workers) -> common::VoidResult
Manually scales to a specific worker count.
std::uint64_t last_jobs_submitted_
std::atomic< bool > running_
std::chrono::steady_clock::time_point last_sample_time_
std::condition_variable cv_
auto is_active() const -> bool
Checks if the autoscaler is currently active.
auto make_decision(const std::vector< scaling_metrics_sample > &samples) const -> scaling_decision
Makes a scaling decision based on recent samples.
auto get_stats() const -> autoscaling_stats
Gets autoscaling statistics.
std::unique_ptr< std::thread > monitor_thread_
auto scale_up() -> common::VoidResult
Manually scales up by the configured increment.
autoscaling_policy policy_
autoscaler(const autoscaler &)=delete
auto get_metrics_history(std::size_t count=60) const -> std::vector< scaling_metrics_sample >
Gets historical metrics samples.
auto execute_scaling(const scaling_decision &decision) -> void
Executes a scaling decision.
auto evaluate_now() -> scaling_decision
Manually triggers a scaling evaluation.
std::chrono::steady_clock::time_point last_scale_down_time_
auto start() -> void
Starts the autoscaling monitor thread.
std::deque< scaling_metrics_sample > metrics_history_
auto stop() -> void
Stops the autoscaling monitor thread.
autoscaler & operator=(const autoscaler &)=delete
~autoscaler()
Destructor. Stops the monitor thread if running.
auto scale_down() -> common::VoidResult
Manually scales down by the configured increment.
std::uint64_t last_jobs_completed_
auto reset_stats() -> void
Resets autoscaling statistics.
auto get_current_metrics() const -> scaling_metrics_sample
Collects current metrics from the thread pool.
autoscaler(autoscaler &&)=delete
auto can_scale_up() const -> bool
Checks if scale-up cooldown has elapsed.
auto get_policy() const -> const autoscaling_policy &
Gets the current autoscaling policy.
auto add_workers(std::size_t count) -> common::VoidResult
Adds workers to the pool.
autoscaler(thread_pool &pool, autoscaling_policy policy={})
Constructs an autoscaler for the given thread pool.
auto remove_workers(std::size_t count) -> common::VoidResult
Removes workers from the pool.
auto set_policy(autoscaling_policy policy) -> void
Updates the autoscaling policy.
std::chrono::steady_clock::time_point last_scale_up_time_
autoscaler & operator=(autoscaler &&)=delete
auto monitor_loop() -> void
Main monitoring loop running in the background thread.
A thread pool for concurrent execution of jobs using multiple worker threads.
Error codes and utilities for the thread system.
Core threading foundation of the thread system library.
Scaling direction and metrics for autoscaling decisions.
Configuration for autoscaling behavior.
Statistics for autoscaling operations.
Metrics sample for autoscaling decisions.