Skip to content

Commit

Permalink
bench: check stop condition first to avoid zero division
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdroychan committed Nov 10, 2024
1 parent efbaa46 commit 8b71d1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,12 @@ fn bench_worker_regular(map: Arc<Box<dyn KVMap>>, context: WorkerContext) {

// start benchmark
loop {
// check if we need to break
if bench_repeat_should_break(&benchmark.len, *counter, start, &mut workload) {
workload.reset();
break;
}

let op = workload.next(&mut rng);
let op_start = latency_tick();
match op {
Expand All @@ -731,12 +737,6 @@ fn bench_worker_regular(map: Arc<Box<dyn KVMap>>, context: WorkerContext) {
if let Some(r) = &rate_limiter {
r.backoff(*counter);
}

// check if we need to break
if bench_repeat_should_break(&benchmark.len, *counter, start, &mut workload) {
workload.reset();
break;
}
}

// after the execution, counter is up-to-date, so it's time to update duration
Expand Down Expand Up @@ -831,17 +831,18 @@ fn bench_worker_async(map: Arc<Box<dyn AsyncKVMap>>, context: WorkerContext) {
requests.clear();
// sample requests
for _ in 0..benchmark.batch {
// stop the batch generation if the repeat is done
if bench_repeat_should_break(&benchmark.len, *counter, start, &mut workload) {
break;
}

let op = workload.next(&mut rng);
requests.push(Request { id: rid, op });
rid += 1;
// need to add to count here, instead of after this loop
// otherwise the last check may fail because the time check is after a certain
// interval, but the mod is never 0
*counter += 1;
// stop the batch generation if the repeat is done
if bench_repeat_should_break(&benchmark.len, *counter, start, &mut workload) {
break;
}
// if a rate limiter is in place and no further backoff is needed, break early to
// send the batch immediately
if let Some(r) = &rate_limiter {
Expand Down
2 changes: 1 addition & 1 deletion src/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl Workload {
}

pub fn is_exhausted(&self) -> bool {
self.kgen.serial == (self.kgen.max - self.kgen.min)
self.kgen.serial == self.kgen.keyspace
}
}

Expand Down

0 comments on commit 8b71d1d

Please sign in to comment.