Skip to content

Commit

Permalink
Don't clone the whole task_monitors vector on each iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
hrxi committed Nov 28, 2024
1 parent 3d4bd1b commit 8117984
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions metrics-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ pub fn start_metrics_server<TNetwork: Network>(
spawn(async move { metrics_server(addr, registry).await.unwrap() });

// Spawn Tokio task monitor updaters
for i in 0..task_monitors.len() {
let task_monitors = task_monitors.to_vec();
for task_monitor in task_monitors {
spawn({
let task_metrics = Arc::clone(&task_metrics);
let task_monitors = task_monitors;
let task_monitor = task_monitor.clone();
async move {
TokioTaskMetrics::update_metric_values(
task_metrics,
&task_monitors[i].name,
task_monitors[i].monitor.clone(),
&task_monitor.name,
task_monitor.monitor.clone(),
)
.await;
}
Expand Down

0 comments on commit 8117984

Please sign in to comment.