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

draft: add load_test bench #2242

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions rs/execution_environment/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,19 @@ rust_ic_bench(
"@crate_index//:serde",
] + BENCH_DEPENDENCIES,
)

rust_ic_bench(
name = "load_test_bench",
srcs = ["benches/load_test.rs"],
data = DATA + ["//rs/rust_canisters/canister_creator:canister_creator_canister"],
env = dict(ENV.items() + [
("CANISTER_CREATOR_CANISTER_WASM_PATH", "$(rootpath //rs/rust_canisters/canister_creator:canister_creator_canister)"),
]),
deps = [
# Keep sorted.
"//rs/execution_environment/benches/lib:execution_environment_bench",
"//rs/state_machine_tests",
"//rs/types/base_types",
"//rs/types/types_test_utils",
] + BENCH_DEPENDENCIES,
)
97 changes: 97 additions & 0 deletions rs/execution_environment/benches/load_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use ic_error_types::UserError;
use ic_management_canister_types::{self as ic00, CanisterIdRecord, Payload};
use ic_state_machine_tests::{StateMachine, StateMachineBuilder};
use ic_test_utilities_execution_environment::get_reply;
use ic_types::{
ingress::{IngressState, IngressStatus, WasmResult},
messages::MessageId,
PrincipalId,
};
use std::time::Instant;

const MAX_TICKS: usize = 100;

fn get_result(status: IngressStatus) -> Option<Result<WasmResult, UserError>> {
match status {
IngressStatus::Known {
state: IngressState::Completed(result),
..
} => Some(Ok(result)),
IngressStatus::Known {
state: IngressState::Failed(error),
..
} => Some(Err(error)),
_ => None,
}
}

fn await_ingress_responses(
env: &StateMachine,
message_ids: &[MessageId],
) -> Vec<Result<WasmResult, UserError>> {
let start_time = Instant::now();

for _ in 0..MAX_TICKS {
let results: Vec<_> = message_ids
.iter()
.filter_map(|msg_id| get_result(env.ingress_status(msg_id)))
.collect();

if results.len() == message_ids.len() {
return results;
}

env.tick();
}

panic!(
"Failed to receive ingress responses within {} ticks ({:?} elapsed)",
MAX_TICKS,
start_time.elapsed()
);
}

fn main() {
println!("Starting the canister creation process...");

const CANISTERS_TO_CREATE: usize = 1_000;
let env = StateMachineBuilder::default().build();

let start = std::time::Instant::now();
let message_ids: Vec<_> = (0..CANISTERS_TO_CREATE)
.map(|_| {
env.send_ingress(
PrincipalId::new_anonymous(),
ic00::IC_00,
ic00::Method::ProvisionalCreateCanisterWithCycles,
ic00::ProvisionalCreateCanisterWithCyclesArgs::new(Some(u128::MAX / 2), None)
.encode(),
)
})
.collect();
println!(
"Sent {} canister creation messages in {:.3} s",
CANISTERS_TO_CREATE,
start.elapsed().as_secs_f64()
);

let start = std::time::Instant::now();
let results = await_ingress_responses(&env, &message_ids);
println!(
"Received {} canister creation responses in {:.3} s",
CANISTERS_TO_CREATE,
start.elapsed().as_secs_f64()
);

let replies: Vec<_> = results.into_iter().map(get_reply).collect();
let canister_ids: Vec<_> = replies
.iter()
.map(|bytes| {
CanisterIdRecord::decode(&bytes[..])
.expect("failed to decode canister ID record")
.get_canister_id()
})
.collect();

println!("Created {} canisters", canister_ids.len());
}
Loading