Skip to content

Commit

Permalink
Merge pull request #53 from film42/gt/stats_cpu
Browse files Browse the repository at this point in the history
Have stats use num_workers as concurrency metric, not cpu cores
  • Loading branch information
film42 authored Oct 3, 2024
2 parents 511b102 + ac76fcd commit 312aab2
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 312aab2

Please sign in to comment.