-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shanin Roman <[email protected]>
- Loading branch information
Showing
12 changed files
with
289 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#![allow(missing_docs, clippy::restriction)] | ||
|
||
use eyre::Result; | ||
use iroha_core::{block::CommittedBlock, prelude::*}; | ||
use iroha_data_model::prelude::*; | ||
|
||
#[path = "./common.rs"] | ||
mod common; | ||
|
||
use common::*; | ||
|
||
pub struct WsvApplyBlocks { | ||
wsv: WorldStateView, | ||
blocks: Vec<CommittedBlock>, | ||
} | ||
|
||
impl WsvApplyBlocks { | ||
/// Create [`WorldStateView`] and blocks for benchmarking | ||
/// | ||
/// # Errors | ||
/// - Failed to parse [`AccountId`] | ||
/// - Failed to generate [`KeyPair`] | ||
/// - Failed to create instructions for block | ||
pub fn setup() -> Result<Self> { | ||
let domains = 100; | ||
let accounts_per_domain = 1000; | ||
let assets_per_domain = 1000; | ||
let account_id: AccountId = "alice@wonderland".parse()?; | ||
let key_pair = KeyPair::generate()?; | ||
let wsv = build_wsv(&account_id, &key_pair); | ||
|
||
let nth = 100; | ||
let instructions = [ | ||
populate_wsv(domains, accounts_per_domain, assets_per_domain, &account_id), | ||
delete_every_nth(domains, accounts_per_domain, assets_per_domain, nth), | ||
restore_every_nth(domains, accounts_per_domain, assets_per_domain, nth), | ||
] | ||
.into_iter() | ||
.collect::<Result<Vec<_>, _>>()?; | ||
|
||
let blocks = { | ||
// Clone wsv because it will be changed during creation of block | ||
let mut wsv = wsv.clone(); | ||
instructions | ||
.into_iter() | ||
.map(|instructions| { | ||
let block = | ||
create_block(&mut wsv, instructions, account_id.clone(), key_pair.clone()); | ||
wsv.apply_without_execution(&block).map(|_| block) | ||
}) | ||
.collect::<Result<Vec<_>, _>>()? | ||
}; | ||
|
||
Ok(Self { wsv, blocks }) | ||
} | ||
|
||
/// Run benchmark body. | ||
/// | ||
/// # Errors | ||
/// - Not enough blocks | ||
/// - Failed to apply block | ||
/// | ||
/// # Panics | ||
/// If wsv isn't one block ahead of finalized wsv. | ||
pub fn measure(Self { wsv, blocks }: &Self) -> Result<()> { | ||
let mut finalized_wsv = wsv.clone(); | ||
let mut wsv = finalized_wsv.clone(); | ||
|
||
assert_eq!(wsv.height(), 0); | ||
for (block, i) in blocks.iter().zip(1..) { | ||
finalized_wsv = wsv.clone(); | ||
wsv.apply(block)?; | ||
assert_eq!(wsv.height(), i); | ||
assert_eq!(wsv.height(), finalized_wsv.height() + 1); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! Oneshot execution of `apply_blocks` benchmark. | ||
//! Can be useful to profile using flamegraph. | ||
//! | ||
//! ```bash | ||
//! CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --root --release --example apply_blocks | ||
//! ``` | ||
mod apply_blocks; | ||
|
||
use apply_blocks::WsvApplyBlocks; | ||
use iroha_config::base::proxy::Builder; | ||
use iroha_data_model::Level; | ||
use iroha_logger::{Configuration, ConfigurationProxy}; | ||
|
||
fn main() { | ||
let log_config = Configuration { | ||
max_log_level: Level::INFO.into(), | ||
compact_mode: false, | ||
..ConfigurationProxy::default() | ||
.build() | ||
.expect("Default logger config should always build") | ||
}; | ||
// Can't use logger because it's failed to initialize. | ||
#[allow(clippy::print_stderr)] | ||
if let Err(err) = iroha_logger::init(&log_config) { | ||
eprintln!("Failed to initialize logger: {err}"); | ||
} | ||
iroha_logger::info!("Starting..."); | ||
let bench = WsvApplyBlocks::setup().expect("Failed to setup benchmark"); | ||
WsvApplyBlocks::measure(&bench).expect("Failed to execute bnechmark"); | ||
} |
Oops, something went wrong.