Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] #1783: Fixed torii benchmark. #1784

Merged
merged 3 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ iroha_permissions_validators = { version = "=2.0.0-pre.1", path = "../permission
test_network = { version = "=2.0.0-pre.1", path = "../core/test_network" }

color-eyre = "0.5.11"
criterion = "0.3"
criterion = { version = "0.3", features = ["html_reports"] }
tempfile = "3"
tokio = { version = "1.6.0", features = ["rt", "rt-multi-thread"]}

Expand Down
32 changes: 24 additions & 8 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ fn query_requests(criterion: &mut Criterion) {
&configuration.genesis,
configuration.sumeragi.max_instruction_number,
)
.unwrap();
.expect("genesis creation failed");

rt.block_on(peer.start_with_config(genesis, configuration));
thread::sleep(std::time::Duration::from_millis(50));

let mut group = criterion.benchmark_group("query-reqeuests");
let mut group = criterion.benchmark_group("query-requests");
let domain_name = "domain";
let create_domain = RegisterBox::new(IdentifiableBox::Domain(Domain::test(domain_name).into()));
let account_name = "account";
Expand All @@ -59,16 +58,27 @@ fn query_requests(criterion: &mut Criterion) {
IdBox::AssetId(AssetId::new(asset_definition_id, account_id.clone())),
);
let mut client_config = iroha_client::samples::get_client_config(&get_key_pair());

// TODO: We should definitely turn this into type-checked state. `String` is a terrible bodge
appetrosyan marked this conversation as resolved.
Show resolved Hide resolved
client_config.torii_api_url = peer.api_address.clone();
if !client_config.torii_api_url.starts_with("http://") {
client_config.torii_api_url = format!("http://{}", client_config.torii_api_url);
}
if !client_config.torii_telemetry_url.starts_with("http://") {
client_config.torii_telemetry_url = format!("http://{}", client_config.torii_telemetry_url);
}
let mut iroha_client = Client::new(&client_config);
thread::sleep(std::time::Duration::from_millis(5000));
appetrosyan marked this conversation as resolved.
Show resolved Hide resolved

let _ = iroha_client
.submit_all(vec![
create_domain.into(),
create_account.into(),
create_asset.into(),
mint_asset.into(),
])
.expect("Failed to prepare state.");
.expect("Failed to prepare state");

let request = asset::by_account_id(account_id);
thread::sleep(std::time::Duration::from_millis(1500));
let mut success_count = 0;
Expand Down Expand Up @@ -100,6 +110,7 @@ fn query_requests(criterion: &mut Criterion) {
}

fn instruction_submits(criterion: &mut Criterion) {
println!("instruction submits");
let rt = Runtime::test();
let mut peer = <TestPeer>::new().expect("Failed to create peer");
let configuration = get_config(
Expand All @@ -113,10 +124,8 @@ fn instruction_submits(criterion: &mut Criterion) {
&configuration.genesis,
configuration.sumeragi.max_instruction_number,
)
.unwrap();
.expect("failed to create genesis");
rt.block_on(peer.start_with_config(genesis, configuration));
thread::sleep(std::time::Duration::from_millis(50));

let mut group = criterion.benchmark_group("instruction-requests");
let domain_name = "domain";
let create_domain = RegisterBox::new(IdentifiableBox::Domain(Domain::test(domain_name).into()));
Expand All @@ -126,15 +135,22 @@ fn instruction_submits(criterion: &mut Criterion) {
NewAccount::with_signatory(
account_id.clone(),
KeyPair::generate()
.expect("Failed to generate KeyPair.")
.expect("Failed to generate Key-pair.")
.public_key,
)
.into(),
));
let asset_definition_id = AssetDefinitionId::test("xor", domain_name);
let mut client_config = iroha_client::samples::get_client_config(&get_key_pair());
client_config.torii_api_url = peer.api_address.clone();
if !client_config.torii_api_url.starts_with("http://") {
client_config.torii_api_url = format!("http://{}", client_config.torii_api_url);
}
if !client_config.torii_telemetry_url.starts_with("http://") {
client_config.torii_telemetry_url = format!("http://{}", client_config.torii_telemetry_url);
}
let mut iroha_client = Client::new(&client_config);
thread::sleep(std::time::Duration::from_millis(5000));
appetrosyan marked this conversation as resolved.
Show resolved Hide resolved
let _ = iroha_client
.submit_all(vec![create_domain.into(), create_account.into()])
.expect("Failed to create role.");
Expand Down
58 changes: 58 additions & 0 deletions client/tests/million_accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#![allow(missing_docs, clippy::pedantic, clippy::restriction)]

use iroha_core::{
genesis::{GenesisNetwork, GenesisNetworkTrait, GenesisTransaction, RawGenesisBlock},
prelude::*,
samples::get_config,
};
use test_network::{get_key_pair, Peer as TestPeer, TestRuntime};
use tokio::runtime::Runtime;

fn generate_accounts(num: u32) -> Vec<GenesisTransaction> {
let mut ret = Vec::with_capacity(usize::try_from(num).expect("panic"));
for _i in 0..num {
ret.push(
GenesisTransaction::new(
&format!("Alice-{}", num),
&format!("wonderland-{}", num),
&PublicKey::default(),
)
.expect("Failed to create Genesis"),
);
}
ret
}

fn generate_genesis(num: u32) -> RawGenesisBlock {
let transactions = generate_accounts(num);
RawGenesisBlock { transactions }
}

/// Generate genesis with a given number of accounts and try to submit
/// it. This will not check if the accounts are created, and is only
/// needed for you to be able to monitor the RAM usage using an
/// external program like `htop`.
#[test]
#[ignore = "Very slow. run with `cargo test --release` to significantly improve performance."]
fn create_million_accounts() {
let mut peer = <TestPeer>::new().expect("Failed to create peer");
let configuration = get_config(
std::iter::once(peer.id.clone()).collect(),
Some(get_key_pair()),
);
let rt = Runtime::test();
let genesis = GenesisNetwork::from_configuration(
true,
generate_genesis(1000000),
&configuration.genesis,
configuration.sumeragi.max_instruction_number,
)
.expect("genesis creation failed");

// This only submits the genesis. It doesn't check if the accounts
// are created, because that check is 1) not needed for what the
// test is actually for, 2) incredibly slow, making this sort of
// test impractical, 3) very likely to overflow memory on systems
// with less than 16GiB of free memory.
rt.block_on(peer.start_with_config(genesis, configuration));
appetrosyan marked this conversation as resolved.
Show resolved Hide resolved
}