Skip to content

Commit

Permalink
Simplify by checking for 0.0 before infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh authored and byronwasti committed Dec 23, 2024
1 parent fcf1eab commit 756adf1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions balter/src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ where
.push((self.sampler.concurrency(), stats.mean));

let tps_per_task = stats.mean / self.sampler.concurrency() as f64;
let new_concurrency = (self.sampler.tps_limit().get() as f64 / tps_per_task).ceil();
//Make sure not infinity in case of division by zero (when mean is 0)
if new_concurrency.is_finite() {
let new_concurrency = (new_concurrency as usize).max(self.sampler.concurrency()).max(1);
if tps_per_task != 0.0 {
//Make sure not infinity in case of division by zero (when mean is 0)
let new_concurrency = (self.sampler.tps_limit().get() as f64 / tps_per_task).ceil();
let new_concurrency = (new_concurrency as usize)
.max(self.sampler.concurrency())
.max(1);
self.sampler.set_concurrency(new_concurrency);
}
}
Expand Down

0 comments on commit 756adf1

Please sign in to comment.