Skip to content

Commit

Permalink
bin: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jul 21, 2024
1 parent fdc960c commit e04488c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/bin/toydb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
};

Expand Down
2 changes: 1 addition & 1 deletion src/bin/toydump.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
34 changes: 18 additions & 16 deletions src/bin/workload.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
//! 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;
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}")
}
}

Expand Down Expand Up @@ -78,13 +81,12 @@ struct Runner {
impl Runner {
/// Runs the specified workload.
fn run<W: Workload>(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::<u32>::new_with_bounds(1_000, 10_000_000_000, 3)?.into_sync();
let mut hist = Histogram::<u32>::new_with_bounds(1_000, 10_000_000_000, 3)?.into_sync();

// Prepare the dataset.
print!("Preparing initial dataset... ");
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit e04488c

Please sign in to comment.