Skip to content

Commit

Permalink
Fixed potential div-by-0 in logging stats (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
slawlor authored May 11, 2023
1 parent 2e9b000 commit 9593f4a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ractor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ractor"
version = "0.8.3"
version = "0.8.4"
authors = ["Sean Lawlor", "Evan Au", "Dillon George"]
description = "A actor framework for Rust"
documentation = "https://docs.rs/ractor"
Expand Down
35 changes: 29 additions & 6 deletions ractor/src/factory/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,23 @@ Avg time in factory queue: {}us
Num expired jobs: {}
Num discarded jobs: {}
",
self.ping_timing_us / self.ping_count as u128,
if self.ping_count > 0 {
self.ping_timing_us / self.ping_count as u128
} else {
0
},
self.total_processed_job_count,
self.avg_job_qps(),
self.job_processing_latency_usec / self.processed_job_count as u128,
self.factory_processing_latency_usec / self.processed_job_count as u128,
if self.processed_job_count > 0 {
self.job_processing_latency_usec / self.processed_job_count as u128
} else {
0
},
if self.processed_job_count > 0 {
self.factory_processing_latency_usec / self.processed_job_count as u128
} else {
0
},
self.total_num_expired_jobs,
self.total_num_discarded_jobs,
)
Expand Down Expand Up @@ -120,7 +132,10 @@ impl MessageProcessingStats {
if self.ping_count > RESET_PINGS_AFTER {
// When we hit 10min, convert the message timing to an average and reset the counters
// this lets us track degradation without being overwhelmed by old (stale) data
self.ping_timing_us /= self.ping_count as u128;
if self.ping_count > 0 {
self.ping_timing_us /= self.ping_count as u128;
}

self.ping_count = 1;
return true;
}
Expand Down Expand Up @@ -160,9 +175,17 @@ impl MessageProcessingStats {
}

pub(crate) fn avg_job_qps(&self) -> u128 {
let us_between_jobs = self.job_incoming_time_us / self.job_count as u128;
if self.job_count > 0 {
let us_between_jobs = self.job_incoming_time_us / self.job_count as u128;

MICROS_IN_SEC / us_between_jobs
if us_between_jobs > 0 {
MICROS_IN_SEC / us_between_jobs
} else {
0
}
} else {
0
}
}

/// Called each time a job is completed to report factory processing time, worker processing time, total processing time
Expand Down
2 changes: 1 addition & 1 deletion ractor_cluster/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ractor_cluster"
version = "0.8.3"
version = "0.8.4"
authors = ["Sean Lawlor", "Evan Au", "Dillon George"]
description = "Distributed cluster environment of Ractor actors"
documentation = "https://docs.rs/ractor"
Expand Down
2 changes: 1 addition & 1 deletion ractor_cluster_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ractor_cluster_derive"
version = "0.8.3"
version = "0.8.4"
authors = ["Sean Lawlor <[email protected]>"]
description = "Derives for ractor_cluster"
license = "MIT"
Expand Down

0 comments on commit 9593f4a

Please sign in to comment.