mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-03 23:34:24 +01:00
Cli option to enable memory IO
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<dyn SimIO> = 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<dyn SimIO> = 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(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,12 +152,12 @@ impl MemorySimIO {
|
||||
latency_probability: usize,
|
||||
min_tick: u64,
|
||||
max_tick: u64,
|
||||
) -> Result<Self> {
|
||||
) -> 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,
|
||||
)),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user