Skip to content

Commit

Permalink
refactor: count actual rows, and make mode an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Jul 28, 2023
1 parent 8867ba8 commit 22ad89a
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions iroh/examples/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async fn handle_command(
mode = format!("{mode:?}").to_lowercase()
);
let start = Instant::now();
let mut handles: Vec<JoinHandle<anyhow::Result<()>>> = Vec::new();
let mut handles: Vec<JoinHandle<anyhow::Result<usize>>> = Vec::new();
match mode {
HammerMode::Set => {
let mut bytes = vec![0; size];
Expand All @@ -382,7 +382,7 @@ async fn handle_command(
let key = format!("{}/{}/{}", prefix, t, i);
doc.insert_bytes(key, value.into_bytes().into()).await?;
}
Ok(())
Ok(count)
});
handles.push(handle);
}
Expand All @@ -392,30 +392,32 @@ async fn handle_command(
let prefix = prefix.clone();
let doc = doc.clone();
let handle = tokio::spawn(async move {
let mut read = 0;
for i in 0..count {
let key = format!("{}/{}/{}", prefix, t, i);
let entries = doc.replica().all_for_key(key.as_bytes());
for (_id, entry) in entries {
let _content = fmt_content(&doc, &entry).await;
read += 1;
}
}
Ok(())
Ok(read)
});
handles.push(handle);
}
}
}

let mut total_count = 0;
for result in futures::future::join_all(handles).await {
// Check that no errors ocurred
result??;
// Check that no errors ocurred and count rows inserted/read
total_count += result??;
}

let diff = start.elapsed().as_secs_f64();
let total_count = threads as u64 * count as u64;
println!(
"> Hammering done in {diff:.2}s for {total_count} messages with total of {size}",
size = HumanBytes(total_count * size as u64),
size = HumanBytes(total_count as u64 * size as u64),
);
}
Cmd::Exit => {}
Expand Down Expand Up @@ -573,6 +575,9 @@ pub enum Cmd {
Stats,
/// Hammer time - stress test with the hammer
Hammer {
/// The hammer mode
#[clap(value_enum)]
mode: HammerMode,
/// The key prefix
prefix: String,
/// The number of threads to use (each thread will create it's own replica)
Expand All @@ -584,19 +589,16 @@ pub enum Cmd {
/// The size of each entry in Bytes
#[clap(long, short, default_value = "1024")]
size: usize,
/// Select the hammer mode
#[clap(long, short, value_enum, default_value = "set")]
mode: HammerMode,
},
/// Quit
Exit,
}

#[derive(Clone, Debug, clap::ValueEnum)]
pub enum HammerMode {
/// Set mode (create entries)
/// Create entries
Set,
/// Get mode (read entries)
/// Read entries
Get,
}

Expand Down

0 comments on commit 22ad89a

Please sign in to comment.