From ac76fcdd7c6e30b21e82b0b9d69c049f3d691b19 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 4 Oct 2024 00:19:45 +0200 Subject: [PATCH] Have stats use num_workers as concurrency metric, not cpu cores Thanks to @Antti for finding this bug and reporting it via https://github.com/film42/sidekiq-rs/pull/50 --- src/processor.rs | 3 ++- src/stats.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/processor.rs b/src/processor.rs index f0149a8..1ecc346 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -240,7 +240,8 @@ impl Processor { "UNKNOWN_HOSTNAME".to_string() }; - let stats_publisher = StatsPublisher::new(hostname, queues, busy_jobs); + let stats_publisher = + StatsPublisher::new(hostname, queues, busy_jobs, self.config.num_workers); loop { // TODO: Use process count to meet a 5 second avg. diff --git a/src/stats.rs b/src/stats.rs index e212ee4..006aad5 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -58,6 +58,7 @@ pub struct StatsPublisher { queues: Vec, started_at: chrono::DateTime, busy_jobs: Counter, + concurrency: usize, } fn generate_identity(hostname: &String) -> String { @@ -71,7 +72,12 @@ fn generate_identity(hostname: &String) -> String { impl StatsPublisher { #[must_use] - pub fn new(hostname: String, queues: Vec, busy_jobs: Counter) -> Self { + pub fn new( + hostname: String, + queues: Vec, + busy_jobs: Counter, + concurrency: usize, + ) -> Self { let identity = generate_identity(&hostname); let started_at = chrono::Utc::now(); @@ -81,6 +87,7 @@ impl StatsPublisher { queues, started_at, busy_jobs, + concurrency, } } @@ -143,7 +150,7 @@ impl StatsPublisher { beat: chrono::Utc::now(), info: ProcessInfo { - concurrency: num_cpus::get(), + concurrency: self.concurrency, hostname: self.hostname.clone(), identity: self.identity.clone(), queues: self.queues.clone(),