Skip to content

Commit

Permalink
Fix calculating average processing time for service API
Browse files Browse the repository at this point in the history
  • Loading branch information
jadamcrain authored Nov 2, 2023
1 parent 67b2798 commit e0b1e4d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion async-nats/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,10 @@ impl Request {
let stats = stats.endpoints.get_mut(self.endpoint.as_str()).unwrap();
stats.requests += 1;
stats.processing_time += elapsed;
stats.average_processing_time = stats.processing_time.checked_div(2).unwrap();
stats.average_processing_time = {
let avg_nanos = (stats.processing_time.as_nanos() / stats.requests as u128) as u64;
Duration::from_nanos(avg_nanos)
};
result
}
}
Expand Down

0 comments on commit e0b1e4d

Please sign in to comment.