From fd4e74929a72a1700d82f2bdcdf62e027af236ad Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Wed, 20 Aug 2025 12:56:30 -0300 Subject: [PATCH] Cli option to enable memory IO --- simulator/runner/cli.rs | 6 +++++ simulator/runner/env.rs | 42 +++++++++++++++++++++++++++-------- simulator/runner/memory/io.rs | 6 ++--- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/simulator/runner/cli.rs b/simulator/runner/cli.rs index daa00be38..1db597223 100644 --- a/simulator/runner/cli.rs +++ b/simulator/runner/cli.rs @@ -130,6 +130,12 @@ pub struct SimulatorCLI { default_value_t = false )] pub keep_files: bool, + #[clap( + long, + help = "Use memory IO for complex simulations", + default_value_t = false + )] + pub memory_io: bool, #[clap(long, default_value_t = ProfileType::Default)] /// Profile selector for Simulation run pub profile: ProfileType, diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs index 2a971b597..f66cf967d 100644 --- a/simulator/runner/env.rs +++ b/simulator/runner/env.rs @@ -12,8 +12,9 @@ use sql_generation::model::table::Table; use turso_core::Database; use crate::profiles::Profile; -use crate::runner::io::SimulatorIO; use crate::runner::SimIO; +use crate::runner::io::SimulatorIO; +use crate::runner::memory::io::MemorySimIO; use super::cli::SimulatorCLI; @@ -71,6 +72,7 @@ pub(crate) struct SimulatorEnv { pub(crate) type_: SimulationType, pub(crate) phase: SimulationPhase, pub(crate) tables: SimulatorTables, + pub memory_io: bool, } impl UnwindSafe for SimulatorEnv {} @@ -89,6 +91,7 @@ impl SimulatorEnv { paths: self.paths.clone(), type_: self.type_, phase: self.phase, + memory_io: self.memory_io, profile: self.profile.clone(), } } @@ -100,16 +103,26 @@ impl SimulatorEnv { let latency_prof = &self.profile.io.latency; - let io = Arc::new( - SimulatorIO::new( + let io: Arc = if self.memory_io { + Arc::new(MemorySimIO::new( self.opts.seed, self.opts.page_size, latency_prof.latency_probability, latency_prof.min_tick, latency_prof.max_tick, + )) + } else { + Arc::new( + SimulatorIO::new( + self.opts.seed, + self.opts.page_size, + latency_prof.latency_probability, + latency_prof.min_tick, + latency_prof.max_tick, + ) + .unwrap(), ) - .unwrap(), - ); + }; // Remove existing database file let db_path = self.get_db_path(); @@ -283,16 +296,26 @@ impl SimulatorEnv { let latency_prof = &profile.io.latency; - let io = Arc::new( - SimulatorIO::new( + let io: Arc = if cli_opts.memory_io { + Arc::new(MemorySimIO::new( seed, opts.page_size, latency_prof.latency_probability, latency_prof.min_tick, latency_prof.max_tick, + )) + } else { + Arc::new( + SimulatorIO::new( + seed, + opts.page_size, + latency_prof.latency_probability, + latency_prof.min_tick, + latency_prof.max_tick, + ) + .unwrap(), ) - .unwrap(), - ); + }; let db = match Database::open_file( io.clone(), @@ -320,6 +343,7 @@ impl SimulatorEnv { db: Some(db), type_: simulation_type, phase: SimulationPhase::Test, + memory_io: cli_opts.memory_io, profile: profile.clone(), } } diff --git a/simulator/runner/memory/io.rs b/simulator/runner/memory/io.rs index 03e1ad0e1..e6ac7075e 100644 --- a/simulator/runner/memory/io.rs +++ b/simulator/runner/memory/io.rs @@ -152,12 +152,12 @@ impl MemorySimIO { latency_probability: usize, min_tick: u64, max_tick: u64, - ) -> Result { + ) -> Self { let fault = Cell::new(false); let files = RefCell::new(IndexMap::new()); let rng = RefCell::new(ChaCha8Rng::seed_from_u64(seed)); let nr_run_once_faults = Cell::new(0); - Ok(Self { + Self { callbacks: Arc::new(Mutex::new(Vec::new())), timeouts: Arc::new(Mutex::new(Vec::new())), fault, @@ -172,7 +172,7 @@ impl MemorySimIO { min_tick, max_tick, )), - }) + } } }