Skip to content

Commit

Permalink
Storage benchmarking (paritytech#10897)
Browse files Browse the repository at this point in the history
* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP: DB benchmarking

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Simplify code

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove old files

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove old files

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Minimize changes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add license

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove dependencies

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Extend template

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Linter

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Linter

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Beauty fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove default

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add feature

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove seed

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* CI wakeup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Review fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Adding doc

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Adding doc

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Improve template

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Do not expose columns

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix ColumnId

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Nicer template prints

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix json path

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Simplify `bench_write` logic

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Invert tx before the second commit

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez authored and ark0f committed Feb 27, 2023
1 parent 54d5e6d commit eb7032f
Show file tree
Hide file tree
Showing 19 changed files with 917 additions and 11 deletions.
31 changes: 27 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub enum Subcommand {
#[clap(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Sub command for benchmarking the storage speed.
#[clap(name = "benchmark-storage", about = "Benchmark storage speed.")]
BenchmarkStorage(frame_benchmarking_cli::StorageCmd),

/// Try some command against runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),
Expand Down
16 changes: 16 additions & 0 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ pub fn run() -> Result<()> {
You can enable it with `--features runtime-benchmarks`."
.into())
},
Some(Subcommand::BenchmarkStorage(cmd)) => {
if !cfg!(feature = "runtime-benchmarks") {
return Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into())
}

let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, backend, .. } = new_partial(&config)?;
let db = backend.expose_db();
let storage = backend.expose_storage();

Ok((cmd.run(config, client, db, storage), task_manager))
})
},
Some(Subcommand::Key(cmd)) => cmd.run(&cli),
Some(Subcommand::Sign(cmd)) => cmd.run(),
Some(Subcommand::Verify(cmd)) => cmd.run(),
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Into<sc_service::config::RpcMethods> for RpcMethods {
}

/// Database backend
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum Database {
/// Facebooks RocksDB
RocksDb,
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/params/database_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use clap::Args;
use sc_service::TransactionStorageMode;

/// Parameters for block import.
#[derive(Debug, Clone, Args)]
#[derive(Debug, Clone, PartialEq, Args)]
pub struct DatabaseParams {
/// Select database backend to use.
#[clap(
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/params/pruning_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use clap::Args;
use sc_service::{KeepBlocks, PruningMode, Role};

/// Parameters to define the pruning mode
#[derive(Debug, Clone, Args)]
#[derive(Debug, Clone, PartialEq, Args)]
pub struct PruningParams {
/// Specify the state pruning mode, a number of blocks to keep or 'archive'.
///
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/params/shared_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sc_service::config::BasePath;
use std::path::PathBuf;

/// Shared parameters used by all `CoreParams`.
#[derive(Debug, Clone, Args)]
#[derive(Debug, Clone, PartialEq, Args)]
pub struct SharedParams {
/// Specify the chain specification.
///
Expand Down
1 change: 1 addition & 0 deletions client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ tempfile = "3"
[features]
default = []
test-helpers = []
runtime-benchmarks = []
with-kvdb-rocksdb = ["kvdb-rocksdb"]
with-parity-db = ["parity-db"]
20 changes: 19 additions & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const DEFAULT_CHILD_RATIO: (usize, usize) = (1, 10);
pub type DbState<B> =
sp_state_machine::TrieBackend<Arc<dyn sp_state_machine::Storage<HashFor<B>>>, HashFor<B>>;

const DB_HASH_LEN: usize = 32;
/// Length of a [`DbHash`].
pub const DB_HASH_LEN: usize = 32;
/// Hash type that this backend uses for the database.
pub type DbHash = sp_core::H256;

Expand Down Expand Up @@ -1050,6 +1051,23 @@ impl<Block: BlockT> Backend<Block> {
Self::new(db_setting, canonicalization_delay).expect("failed to create test-db")
}

/// Expose the Database that is used by this backend.
/// The second argument is the Column that stores the State.
///
/// Should only be needed for benchmarking.
#[cfg(any(feature = "runtime-benchmarks"))]
pub fn expose_db(&self) -> (Arc<dyn sp_database::Database<DbHash>>, sp_database::ColumnId) {
(self.storage.db.clone(), columns::STATE)
}

/// Expose the Storage that is used by this backend.
///
/// Should only be needed for benchmarking.
#[cfg(any(feature = "runtime-benchmarks"))]
pub fn expose_storage(&self) -> Arc<dyn sp_state_machine::Storage<HashFor<Block>>> {
self.storage.clone()
}

fn from_database(
db: Arc<dyn Database<DbHash>>,
canonicalization_delay: u64,
Expand Down
17 changes: 16 additions & 1 deletion utils/frame/benchmarking-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ frame-benchmarking = { version = "4.0.0-dev", path = "../../../frame/benchmarkin
frame-support = { version = "4.0.0-dev", path = "../../../frame/support" }
sp-core = { version = "5.0.0", path = "../../../primitives/core" }
sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" }
sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" }
sc-cli = { version = "0.10.0-dev", path = "../../../client/cli" }
sc-client-db = { version = "0.10.0-dev", path = "../../../client/db" }
sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" }

sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" }
sp-externalities = { version = "0.11.0", path = "../../../primitives/externalities" }
sp-database = { version = "4.0.0-dev", path = "../../../primitives/database" }
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
sp-keystore = { version = "0.11.0", path = "../../../primitives/keystore" }
sp-storage = { version = "5.0.0", path = "../../../primitives/storage" }
sp-runtime = { version = "5.0.0", path = "../../../primitives/runtime" }
sp-std = { version = "4.0.0", default-features = false, path = "../../../primitives/std" }
sp-state-machine = { version = "0.11.0", path = "../../../primitives/state-machine" }
sp-trie = { version = "5.0.0", path = "../../../primitives/trie" }
codec = { version = "3.0.0", package = "parity-scale-codec" }
clap = { version = "3.0", features = ["derive"] }
chrono = "0.4"
Expand All @@ -33,7 +41,14 @@ handlebars = "4.1.6"
Inflector = "0.11.4"
linked-hash-map = "0.5.4"
log = "0.4.8"
itertools = "0.10.3"
serde_nanos = "0.1.2"
kvdb = "0.11.0"
hash-db = "0.15.2"
hex = "0.4.3"
memory-db = "0.29.0"
rand = { version = "0.8.4", features = ["small_rng"] }

[features]
default = ["db"]
default = ["db", "sc-client-db/runtime-benchmarks"]
db = ["sc-client-db/with-kvdb-rocksdb", "sc-client-db/with-parity-db"]
3 changes: 3 additions & 0 deletions utils/frame/benchmarking-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
// limitations under the License.

mod command;
mod storage;
mod writer;

use sc_cli::{ExecutionStrategy, WasmExecutionMethod};
use std::{fmt::Debug, path::PathBuf};

pub use storage::StorageCmd;

// Add a more relaxed parsing for pallet names by allowing pallet directory names with `-` to be
// used like crate names with `_`
fn parse_pallet_name(pallet: &str) -> String {
Expand Down
Loading

0 comments on commit eb7032f

Please sign in to comment.