17 : autoscaler_(
std::move(scaler))
49 return "autoscaling_pool_policy";
54 return enabled_.load(std::memory_order_acquire);
59 bool was_enabled =
enabled_.exchange(enabled, std::memory_order_acq_rel);
62 if (enabled && !was_enabled) {
67 }
else if (!enabled && was_enabled) {
121 return default_policy;
127 return autoscaler_->evaluate_now();
135 return autoscaler_->scale_to(target_workers);
Pool policy implementing automatic worker scaling based on load.
Manages automatic scaling of thread pool workers based on load metrics.
auto get_stats() const -> autoscaling_stats
Gets current autoscaling statistics.
std::shared_ptr< autoscaler > autoscaler_
auto get_autoscaler() const -> std::shared_ptr< autoscaler >
Gets the underlying autoscaler.
autoscaling_pool_policy(thread_pool &pool, const autoscaling_policy &config={})
Constructs an autoscaling pool policy with the given configuration.
auto scale_to(std::size_t target_workers) -> common::VoidResult
Manually scales to a specific worker count.
void set_policy(const autoscaling_policy &config)
Updates the autoscaling policy configuration.
void start()
Starts the autoscaler monitor thread.
std::atomic< bool > enabled_
auto get_name() const -> std::string override
Gets the policy name.
~autoscaling_pool_policy() override
Destructor. Stops the autoscaler if running.
void set_enabled(bool enabled) override
Enables or disables the policy.
auto evaluate_now() -> scaling_decision
Manually triggers a scaling evaluation.
auto is_enabled() const -> bool override
Checks if the policy is enabled.
auto is_active() const -> bool
Checks if the autoscaler is currently active.
void on_job_start(job &j) override
Called when job starts executing.
void on_job_complete(job &j, bool success, const std::exception *error=nullptr) override
Called when a job completes.
auto on_enqueue(job &j) -> common::VoidResult override
Called before a job is enqueued.
void stop()
Stops the autoscaler monitor thread.
auto get_policy() const -> const autoscaling_policy &
Gets the current autoscaling policy configuration.
Represents an error in the thread system.
Represents a unit of work (task) to be executed, typically by a job queue.
A thread pool for concurrent execution of jobs using multiple worker threads.
Base job class for schedulable work units in the thread system.
Core threading foundation of the thread system library.
Configuration for autoscaling behavior.
Statistics for autoscaling operations.