Full block import benchmark (#5745)

This commit is contained in:
Nikolay Volf
2020-04-23 13:55:57 +03:00
committed by GitHub
parent 624e95b1af
commit 1a41b88430
5 changed files with 49 additions and 13 deletions
+1 -1
View File
@@ -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 {
+30 -11
View File
@@ -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!(
+10
View File
@@ -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,