From 1a41b88430f380feff76fc3fe384231a73855d7b Mon Sep 17 00:00:00 2001 From: Nikolay Volf <nikvolf@gmail.com> Date: Thu, 23 Apr 2020 13:55:57 +0300 Subject: [PATCH] Full block import benchmark (#5745) --- substrate/bin/node/bench/Cargo.toml | 2 +- substrate/bin/node/bench/src/core.rs | 2 +- substrate/bin/node/bench/src/import.rs | 41 ++++++++++++++----- substrate/bin/node/bench/src/main.rs | 10 +++++ substrate/primitives/io/src/batch_verifier.rs | 7 ++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/substrate/bin/node/bench/Cargo.toml b/substrate/bin/node/bench/Cargo.toml index d8f23f21049..e5738397556 100644 --- a/substrate/bin/node/bench/Cargo.toml +++ b/substrate/bin/node/bench/Cargo.toml @@ -15,7 +15,7 @@ node-testing = { version = "2.0.0-dev", path = "../testing" } sc-cli = { version = "0.8.0-dev", path = "../../../client/cli" } sc-client-api = { version = "2.0.0-dev", path = "../../../client/api/" } sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" } -sp-state-machine = { version = "0.8.0-alpha.5", path = "../../../primitives/state-machine" } +sp-state-machine = { version = "0.8.0-dev", path = "../../../primitives/state-machine" } serde = "1.0.101" serde_json = "1.0.41" structopt = "0.3" diff --git a/substrate/bin/node/bench/src/core.rs b/substrate/bin/node/bench/src/core.rs index 9105fcbd017..7a345f7a5bd 100644 --- a/substrate/bin/node/bench/src/core.rs +++ b/substrate/bin/node/bench/src/core.rs @@ -58,7 +58,7 @@ pub struct BenchmarkOutput { average: u64, } -struct NsFormatter(u64); +pub struct NsFormatter(pub u64); impl fmt::Display for NsFormatter { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/substrate/bin/node/bench/src/import.rs b/substrate/bin/node/bench/src/import.rs index 2dea292ab00..a6e4eb2514e 100644 --- a/substrate/bin/node/bench/src/import.rs +++ b/substrate/bin/node/bench/src/import.rs @@ -37,8 +37,17 @@ use sp_runtime::generic::BlockId; use crate::core::{self, Path, Mode}; -#[derive(Clone, Copy, Debug)] -pub enum SizeType { Small, Medium, Large } +#[derive(Clone, Copy, Debug, derive_more::Display)] +pub enum SizeType { + #[display(fmt = "small")] + Small, + #[display(fmt = "medium")] + Medium, + #[display(fmt = "large")] + Large, + #[display(fmt = "full")] + Full, +} impl SizeType { fn transactions(&self) -> usize { @@ -46,6 +55,7 @@ impl SizeType { SizeType::Small => 10, SizeType::Medium => 100, SizeType::Large => 500, + SizeType::Full => 4000, } } } @@ -77,18 +87,17 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription { KeyTypes::Ed25519 => path.push("ed25519"), } - match self.size { - SizeType::Small => path.push("small"), - SizeType::Medium => path.push("medium"), - SizeType::Large => path.push("large"), - } + path.push(&format!("{}", self.size)); path } fn setup(self: Box<Self>) -> Box<dyn core::Benchmark> { let profile = self.profile; - let mut bench_db = BenchDb::with_key_types(self.size.transactions(), self.key_types); + let mut bench_db = BenchDb::with_key_types( + 50_000, + self.key_types + ); let block = bench_db.generate_block(BlockType::RandomTransfers(self.size.transactions())); Box::new(ImportBenchmark { database: bench_db, @@ -99,8 +108,14 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription { fn name(&self) -> Cow<'static, str> { match self.profile { - Profile::Wasm => "Import benchmark (random transfers, wasm)".into(), - Profile::Native => "Import benchmark (random transfers, native)".into(), + Profile::Wasm => format!( + "Import benchmark (random transfers, wasm, {} block)", + self.size, + ).into(), + Profile::Native => format!( + "Import benchmark (random transfers, native, {} block)", + self.size, + ).into(), } } } @@ -113,12 +128,16 @@ impl core::Benchmark for ImportBenchmark { .expect("Failed to get runtime version") .spec_version; + if mode == Mode::Profile { + std::thread::park_timeout(std::time::Duration::from_secs(3)); + } + let start = std::time::Instant::now(); context.import_block(self.block.clone()); let elapsed = start.elapsed(); if mode == Mode::Profile { - std::thread::park_timeout(std::time::Duration::from_secs(2)); + std::thread::park_timeout(std::time::Duration::from_secs(1)); } log::info!( diff --git a/substrate/bin/node/bench/src/main.rs b/substrate/bin/node/bench/src/main.rs index c821746b33a..48f1213d621 100644 --- a/substrate/bin/node/bench/src/main.rs +++ b/substrate/bin/node/bench/src/main.rs @@ -76,6 +76,16 @@ fn main() { key_types: KeyTypes::Ed25519, size: SizeType::Medium, }, + ImportBenchmarkDescription { + profile: Profile::Wasm, + key_types: KeyTypes::Sr25519, + size: SizeType::Full, + }, + ImportBenchmarkDescription { + profile: Profile::Native, + key_types: KeyTypes::Sr25519, + size: SizeType::Full, + }, size in [SizeType::Small, SizeType::Large] => ImportBenchmarkDescription { profile: Profile::Native, diff --git a/substrate/primitives/io/src/batch_verifier.rs b/substrate/primitives/io/src/batch_verifier.rs index a23b8fcbc2d..82ce0b04ef0 100644 --- a/substrate/primitives/io/src/batch_verifier.rs +++ b/substrate/primitives/io/src/batch_verifier.rs @@ -117,6 +117,7 @@ impl BatchVerifier { use std::sync::{Mutex, Condvar}; let pending = std::mem::replace(&mut self.pending_tasks, vec![]); + let started = std::time::Instant::now(); log::trace!( target: "runtime", @@ -158,6 +159,12 @@ impl BatchVerifier { let _ = cond_var.wait(mtx).expect("Waiting can only fail when the mutex waited on is poisoned; qed"); } + log::trace!( + target: "runtime", + "Finalization of batch verification took {} ms", + started.elapsed().as_millis(), + ); + !self.invalid.swap(false, AtomicOrdering::Relaxed) } } -- GitLab