properly handle different block content (#6007)

This commit is contained in:
Nikolay Volf
2020-05-13 23:48:28 +03:00
committed by GitHub
parent 074d80f519
commit 91d93be9b5
3 changed files with 56 additions and 46 deletions
+12 -12
View File
@@ -50,19 +50,19 @@ pub enum SizeType {
#[display(fmt = "full")]
Full,
#[display(fmt = "custom")]
Custom,
Custom(usize),
}
impl SizeType {
pub fn transactions(&self) -> usize {
pub fn transactions(&self) -> Option<usize> {
match self {
SizeType::Empty => 0,
SizeType::Small => 10,
SizeType::Medium => 100,
SizeType::Large => 500,
SizeType::Full => 4000,
SizeType::Empty => Some(0),
SizeType::Small => Some(10),
SizeType::Medium => Some(100),
SizeType::Large => Some(500),
SizeType::Full => None,
// Custom SizeType will use the `--transactions` input parameter
SizeType::Custom => 0,
SizeType::Custom(val) => Some(*val),
}
}
}
@@ -97,9 +97,9 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription {
}
match self.block_type {
BlockType::RandomTransfersKeepAlive(_) => path.push("transfer_keep_alive"),
BlockType::RandomTransfersReaping(_) => path.push("transfer_reaping"),
BlockType::Noop(_) => path.push("noop"),
BlockType::RandomTransfersKeepAlive => path.push("transfer_keep_alive"),
BlockType::RandomTransfersReaping => path.push("transfer_reaping"),
BlockType::Noop => path.push("noop"),
}
match self.database_type {
@@ -119,7 +119,7 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription {
50_000,
self.key_types
);
let block = bench_db.generate_block(self.block_type);
let block = bench_db.generate_block(self.block_type.to_content(self.size.transactions()));
Box::new(ImportBenchmark {
database: bench_db,
block,
+6 -10
View File
@@ -79,19 +79,15 @@ fn main() {
SizeType::Medium,
SizeType::Large,
SizeType::Full,
SizeType::Custom,
SizeType::Custom(opt.transactions.unwrap_or(0)),
].iter() {
let txs = match size {
SizeType::Custom => opt.transactions.unwrap_or(0),
_ => size.transactions()
};
for block_type in [
BlockType::RandomTransfersKeepAlive(txs),
BlockType::RandomTransfersReaping(txs),
BlockType::Noop(txs),
BlockType::RandomTransfersKeepAlive,
BlockType::RandomTransfersReaping,
BlockType::Noop,
].iter() {
for database_type in [BenchDataBaseType::RocksDb, BenchDataBaseType::ParityDb].iter() {
import_benchmarks.push((profile, size, block_type.clone(), database_type));
import_benchmarks.push((profile, size.clone(), block_type.clone(), database_type));
}
}
}
@@ -102,7 +98,7 @@ fn main() {
ImportBenchmarkDescription {
profile: *profile,
key_types: KeyTypes::Sr25519,
size: *size,
size: size,
block_type: block_type,
database_type: *database_type,
},
+38 -24
View File
@@ -132,11 +132,36 @@ impl Clone for BenchDb {
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum BlockType {
/// Bunch of random transfers.
RandomTransfersKeepAlive(usize),
RandomTransfersKeepAlive,
/// Bunch of random transfers that drain all of the source balance.
RandomTransfersReaping(usize),
RandomTransfersReaping,
/// Bunch of "no-op" calls.
Noop(usize),
Noop,
}
impl BlockType {
/// Create block content description with specified number of transactions.
pub fn to_content(self, size: Option<usize>) -> BlockContent {
BlockContent {
block_type: self,
size: size,
}
}
}
/// Content of the generated block.
pub struct BlockContent {
block_type: BlockType,
size: Option<usize>,
}
impl BlockContent {
fn iter_while(&self, mut f: impl FnMut(usize) -> bool) {
match self.size {
Some(v) => { for i in 0..v { if !f(i) { break; }}}
None => { for i in 0.. { if !f(i) { break; }}}
}
}
}
/// Type of backend database.
@@ -162,15 +187,6 @@ impl DatabaseType {
}
}
impl BlockType {
/// Number of transactions for this block type.
pub fn transactions(&self) -> usize {
match self {
Self::RandomTransfersKeepAlive(v) | Self::RandomTransfersReaping(v) | Self::Noop(v) => *v,
}
}
}
/// Benchmarking task executor.
///
/// Uses multiple threads as the regular executable.
@@ -271,7 +287,7 @@ impl BenchDb {
}
/// Generate new block using this database.
pub fn generate_block(&mut self, block_type: BlockType) -> Block {
pub fn generate_block(&mut self, content: BlockContent) -> Block {
let (client, _backend) = Self::bench_client(
self.database_type,
self.directory_guard.path(),
@@ -310,10 +326,8 @@ impl BenchDb {
block.push(extrinsic).expect("Push inherent failed");
}
let mut iteration = 0;
let start = std::time::Instant::now();
for _ in 0..block_type.transactions() {
content.iter_while(|iteration| {
let sender = self.keyring.at(iteration);
let receiver = get_account_id_from_seed::<sr25519::Public>(
&format!("random-user//{}", iteration)
@@ -322,8 +336,8 @@ impl BenchDb {
let signed = self.keyring.sign(
CheckedExtrinsic {
signed: Some((sender, signed_extra(0, node_runtime::ExistentialDeposit::get() + 1))),
function: match block_type {
BlockType::RandomTransfersKeepAlive(_) => {
function: match content.block_type {
BlockType::RandomTransfersKeepAlive => {
Call::Balances(
BalancesCall::transfer_keep_alive(
pallet_indices::address::Address::Id(receiver),
@@ -331,7 +345,7 @@ impl BenchDb {
)
)
},
BlockType::RandomTransfersReaping(_) => {
BlockType::RandomTransfersReaping => {
Call::Balances(
BalancesCall::transfer(
pallet_indices::address::Address::Id(receiver),
@@ -341,7 +355,7 @@ impl BenchDb {
)
)
},
BlockType::Noop(_) => {
BlockType::Noop => {
Call::System(
SystemCall::remark(Vec::new())
)
@@ -361,13 +375,13 @@ impl BenchDb {
Err(sp_blockchain::Error::ApplyExtrinsicFailed(
sp_blockchain::ApplyExtrinsicFailed::Validity(e)
)) if e.exhausted_resources() => {
break;
return false;
},
Err(err) => panic!("Error pushing transaction: {:?}", err),
Ok(_) => {},
Ok(_) => true,
}
iteration += 1;
}
});
let block = block.build().expect("Block build failed").block;
log::info!(