Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
scaling_metrics.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
12#pragma once
13
14#include <chrono>
15#include <cstddef>
16#include <cstdint>
17
18namespace kcenon::thread
19{
24 {
25 none,
26 up,
27 down
28 };
29
33 enum class scaling_reason
34 {
37 latency,
38 manual,
40 };
41
52 {
54 std::chrono::steady_clock::time_point timestamp;
55
57 std::size_t worker_count{0};
58
60 std::size_t active_workers{0};
61
63 std::size_t queue_depth{0};
64
66 double utilization{0.0};
67
70
72 double p95_latency_ms{0.0};
73
75 std::uint64_t jobs_completed{0};
76
78 std::uint64_t jobs_submitted{0};
79
82 };
83
91 {
94
97
99 std::size_t target_workers{0};
100
102 std::string explanation;
103
108 [[nodiscard]] auto should_scale() const -> bool
109 {
111 }
112 };
113
121 {
123 std::size_t scale_up_count{0};
124
126 std::size_t scale_down_count{0};
127
129 std::size_t decisions_evaluated{0};
130
132 std::chrono::steady_clock::time_point last_scale_up;
133
135 std::chrono::steady_clock::time_point last_scale_down;
136
138 std::size_t peak_workers{0};
139
141 std::size_t min_workers{0};
142 };
143
144} // namespace kcenon::thread
@ none
Below low_watermark, queue is healthy.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
scaling_direction
Scaling direction for autoscaling decisions.
@ up
Scale up (add workers)
@ down
Scale down (remove workers)
scaling_reason
Reason for scaling decision.
@ manual
Manual trigger via API.
@ scheduled
Scheduled scaling event.
@ latency
Latency threshold exceeded.
@ worker_utilization
Worker utilization threshold exceeded.
@ queue_depth
Queue depth threshold exceeded.
Statistics for autoscaling operations.
std::size_t scale_up_count
Number of scale-up events.
std::size_t decisions_evaluated
Number of decisions evaluated.
std::chrono::steady_clock::time_point last_scale_down
Time of last scale-down event.
std::chrono::steady_clock::time_point last_scale_up
Time of last scale-up event.
std::size_t scale_down_count
Number of scale-down events.
std::size_t peak_workers
Peak worker count observed.
std::size_t min_workers
Minimum worker count observed.
Scaling decision result.
std::string explanation
Human-readable explanation.
auto should_scale() const -> bool
Checks if scaling should occur.
scaling_reason reason
Reason for the decision.
scaling_direction direction
The scaling direction.
std::size_t target_workers
Target worker count after scaling.
Metrics sample for autoscaling decisions.
std::uint64_t jobs_submitted
Jobs submitted since last sample.
std::size_t worker_count
Current number of workers in the pool.
std::chrono::steady_clock::time_point timestamp
Timestamp when this sample was collected.
double queue_depth_per_worker
Jobs per worker ratio.
std::uint64_t jobs_completed
Jobs completed since last sample.
std::size_t queue_depth
Number of jobs waiting in the queue.
double p95_latency_ms
P95 latency in milliseconds.
double throughput_per_second
Throughput in jobs per second.
std::size_t active_workers
Number of workers currently processing jobs.
double utilization
Worker utilization ratio (0.0 - 1.0)