From 8dc2e738a45d2889ef57efd3dc010db7e5366dd5 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sat, 13 Sep 2025 13:02:43 +0300 Subject: [PATCH] core/throughput: Add per transaction think time support --- perf/throughput/rusqlite/src/main.rs | 17 ++++++++++++++--- perf/throughput/turso/src/main.rs | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/perf/throughput/rusqlite/src/main.rs b/perf/throughput/rusqlite/src/main.rs index 45226a589..103958c71 100644 --- a/perf/throughput/rusqlite/src/main.rs +++ b/perf/throughput/rusqlite/src/main.rs @@ -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, + think_ms: u64, ) -> Result { 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", [])?; } diff --git a/perf/throughput/turso/src/main.rs b/perf/throughput/turso/src/main.rs index c19513022..e08b1610c 100644 --- a/perf/throughput/turso/src/main.rs +++ b/perf/throughput/turso/src/main.rs @@ -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, mode: TransactionMode, + think_ms: u64, ) -> Result { 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?; }