Skip to content

Commit

Permalink
fix latency calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-maron committed Jun 11, 2024
1 parent f25e6a3 commit 7bf490b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cdn-proto/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ pub async fn running_latency_calculator() {
// Sleep for 30s
sleep(Duration::from_secs(30)).await;

// Fetch the current sum and count
let current_sum = metrics::LATENCY.get_sample_sum();
let current_count = metrics::LATENCY.get_sample_count();

// Calculate the running latency by subtracting the previous sum and count
latency_sum = metrics::LATENCY.get_sample_sum() - latency_sum;
latency_count = metrics::LATENCY.get_sample_count() - latency_count;
latency_sum = current_sum - latency_sum;
latency_count = current_count - latency_count;

// Set the running latency if the new count is not 0
if latency_count != 0 {
metrics::RUNNING_LATENCY.set(latency_sum / latency_count as f64);
}

// Update the previous sum and count for the next iteration
latency_sum = current_sum;
latency_count = current_count;
}
}

0 comments on commit 7bf490b

Please sign in to comment.