From e04488cab6dff6b9296e09369bf82e1cd8cde319 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Mon, 22 Jul 2024 00:59:32 +0200 Subject: [PATCH] bin: minor tweaks --- src/bin/toydb.rs | 5 +---- src/bin/toydump.rs | 2 +- src/bin/workload.rs | 34 ++++++++++++++++++---------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/bin/toydb.rs b/src/bin/toydb.rs index d0eceeca..14f53692 100644 --- a/src/bin/toydb.rs +++ b/src/bin/toydb.rs @@ -120,10 +120,7 @@ impl Command { )?; Box::new(sql::engine::Raft::new_state(engine)?) } - "memory" => { - let engine = storage::Memory::new(); - Box::new(sql::engine::Raft::new_state(engine)?) - } + "memory" => Box::new(sql::engine::Raft::new_state(storage::Memory::new())?), name => return errinput!("invalid SQL storage engine {name}"), }; diff --git a/src/bin/toydump.rs b/src/bin/toydump.rs index a487800e..1859d3f5 100644 --- a/src/bin/toydump.rs +++ b/src/bin/toydump.rs @@ -1,5 +1,5 @@ //! toydump is a debug tool that prints a toyDB BitCask database in -//! human-readable form. It can print both the SQL database, and the Raft log +//! human-readable form. It can print both the SQL database and the Raft log //! (via --raft). It only outputs live BitCask data, not garbage entries. #![warn(clippy::all)] diff --git a/src/bin/workload.rs b/src/bin/workload.rs index a1bdc22f..beecc53d 100644 --- a/src/bin/workload.rs +++ b/src/bin/workload.rs @@ -1,17 +1,20 @@ -//! Runs toyDB workload benchmarks. For example, a read-only -//! workload can be run as: +//! Runs toyDB workload benchmarks. By default, it assumes a running 5-node +//! cluster as launched via cluster/run.sh, but this can be modified via -H. +//! For example, a read-only workload can be run as: //! -//! cargo run --bin workload -- -//! --hosts localhost:9605,localhost:9604,localhost:9603 -//! --concurrency 16 --count 100000 -//! read --rows 1000 --size 65536 --batch 10 +//! cargo run --release --bin workload -- read //! //! See --help for a list of available workloads and arguments. #![warn(clippy::all)] +use hdrhistogram::Histogram; +use toydb::error::Result; +use toydb::sql::types::{Row, Rows}; +use toydb::{Client, StatementResult}; + use clap::Parser; -use itertools::Itertools; +use itertools::Itertools as _; use petname::Generator as _; use rand::distributions::Distribution as _; use rand::rngs::StdRng; @@ -19,16 +22,16 @@ use rand::SeedableRng as _; use std::collections::HashSet; use std::io::Write as _; use std::time::Duration; -use toydb::error::Result; -use toydb::sql::types::{Row, Rows}; -use toydb::{Client, StatementResult}; -fn main() -> Result<()> { +fn main() { let Command { runner, subcommand } = Command::parse(); - match subcommand { + let result = match subcommand { Subcommand::Read(read) => runner.run(read), Subcommand::Write(write) => runner.run(write), Subcommand::Bank(bank) => runner.run(bank), + }; + if let Err(error) = result { + eprintln!("Error: {error}") } } @@ -78,13 +81,12 @@ struct Runner { impl Runner { /// Runs the specified workload. fn run(self, workload: W) -> Result<()> { - let mut rng = rand::rngs::StdRng::seed_from_u64(self.seed); + let mut rng = StdRng::seed_from_u64(self.seed); let mut client = Client::connect(&self.hosts[0])?; // Set up a histogram recording txn latencies as nanoseconds. The // buckets range from 0.001s to 10s. - let mut hist = - hdrhistogram::Histogram::::new_with_bounds(1_000, 10_000_000_000, 3)?.into_sync(); + let mut hist = Histogram::::new_with_bounds(1_000, 10_000_000_000, 3)?.into_sync(); // Prepare the dataset. print!("Preparing initial dataset... "); @@ -177,7 +179,7 @@ impl Runner { } /// A workload. -trait Workload: std::fmt::Display + 'static { +trait Workload: std::fmt::Display { /// A work item. type Item: Send;