Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Storage benchmarking #10897

Merged
merged 33 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6919702
WIP
ggwpez Feb 5, 2022
f09e4fb
WIP: DB benchmarking
ggwpez Feb 21, 2022
03a6d49
WIP
ggwpez Feb 23, 2022
b9e78cd
WIP
ggwpez Feb 23, 2022
b94b18c
Simplify code
ggwpez Feb 23, 2022
940c116
Remove old files
ggwpez Feb 23, 2022
b4df3f0
Merge remote-tracking branch 'origin/master' into oty-client-bench
ggwpez Feb 23, 2022
a1d08a2
Remove old files
ggwpez Feb 23, 2022
e98560f
Merge remote-tracking branch 'origin/master' into oty-client-bench
ggwpez Feb 23, 2022
d2cea7f
Minimize changes
ggwpez Feb 23, 2022
a0c9eb8
Add license
ggwpez Feb 23, 2022
6233cfd
Remove dependencies
ggwpez Feb 23, 2022
9187dd2
Extend template
ggwpez Feb 24, 2022
18d4e9b
Linter
ggwpez Feb 24, 2022
4e61a57
Linter
ggwpez Feb 24, 2022
84132f6
Beauty fixes
ggwpez Feb 24, 2022
861e4db
Remove default
ggwpez Feb 24, 2022
c66b01b
Add feature
ggwpez Feb 24, 2022
2e8d724
Remove seed
ggwpez Feb 24, 2022
0c9cbcf
CI wakeup
ggwpez Feb 24, 2022
2bd626e
Fmt
ggwpez Feb 24, 2022
311a2b0
Review fixes
ggwpez Feb 25, 2022
932c9df
Adding doc
ggwpez Feb 25, 2022
872871f
Adding doc
ggwpez Feb 25, 2022
8e08d37
Improve template
ggwpez Feb 25, 2022
35203ea
Do not expose columns
ggwpez Feb 25, 2022
a8dd207
Fix ColumnId
ggwpez Feb 25, 2022
13b1d38
Nicer template prints
ggwpez Feb 25, 2022
661b9f8
Cleanup
ggwpez Feb 25, 2022
776f699
Fix json path
ggwpez Feb 25, 2022
184d719
Merge remote-tracking branch 'origin/master' into oty-client-bench
ggwpez Feb 25, 2022
6496220
Simplify `bench_write` logic
ggwpez Feb 25, 2022
02ce52c
Invert tx before the second commit
ggwpez Feb 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -185,7 +185,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