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

[WIP] Add approval-voting initial regression tests #3526

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions polkadot/node/core/approval-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ kvdb-memorydb = "0.13.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
log = { workspace = true, default-features = true }
env_logger = "0.9.0"

polkadot-subsystem-bench = { path = "../../subsystem-bench" }

[[bench]]
name = "approval-voting-regression-bench"
path = "benches/approval-voting-regression-bench.rs"
harness = false
required-features = ["subsystem-benchmarks"]

[features]
subsystem-benchmarks = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! approval-voting regression tests
//!
//! Approval Voting benchmark based on Kusama parameters and scale.
//!
//! Subsystems involved:
//! - approval-distribution
//! - approval-voting

use polkadot_subsystem_bench::{
approval::{bench_approvals, prepare_test, ApprovalsOptions},
configuration::TestConfiguration,
usage::BenchmarkUsage,
utils::save_to_file,
};
use std::io::Write;

const BENCH_COUNT: usize = 3;

fn main() -> Result<(), String> {
let mut messages = vec![];

messages.extend(approvals_no_shows()?);
messages.extend(approvals_throughput()?);
messages.extend(approvals_throughput_best_case()?);

if messages.is_empty() {
Ok(())
} else {
eprintln!("{}", messages.join("\n"));
Err("Regressions found".to_string())
}
}

fn test_configuration() -> TestConfiguration {
let mut config = TestConfiguration::default();
config.num_blocks = 3;
config.generate_pov_sizes();

config
}

fn run(test_case: &str, options: ApprovalsOptions) -> Result<BenchmarkUsage, String> {
println!("Benchmarking...");
let usages: Vec<BenchmarkUsage> = (0..BENCH_COUNT)
.map(|n| {
print!("\r[{}{}]", "#".repeat(n), "_".repeat(BENCH_COUNT - n));
std::io::stdout().flush().unwrap();

let (mut env, state) = prepare_test(test_configuration(), options.clone(), false);
env.runtime().block_on(bench_approvals(test_case, &mut env, state))
})
.collect();
println!("\rDone!{}", " ".repeat(BENCH_COUNT));

let average_usage = BenchmarkUsage::average(&usages);
save_to_file(
&format!("charts/availability-recovery-regression-bench-{}.json", test_case),
average_usage.to_chart_json().map_err(|e| e.to_string())?,
)
.map_err(|e| e.to_string())?;
println!("{}", average_usage);

Ok(average_usage)
}

fn approvals_no_shows() -> Result<Vec<String>, String> {
let mut messages = vec![];
let test_case = "approvals_no_shows";
let options = ApprovalsOptions {
coalesce_mean: 3.0,
coalesce_std_dev: 1.0,
enable_assignments_v2: true,
last_considered_tranche: 89,
stop_when_approved: true,
coalesce_tranche_diff: 12,
num_no_shows_per_candidate: 10,
workdir_prefix: "/tmp".to_string(),
};

let usage = run(test_case, options)?;

// We expect no variance for received and sent
// but use 0.001 because we operate with floats
messages.extend(usage.check_network_usage(&[
("Received from peers", 7000.0, 0.001),
("Sent to peers", 8100.0, 0.001),
]));
messages.extend(usage.check_cpu_usage(&[
("approval-distribution", 0.990, 0.05),
("approval-voting", 1.310, 0.05),
]));

Ok(messages)
}

fn approvals_throughput() -> Result<Vec<String>, String> {
let mut messages = vec![];
let test_case = "approvals_throughput";
let options = ApprovalsOptions {
coalesce_mean: 3.0,
coalesce_std_dev: 1.0,
enable_assignments_v2: true,
last_considered_tranche: 89,
stop_when_approved: false,
coalesce_tranche_diff: 12,
num_no_shows_per_candidate: 0,
workdir_prefix: "/tmp".to_string(),
};

let usage = run(test_case, options)?;

// We expect no variance for received and sent
// but use 0.001 because we operate with floats
messages.extend(usage.check_network_usage(&[
("Received from peers", 52850.0, 0.001),
("Sent to peers", 63500.0, 0.001),
]));
messages.extend(usage.check_cpu_usage(&[
("approval-distribution", 8.645, 0.05),
("approval-voting", 11.085, 0.05),
]));

Ok(messages)
}

fn approvals_throughput_best_case() -> Result<Vec<String>, String> {
let mut messages = vec![];
let test_case = "approvals_throughput_best_case";
let options = ApprovalsOptions {
coalesce_mean: 3.0,
coalesce_std_dev: 1.0,
enable_assignments_v2: true,
last_considered_tranche: 89,
stop_when_approved: true,
coalesce_tranche_diff: 12,
num_no_shows_per_candidate: 0,
workdir_prefix: "/tmp".to_string(),
};

let usage = run(test_case, options)?;

// We expect no variance for received and sent
// but use 0.001 because we operate with floats
messages.extend(usage.check_network_usage(&[
("Received from peers", 2950.0, 0.05),
("Sent to peers", 3250.0, 0.05),
]));
messages.extend(usage.check_cpu_usage(&[
("approval-distribution", 0.48, 0.05),
("approval-voting", 0.625, 0.05),
]));

Ok(messages)
}