mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 14:01:06 +00:00
Add subsystems regression tests to CI (#3527)
Fixes https://github.com/paritytech/polkadot-sdk/issues/3530
This commit is contained in:
+24
-53
@@ -26,13 +26,9 @@
|
||||
use polkadot_subsystem_bench::{
|
||||
availability::{benchmark_availability_write, prepare_test, TestDataAvailability, TestState},
|
||||
configuration::TestConfiguration,
|
||||
usage::BenchmarkUsage,
|
||||
utils::{warm_up_and_benchmark, WarmUpOptions},
|
||||
};
|
||||
|
||||
const BENCH_COUNT: usize = 3;
|
||||
const WARM_UP_COUNT: usize = 30;
|
||||
const WARM_UP_PRECISION: f64 = 0.01;
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
let mut messages = vec![];
|
||||
let mut config = TestConfiguration::default();
|
||||
@@ -41,17 +37,33 @@ fn main() -> Result<(), String> {
|
||||
config.num_blocks = 3;
|
||||
config.generate_pov_sizes();
|
||||
|
||||
warm_up(config.clone())?;
|
||||
let usage = benchmark(config.clone());
|
||||
let usage = warm_up_and_benchmark(
|
||||
WarmUpOptions::new(&[
|
||||
"availability-distribution",
|
||||
"bitfield-distribution",
|
||||
"availability-store",
|
||||
]),
|
||||
|| {
|
||||
let mut state = TestState::new(&config);
|
||||
let (mut env, _protocol_config) =
|
||||
prepare_test(config.clone(), &mut state, TestDataAvailability::Write, false);
|
||||
env.runtime().block_on(benchmark_availability_write(
|
||||
"data_availability_write",
|
||||
&mut env,
|
||||
state,
|
||||
))
|
||||
},
|
||||
)?;
|
||||
println!("{}", usage);
|
||||
|
||||
messages.extend(usage.check_network_usage(&[
|
||||
("Received from peers", 4330.0, 0.05),
|
||||
("Sent to peers", 15900.0, 0.05),
|
||||
("Received from peers", 443.333, 0.05),
|
||||
("Sent to peers", 21818.555, 0.05),
|
||||
]));
|
||||
messages.extend(usage.check_cpu_usage(&[
|
||||
("availability-distribution", 0.025, 0.05),
|
||||
("bitfield-distribution", 0.085, 0.05),
|
||||
("availability-store", 0.180, 0.05),
|
||||
("availability-distribution", 0.011, 0.05),
|
||||
("bitfield-distribution", 0.029, 0.05),
|
||||
("availability-store", 0.232, 0.05),
|
||||
]));
|
||||
|
||||
if messages.is_empty() {
|
||||
@@ -61,44 +73,3 @@ fn main() -> Result<(), String> {
|
||||
Err("Regressions found".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn warm_up(config: TestConfiguration) -> Result<(), String> {
|
||||
println!("Warming up...");
|
||||
let mut prev_run: Option<BenchmarkUsage> = None;
|
||||
for _ in 0..WARM_UP_COUNT {
|
||||
let curr = run(config.clone());
|
||||
if let Some(ref prev) = prev_run {
|
||||
let av_distr_diff =
|
||||
curr.cpu_usage_diff(prev, "availability-distribution").expect("Must exist");
|
||||
let bitf_distr_diff =
|
||||
curr.cpu_usage_diff(prev, "bitfield-distribution").expect("Must exist");
|
||||
let av_store_diff =
|
||||
curr.cpu_usage_diff(prev, "availability-store").expect("Must exist");
|
||||
if av_distr_diff < WARM_UP_PRECISION &&
|
||||
bitf_distr_diff < WARM_UP_PRECISION &&
|
||||
av_store_diff < WARM_UP_PRECISION
|
||||
{
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
prev_run = Some(curr);
|
||||
}
|
||||
|
||||
Err("Can't warm up".to_string())
|
||||
}
|
||||
|
||||
fn benchmark(config: TestConfiguration) -> BenchmarkUsage {
|
||||
println!("Benchmarking...");
|
||||
let usages: Vec<BenchmarkUsage> = (0..BENCH_COUNT).map(|_| run(config.clone())).collect();
|
||||
let usage = BenchmarkUsage::average(&usages);
|
||||
println!("{}", usage);
|
||||
usage
|
||||
}
|
||||
|
||||
fn run(config: TestConfiguration) -> BenchmarkUsage {
|
||||
let mut state = TestState::new(&config);
|
||||
let (mut env, _protocol_config) =
|
||||
prepare_test(config.clone(), &mut state, TestDataAvailability::Write, false);
|
||||
env.runtime()
|
||||
.block_on(benchmark_availability_write("data_availability_write", &mut env, state))
|
||||
}
|
||||
|
||||
+19
-44
@@ -27,13 +27,9 @@ use polkadot_subsystem_bench::{
|
||||
TestDataAvailability, TestState,
|
||||
},
|
||||
configuration::TestConfiguration,
|
||||
usage::BenchmarkUsage,
|
||||
utils::{warm_up_and_benchmark, WarmUpOptions},
|
||||
};
|
||||
|
||||
const BENCH_COUNT: usize = 3;
|
||||
const WARM_UP_COUNT: usize = 10;
|
||||
const WARM_UP_PRECISION: f64 = 0.01;
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
let mut messages = vec![];
|
||||
|
||||
@@ -42,14 +38,27 @@ fn main() -> Result<(), String> {
|
||||
config.num_blocks = 3;
|
||||
config.generate_pov_sizes();
|
||||
|
||||
warm_up(config.clone(), options.clone())?;
|
||||
let usage = benchmark(config.clone(), options.clone());
|
||||
let usage = warm_up_and_benchmark(WarmUpOptions::new(&["availability-recovery"]), || {
|
||||
let mut state = TestState::new(&config);
|
||||
let (mut env, _protocol_config) = prepare_test(
|
||||
config.clone(),
|
||||
&mut state,
|
||||
TestDataAvailability::Read(options.clone()),
|
||||
false,
|
||||
);
|
||||
env.runtime().block_on(benchmark_availability_read(
|
||||
"data_availability_read",
|
||||
&mut env,
|
||||
state,
|
||||
))
|
||||
})?;
|
||||
println!("{}", usage);
|
||||
|
||||
messages.extend(usage.check_network_usage(&[
|
||||
("Received from peers", 102400.000, 0.05),
|
||||
("Sent to peers", 0.335, 0.05),
|
||||
("Received from peers", 307200.000, 0.05),
|
||||
("Sent to peers", 1.667, 0.05),
|
||||
]));
|
||||
messages.extend(usage.check_cpu_usage(&[("availability-recovery", 3.850, 0.05)]));
|
||||
messages.extend(usage.check_cpu_usage(&[("availability-recovery", 11.500, 0.05)]));
|
||||
|
||||
if messages.is_empty() {
|
||||
Ok(())
|
||||
@@ -58,37 +67,3 @@ fn main() -> Result<(), String> {
|
||||
Err("Regressions found".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn warm_up(config: TestConfiguration, options: DataAvailabilityReadOptions) -> Result<(), String> {
|
||||
println!("Warming up...");
|
||||
let mut prev_run: Option<BenchmarkUsage> = None;
|
||||
for _ in 0..WARM_UP_COUNT {
|
||||
let curr = run(config.clone(), options.clone());
|
||||
if let Some(ref prev) = prev_run {
|
||||
let diff = curr.cpu_usage_diff(prev, "availability-recovery").expect("Must exist");
|
||||
if diff < WARM_UP_PRECISION {
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
prev_run = Some(curr);
|
||||
}
|
||||
|
||||
Err("Can't warm up".to_string())
|
||||
}
|
||||
|
||||
fn benchmark(config: TestConfiguration, options: DataAvailabilityReadOptions) -> BenchmarkUsage {
|
||||
println!("Benchmarking...");
|
||||
let usages: Vec<BenchmarkUsage> =
|
||||
(0..BENCH_COUNT).map(|_| run(config.clone(), options.clone())).collect();
|
||||
let usage = BenchmarkUsage::average(&usages);
|
||||
println!("{}", usage);
|
||||
usage
|
||||
}
|
||||
|
||||
fn run(config: TestConfiguration, options: DataAvailabilityReadOptions) -> BenchmarkUsage {
|
||||
let mut state = TestState::new(&config);
|
||||
let (mut env, _protocol_config) =
|
||||
prepare_test(config.clone(), &mut state, TestDataAvailability::Read(options), false);
|
||||
env.runtime()
|
||||
.block_on(benchmark_availability_read("data_availability_read", &mut env, state))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user