mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 17:04:18 +01:00
Merge 'stress: Improve progress reporting' from Pekka Enberg
A stress run can take a long time. Improve progress reporting to improve DX. Closes #1796
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
/bin/limbo_stress
|
||||
/bin/limbo_stress --silent
|
||||
|
||||
@@ -322,7 +322,16 @@ fn generate_plan(opts: &Opts) -> Result<Plan, Box<dyn std::error::Error + Send +
|
||||
plan.ddl_statements = ddl_statements;
|
||||
for _ in 0..opts.nr_threads {
|
||||
let mut queries = vec![];
|
||||
for _ in 0..opts.nr_iterations {
|
||||
for i in 0..opts.nr_iterations {
|
||||
if !opts.silent && !opts.verbose {
|
||||
if i % 100 == 0 {
|
||||
print!(
|
||||
"\r{} %",
|
||||
(i as f64 / opts.nr_iterations as f64 * 100.0) as usize
|
||||
);
|
||||
std::io::stdout().flush().unwrap();
|
||||
}
|
||||
}
|
||||
let sql = generate_random_statement(&schema);
|
||||
if !opts.skip_log {
|
||||
writeln!(log_file, "{}", sql)?;
|
||||
@@ -406,8 +415,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
}
|
||||
|
||||
let plan = if opts.load_log {
|
||||
println!("Loading plan from log file...");
|
||||
read_plan_from_log_file(&mut opts)?
|
||||
} else {
|
||||
println!("Generating plan...");
|
||||
generate_plan(&opts)?
|
||||
};
|
||||
|
||||
@@ -428,7 +439,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
|
||||
// Apply each DDL statement individually
|
||||
for stmt in &plan.ddl_statements {
|
||||
println!("executing ddl {}", stmt);
|
||||
if opts.verbose {
|
||||
println!("executing ddl {}", stmt);
|
||||
}
|
||||
if let Err(e) = conn.execute(stmt, ()).await {
|
||||
match e {
|
||||
limbo::Error::SqlExecutionFailure(e) => {
|
||||
@@ -448,9 +461,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
let conn = db.connect()?;
|
||||
println!("\rExecuting queries...");
|
||||
for query_index in 0..nr_iterations {
|
||||
let sql = &plan.queries_per_thread[thread][query_index];
|
||||
println!("executing: {}", sql);
|
||||
if !opts.silent {
|
||||
if opts.verbose {
|
||||
println!("executing query {}", sql);
|
||||
} else {
|
||||
if query_index % 100 == 0 {
|
||||
print!(
|
||||
"\r{:.2} %",
|
||||
(query_index as f64 / nr_iterations as f64 * 100.0)
|
||||
);
|
||||
std::io::stdout().flush().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Err(e) = conn.execute(&sql, ()).await {
|
||||
match e {
|
||||
limbo::Error::SqlExecutionFailure(e) => {
|
||||
|
||||
@@ -4,6 +4,14 @@ use clap::{command, Parser};
|
||||
#[command(name = "limbo_stress")]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Opts {
|
||||
/// Verbose mode
|
||||
#[clap(short = 'v', long, help = "verbose mode")]
|
||||
pub verbose: bool,
|
||||
|
||||
/// Silent mode
|
||||
#[clap(long, help = "silent mode")]
|
||||
pub silent: bool,
|
||||
|
||||
/// Number of threads to run
|
||||
#[clap(short = 't', long, help = "the number of threads", default_value_t = 1)]
|
||||
pub nr_threads: usize,
|
||||
|
||||
Reference in New Issue
Block a user