|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Pool policy that implements automatic scaling for dynamic worker management. More...
#include <autoscaling_pool_policy.h>


Public Member Functions | |
| autoscaling_pool_policy (thread_pool &pool, const autoscaling_policy &config={}) | |
| Constructs an autoscaling pool policy with the given configuration. | |
| autoscaling_pool_policy (std::shared_ptr< autoscaler > scaler) | |
| Constructs an autoscaling pool policy with an existing autoscaler. | |
| ~autoscaling_pool_policy () override | |
| Destructor. Stops the autoscaler if running. | |
| autoscaling_pool_policy (const autoscaling_pool_policy &)=delete | |
| autoscaling_pool_policy & | operator= (const autoscaling_pool_policy &)=delete |
| autoscaling_pool_policy (autoscaling_pool_policy &&)=delete | |
| autoscaling_pool_policy & | operator= (autoscaling_pool_policy &&)=delete |
| auto | on_enqueue (job &j) -> common::VoidResult override |
| Called before a job is enqueued. | |
| 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 | get_name () const -> std::string override |
| Gets the policy name. | |
| auto | is_enabled () const -> bool override |
| Checks if the policy is enabled. | |
| void | set_enabled (bool enabled) override |
| Enables or disables the policy. | |
| void | start () |
| Starts the autoscaler monitor thread. | |
| void | stop () |
| Stops the autoscaler monitor thread. | |
| auto | is_active () const -> bool |
| Checks if the autoscaler is currently active. | |
| auto | get_autoscaler () const -> std::shared_ptr< autoscaler > |
| Gets the underlying autoscaler. | |
| auto | get_stats () const -> autoscaling_stats |
| Gets current autoscaling statistics. | |
| void | set_policy (const autoscaling_policy &config) |
| Updates the autoscaling policy configuration. | |
| auto | get_policy () const -> const autoscaling_policy & |
| Gets the current autoscaling policy configuration. | |
| auto | evaluate_now () -> scaling_decision |
| Manually triggers a scaling evaluation. | |
| auto | scale_to (std::size_t target_workers) -> common::VoidResult |
| Manually scales to a specific worker count. | |
Public Member Functions inherited from kcenon::thread::pool_policy | |
| virtual | ~pool_policy ()=default |
| Virtual destructor for proper cleanup. | |
Private Attributes | |
| std::shared_ptr< autoscaler > | autoscaler_ |
| std::atomic< bool > | enabled_ {true} |
Pool policy that implements automatic scaling for dynamic worker management.
This policy wraps the autoscaling functionality as a composable pool policy, enabling automatic scaling without modifying the thread_pool class.
The autoscaler monitors thread pool metrics and adjusts worker count:
All methods are thread-safe and can be called from any thread.
Definition at line 59 of file autoscaling_pool_policy.h.
|
explicit |
Constructs an autoscaling pool policy with the given configuration.
| pool | Reference to the thread pool to manage. |
| config | Autoscaling policy configuration. |
Definition at line 11 of file autoscaling_pool_policy.cpp.
|
explicit |
Constructs an autoscaling pool policy with an existing autoscaler.
| scaler | Shared pointer to an existing autoscaler. |
This allows sharing an autoscaler across multiple pools or components.
Definition at line 16 of file autoscaling_pool_policy.cpp.
|
override |
Destructor. Stops the autoscaler if running.
Definition at line 21 of file autoscaling_pool_policy.cpp.
References autoscaler_.
|
delete |
|
delete |
|
nodiscard |
Manually triggers a scaling evaluation.
Definition at line 124 of file autoscaling_pool_policy.cpp.
|
nodiscard |
Gets the underlying autoscaler.
Useful for accessing detailed scaling controls and statistics.
Definition at line 95 of file autoscaling_pool_policy.cpp.
References autoscaler_.
|
nodiscardoverridevirtual |
Gets the policy name.
Implements kcenon::thread::pool_policy.
Definition at line 47 of file autoscaling_pool_policy.cpp.
|
nodiscard |
Gets the current autoscaling policy configuration.
Definition at line 115 of file autoscaling_pool_policy.cpp.
References autoscaler_.
|
nodiscard |
Gets current autoscaling statistics.
Definition at line 100 of file autoscaling_pool_policy.cpp.
References autoscaler_.
|
nodiscard |
Checks if the autoscaler is currently active.
Definition at line 90 of file autoscaling_pool_policy.cpp.
References autoscaler_.
|
nodiscardoverridevirtual |
Checks if the policy is enabled.
Reimplemented from kcenon::thread::pool_policy.
Definition at line 52 of file autoscaling_pool_policy.cpp.
References enabled_.
|
overridevirtual |
Called before a job is enqueued.
| j | Reference to the job being enqueued. |
Autoscaling does not reject jobs; it adjusts worker count to handle load.
Implements kcenon::thread::pool_policy.
Definition at line 28 of file autoscaling_pool_policy.cpp.
|
overridevirtual |
Called when a job completes.
| j | Reference to the completed job. |
| success | True if job succeeded. |
| error | Exception pointer if job failed. |
Records completion for metrics used in scaling decisions.
Implements kcenon::thread::pool_policy.
Definition at line 39 of file autoscaling_pool_policy.cpp.
References kcenon::thread::success.
|
overridevirtual |
Called when job starts executing.
| j | Reference to the job. |
Records job start for metrics collection.
Implements kcenon::thread::pool_policy.
Definition at line 34 of file autoscaling_pool_policy.cpp.
|
delete |
|
delete |
| auto kcenon::thread::autoscaling_pool_policy::scale_to | ( | std::size_t | target_workers | ) | -> common::VoidResult |
Manually scales to a specific worker count.
| target_workers | Desired number of workers. |
Definition at line 132 of file autoscaling_pool_policy.cpp.
|
overridevirtual |
Enables or disables the policy.
| enabled | Whether to enable. |
When disabled, the autoscaler is stopped. When enabled, it is started (if the pool is running).
Reimplemented from kcenon::thread::pool_policy.
Definition at line 57 of file autoscaling_pool_policy.cpp.
References autoscaler_, and enabled_.
| void kcenon::thread::autoscaling_pool_policy::set_policy | ( | const autoscaling_policy & | config | ) |
Updates the autoscaling policy configuration.
| config | New policy configuration. |
Definition at line 108 of file autoscaling_pool_policy.cpp.
References autoscaler_.
| void kcenon::thread::autoscaling_pool_policy::start | ( | ) |
Starts the autoscaler monitor thread.
Should be called after the pool starts. This is automatically managed if the policy is added before pool.start().
Definition at line 76 of file autoscaling_pool_policy.cpp.
References autoscaler_, and enabled_.
| void kcenon::thread::autoscaling_pool_policy::stop | ( | ) |
Stops the autoscaler monitor thread.
Definition at line 83 of file autoscaling_pool_policy.cpp.
References autoscaler_.
|
private |
Definition at line 205 of file autoscaling_pool_policy.h.
Referenced by get_autoscaler(), get_policy(), get_stats(), is_active(), set_enabled(), set_policy(), start(), stop(), and ~autoscaling_pool_policy().
|
private |
Definition at line 206 of file autoscaling_pool_policy.h.
Referenced by is_enabled(), set_enabled(), and start().