|
| 1 | +// Copyright (C) Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Polkadot. |
| 3 | + |
| 4 | +// Polkadot is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Polkadot is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +//! statement-distribution regression tests |
| 18 | +//! |
| 19 | +//! Statement distribution benchmark based on Kusama parameters and scale. |
| 20 | +
|
| 21 | +use polkadot_subsystem_bench::{ |
| 22 | + configuration::TestConfiguration, |
| 23 | + statement::{benchmark_statement_distribution, prepare_test, TestState}, |
| 24 | + usage::BenchmarkUsage, |
| 25 | + utils::save_to_file, |
| 26 | +}; |
| 27 | +use std::io::Write; |
| 28 | + |
| 29 | +const BENCH_COUNT: usize = 50; |
| 30 | + |
| 31 | +fn main() -> Result<(), String> { |
| 32 | + let mut messages = vec![]; |
| 33 | + let mut config = TestConfiguration::default(); |
| 34 | + config.n_cores = 100; |
| 35 | + config.n_validators = 500; |
| 36 | + config.num_blocks = 10; |
| 37 | + config.connectivity = 100; |
| 38 | + config.generate_pov_sizes(); |
| 39 | + let state = TestState::new(&config); |
| 40 | + |
| 41 | + println!("Benchmarking..."); |
| 42 | + let usages: Vec<BenchmarkUsage> = (0..BENCH_COUNT) |
| 43 | + .map(|n| { |
| 44 | + print!("\r[{}{}]", "#".repeat(n), "_".repeat(BENCH_COUNT - n)); |
| 45 | + std::io::stdout().flush().unwrap(); |
| 46 | + let (mut env, _cfgs) = prepare_test(&state, false); |
| 47 | + env.runtime().block_on(benchmark_statement_distribution( |
| 48 | + "statement-distribution", |
| 49 | + &mut env, |
| 50 | + &state, |
| 51 | + )) |
| 52 | + }) |
| 53 | + .collect(); |
| 54 | + println!("\rDone!{}", " ".repeat(BENCH_COUNT)); |
| 55 | + |
| 56 | + let average_usage = BenchmarkUsage::average(&usages); |
| 57 | + save_to_file( |
| 58 | + "charts/statement-distribution-regression-bench.json", |
| 59 | + average_usage.to_chart_json().map_err(|e| e.to_string())?, |
| 60 | + ) |
| 61 | + .map_err(|e| e.to_string())?; |
| 62 | + println!("{}", average_usage); |
| 63 | + |
| 64 | + // We expect no variance for received and sent |
| 65 | + // but use 0.001 because we operate with floats |
| 66 | + messages.extend(average_usage.check_network_usage(&[ |
| 67 | + ("Received from peers", 106.4000, 0.001), |
| 68 | + ("Sent to peers", 127.9100, 0.001), |
| 69 | + ])); |
| 70 | + messages.extend(average_usage.check_cpu_usage(&[("statement-distribution", 0.0390, 0.1)])); |
| 71 | + |
| 72 | + if messages.is_empty() { |
| 73 | + Ok(()) |
| 74 | + } else { |
| 75 | + eprintln!("{}", messages.join("\n")); |
| 76 | + Err("Regressions found".to_string()) |
| 77 | + } |
| 78 | +} |
0 commit comments