Skip to content

Commit a8310a6

Browse files
authored
fix(pool): Fix pool metrics (#4666)
1 parent 25c8c4b commit a8310a6

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

relay-system/src/monitor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ pin_project_lite::pin_project! {
2222
impl<F> MonitoredFuture<F> {
2323
/// Wraps a future with the [`MonitoredFuture`].
2424
pub fn wrap(inner: F) -> Self {
25+
Self::wrap_with_metrics(inner, Arc::new(RawMetrics::default()))
26+
}
27+
28+
/// Wraps a future with the [`MonitoredFuture`].
29+
pub fn wrap_with_metrics(inner: F, metrics: Arc<RawMetrics>) -> Self {
2530
Self {
2631
inner,
27-
metrics: Arc::new(RawMetrics::default()),
32+
metrics,
2833
// The last time the utilization was updated.
2934
last_utilization_update: Instant::now(),
3035
// The poll duration that was accumulated across zero or more polls since the last

relay-threading/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ impl AsyncPoolMetrics<'_> {
106106
.map(|m| m.active_tasks.load(Ordering::Relaxed))
107107
.sum();
108108

109-
(total_polled_futures as f32 / self.max_tasks as f32).clamp(0.0, 1.0) as u8 * 100
109+
((total_polled_futures as f32 / self.max_tasks as f32).clamp(0.0, 1.0) * 100.0) as u8
110110
}
111111
}

relay-threading/src/pool.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ where
6767

6868
let thread_name: Option<String> = builder.thread_name.as_mut().map(|f| f(thread_id));
6969
let metrics = Arc::new(ThreadMetrics::default());
70-
let task = MonitoredFuture::wrap(Multiplexed::new(
71-
pool_name,
72-
builder.max_concurrency,
73-
rx.into_stream(),
74-
builder.task_panic_handler.clone(),
75-
metrics.clone(),
76-
));
70+
let task = MonitoredFuture::wrap_with_metrics(
71+
Multiplexed::new(
72+
pool_name,
73+
builder.max_concurrency,
74+
rx.into_stream(),
75+
builder.task_panic_handler.clone(),
76+
metrics.clone(),
77+
),
78+
metrics.raw_metrics.clone(),
79+
);
7780

7881
let thread = Thread {
7982
id: thread_id,

0 commit comments

Comments
 (0)