core/throughput: Add per transaction think time support

This commit is contained in:
Pekka Enberg
2025-09-13 13:02:43 +03:00
parent a7e34f1551
commit 8dc2e738a4
2 changed files with 27 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ use clap::Parser;
use rusqlite::{Connection, Result};
use std::sync::{Arc, Barrier};
use std::thread;
use std::time::Instant;
use std::time::{Duration, Instant};
#[derive(Parser)]
#[command(name = "write-throughput")]
@@ -16,6 +16,13 @@ struct Args {
#[arg(short = 'i', long = "iterations", default_value = "10")]
iterations: usize,
#[arg(
long = "think",
default_value = "0",
help = "Per transaction think time (ms)"
)]
think: u64,
}
fn main() -> Result<()> {
@@ -54,6 +61,7 @@ fn main() -> Result<()> {
args.batch_size,
args.iterations,
barrier,
args.think,
)
});
@@ -118,11 +126,12 @@ fn worker_thread(
batch_size: usize,
iterations: usize,
start_barrier: Arc<Barrier>,
think_ms: u64,
) -> Result<u64> {
let conn = Connection::open(&db_path)?;
conn.busy_timeout(std::time::Duration::from_secs(30))?;
let mut stmt = conn.prepare("INSERT INTO test_table (id, data) VALUES (?, ?)")?;
start_barrier.wait();
@@ -138,7 +147,9 @@ fn worker_thread(
stmt.execute([&id.to_string(), &format!("data_{}", id)])?;
total_inserts += 1;
}
if think_ms > 0 {
thread::sleep(std::time::Duration::from_millis(think_ms));
}
conn.execute("COMMIT", [])?;
}

View File

@@ -26,6 +26,13 @@ struct Args {
#[arg(short = 'm', long = "mode", default_value = "legacy")]
mode: TransactionMode,
#[arg(
long = "think",
default_value = "0",
help = "Per transaction think time (ms)"
)]
think: u64,
}
#[tokio::main]
@@ -66,6 +73,7 @@ async fn main() -> Result<()> {
args.iterations,
barrier,
args.mode,
args.think,
))
});
@@ -139,6 +147,7 @@ async fn worker_thread(
iterations: usize,
start_barrier: Arc<Barrier>,
mode: TransactionMode,
think_ms: u64,
) -> Result<u64> {
let conn = db.connect()?;
@@ -168,6 +177,10 @@ async fn worker_thread(
total_inserts += 1;
}
if think_ms > 0 {
tokio::time::sleep(tokio::time::Duration::from_millis(think_ms)).await;
}
conn.execute("COMMIT", ()).await?;
}