Skip to content

Commit

Permalink
Have stats use num_workers as concurrency metric, not cpu cores
Browse files Browse the repository at this point in the history
Thanks to @Antti for finding this bug and reporting it via #50
  • Loading branch information
film42 committed Oct 3, 2024
1 parent 0782e18 commit ac76fcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct StatsPublisher {
queues: Vec<String>,
started_at: chrono::DateTime<chrono::Utc>,
busy_jobs: Counter,
concurrency: usize,
}

fn generate_identity(hostname: &String) -> String {
Expand All @@ -71,7 +72,12 @@ fn generate_identity(hostname: &String) -> String {

impl StatsPublisher {
#[must_use]
pub fn new(hostname: String, queues: Vec<String>, busy_jobs: Counter) -> Self {
pub fn new(
hostname: String,
queues: Vec<String>,
busy_jobs: Counter,
concurrency: usize,
) -> Self {
let identity = generate_identity(&hostname);
let started_at = chrono::Utc::now();

Expand All @@ -81,6 +87,7 @@ impl StatsPublisher {
queues,
started_at,
busy_jobs,
concurrency,
}
}

Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit ac76fcd

Please sign in to comment.