Skip to content

Commit

Permalink
Terminate the benchmark after 65 mintues (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Oct 10, 2024
1 parent 4ae87d1 commit 14d029c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
9 changes: 9 additions & 0 deletions benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ struct GlobalOpts {
default_value = PathBuf::from("benchmark_db").into_os_string(),
)]
dbname: PathBuf,
#[arg(
long,
short = 't',
required = false,
help = "Terminate the test after this many minutes",
value_name = "TRUNCATE",
default_value_t = 65
)]
duration_minutes: u64,
}

mod create;
Expand Down
8 changes: 5 additions & 3 deletions benchmark/src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ use std::time::Instant;
pub struct Single;

impl TestRunner for Single {
async fn run(&self, db: &Db, _args: &crate::Args) -> Result<(), Box<dyn Error>> {
async fn run(&self, db: &Db, args: &crate::Args) -> Result<(), Box<dyn Error>> {
let start = Instant::now();
let inner_key = Sha256::digest(0u64.to_ne_bytes()).to_vec();
let mut batch_id = 0;

for batch_id in 0.. {
while start.elapsed().as_secs() / 60 < args.global_opts.duration_minutes {
let batch = vec![BatchOp::Put {
key: inner_key.clone(),
value: vec![batch_id as u8],
Expand All @@ -33,7 +34,8 @@ impl TestRunner for Single {
pretty_duration(&start.elapsed(), None)
);
}
batch_id += 1;
}
unreachable!()
Ok(())
}
}
6 changes: 5 additions & 1 deletion benchmark/src/tenkrandom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the file LICENSE.md for licensing terms.

use std::error::Error;
use std::time::Instant;

use firewood::db::{BatchOp, Db};
use firewood::logger::debug;
Expand All @@ -19,7 +20,9 @@ impl TestRunner for TenKRandom {
let mut high = args.number_of_batches * args.batch_size;
let twenty_five_pct = args.batch_size / 4;

loop {
let start = Instant::now();

while start.elapsed().as_secs() / 60 < args.global_opts.duration_minutes {
let batch: Vec<BatchOp<_, _>> = Self::generate_inserts(high, twenty_five_pct)
.chain(generate_deletes(low, twenty_five_pct))
.chain(generate_updates(low + high / 2, twenty_five_pct * 2, low))
Expand All @@ -29,6 +32,7 @@ impl TestRunner for TenKRandom {
low += twenty_five_pct;
high += twenty_five_pct;
}
Ok(())
}
}
fn generate_updates(
Expand Down
6 changes: 4 additions & 2 deletions benchmark/src/zipf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ impl TestRunner for Zipf {
let rows = (args.number_of_batches * args.batch_size) as usize;
let zipf = zipf::ZipfDistribution::new(rows, exponent).unwrap();
let start = Instant::now();
let mut batch_id = 0;

for batch_id in 0.. {
while start.elapsed().as_secs() / 60 < args.global_opts.duration_minutes {
let batch: Vec<BatchOp<_, _>> =
generate_updates(batch_id, args.batch_size as usize, &zipf).collect();
if log::log_enabled!(log::Level::Debug) {
Expand Down Expand Up @@ -62,8 +63,9 @@ impl TestRunner for Zipf {
pretty_duration(&start.elapsed(), None)
);
}
batch_id += 1;
}
unreachable!()
Ok(())
}
}
fn generate_updates(
Expand Down

0 comments on commit 14d029c

Please sign in to comment.