Skip to content

Commit a1d81e6

Browse files
starknet_committer_cli: add option for cache on mdbx storage (#9747)
Signed-off-by: Dori Medini <[email protected]>
1 parent 1c02058 commit a1d81e6

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

crates/starknet_committer/src/block_committer/timing_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl TimeMeasurement {
8888
.expect("stop_measurement called before start_measurement")
8989
.elapsed();
9090
info!(
91-
"Time elapsed for iteration {}: {} milliseconds",
91+
"Time elapsed for {action:?} in iteration {}: {} milliseconds",
9292
self.n_results(),
9393
duration.as_millis()
9494
);

crates/starknet_committer_cli/src/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub async fn run_storage_benchmark<S: Storage>(
5050
.expect("Failed to commit the given block.");
5151
time_measurement.start_measurement(Action::Write);
5252
let n_new_facts = filled_forest.write_to_storage(&mut storage);
53+
info!("Written {n_new_facts} new facts to storage");
5354
time_measurement.stop_measurement(None, Action::Write);
5455

5556
time_measurement.stop_measurement(Some(n_new_facts), Action::EndToEnd);

crates/starknet_committer_cli/src/main.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::fs;
2+
use std::num::NonZeroUsize;
23
use std::path::Path;
34

45
use apollo_infra_utils::tracing_utils::{configure_tracing, modify_log_level};
56
use clap::{Args, Parser, Subcommand};
67
use starknet_committer_cli::commands::run_storage_benchmark;
7-
use starknet_patricia_storage::map_storage::MapStorage;
8+
use starknet_patricia_storage::map_storage::{CachedStorage, MapStorage};
89
use starknet_patricia_storage::mdbx_storage::MdbxStorage;
910
use tracing::info;
1011
use tracing::level_filters::LevelFilter;
@@ -21,6 +22,7 @@ pub struct CommitterCliCommand {
2122
pub enum StorageType {
2223
MapStorage,
2324
Mdbx,
25+
CachedMdbx,
2426
}
2527

2628
const DEFAULT_DATA_PATH: &str = "/tmp/committer_storage_benchmark";
@@ -38,8 +40,11 @@ struct StorageArgs {
3840
n_diffs: usize,
3941
/// Storage impl to use. Note that MapStorage isn't persisted in the file system, so
4042
/// checkpointing is ignored.
41-
#[clap(long, default_value = "mdbx")]
43+
#[clap(long, default_value = "cached-mdbx")]
4244
storage_type: StorageType,
45+
/// If using cached storage, the size of the cache.
46+
#[clap(long, default_value = "1000000")]
47+
cache_size: usize,
4348
#[clap(long, default_value = "1000")]
4449
checkpoint_interval: usize,
4550
#[clap(long, default_value = "warn")]
@@ -79,6 +84,7 @@ pub async fn run_committer_cli(
7984
n_iterations,
8085
n_diffs,
8186
storage_type,
87+
cache_size,
8288
checkpoint_interval,
8389
log_level,
8490
data_path,
@@ -123,6 +129,25 @@ pub async fn run_committer_cli(
123129
)
124130
.await;
125131
}
132+
StorageType::CachedMdbx => {
133+
let storage_path = storage_path
134+
.unwrap_or_else(|| format!("{data_path}/storage/{storage_type:?}"));
135+
fs::create_dir_all(&storage_path).expect("Failed to create storage directory.");
136+
let storage = CachedStorage::new(
137+
MdbxStorage::open(Path::new(&storage_path)).unwrap(),
138+
NonZeroUsize::new(cache_size).unwrap(),
139+
);
140+
run_storage_benchmark(
141+
seed,
142+
n_iterations,
143+
n_diffs,
144+
&output_dir,
145+
Some(&checkpoint_dir),
146+
storage,
147+
checkpoint_interval,
148+
)
149+
.await;
150+
}
126151
}
127152
}
128153
}

0 commit comments

Comments
 (0)