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] subsystem-bench: Add real networking stack #6845

Closed
wants to merge 18 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
4 changes: 4 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,29 @@ use polkadot_subsystem_bench::{
usage::BenchmarkUsage,
utils::save_to_file,
};
use std::io::Write;
use std::{io::Write, sync::Arc};

const BENCH_COUNT: usize = 50;

fn main() -> Result<(), String> {
sp_tracing::try_init_simple();
let mut messages = vec![];
let mut config = TestConfiguration::default();
config.n_cores = 100;
config.n_validators = 500;
config.n_cores = 2;
config.n_validators = 10;
config.num_blocks = 10;
config.connectivity = 100;
config.generate_pov_sizes();
let state = TestState::new(&config);
let state = Arc::new(TestState::new(&config));

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, _cfgs) = prepare_test(&state, false);
env.runtime().block_on(benchmark_statement_distribution(&mut env, &state))
let (mut env, _cfgs) = prepare_test(Arc::clone(&state), false);
env.runtime()
.block_on(benchmark_statement_distribution(&mut env, Arc::clone(&state)))
})
.collect();
println!("\rDone!{}", " ".repeat(BENCH_COUNT));
Expand Down
5 changes: 5 additions & 0 deletions polkadot/node/subsystem-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ pyroscope = { workspace = true }
pyroscope_pprofrs = { workspace = true }
strum = { features = ["derive"], workspace = true, default-features = true }

parking_lot = { workspace = true, default-features = true }
polkadot-network-bridge = { workspace = true, default-features = true }
sc-network-common = { workspace = true, default-features = true }
array-bytes = { workspace = true, default-features = true }

[features]
default = []
memprofile = [
Expand Down
9 changes: 5 additions & 4 deletions polkadot/node/subsystem-bench/src/cli/subsystem-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use polkadot_subsystem_bench::{approval, availability, configuration, statement}
use pyroscope::PyroscopeAgent;
use pyroscope_pprofrs::{pprof_backend, PprofConfig};
use serde::{Deserialize, Serialize};
use std::path::Path;
use std::{path::Path, sync::Arc};

mod valgrind;

Expand Down Expand Up @@ -164,10 +164,11 @@ impl BenchCli {
env.runtime().block_on(approval::bench_approvals(&mut env, state))
},
TestObjective::StatementDistribution => {
let state = statement::TestState::new(&test_config);
let (mut env, _protocol_config) = statement::prepare_test(&state, true);
let state = Arc::new(statement::TestState::new(&test_config));
let (mut env, _protocol_config) =
statement::prepare_test(Arc::clone(&state), true);
env.runtime()
.block_on(statement::benchmark_statement_distribution(&mut env, &state))
.block_on(statement::benchmark_statement_distribution(&mut env, state))
},
};
println!("\n{}\n{}", benchmark_name.purple(), usage);
Expand Down
17 changes: 14 additions & 3 deletions polkadot/node/subsystem-bench/src/lib/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use itertools::Itertools;
use polkadot_primitives::{AssignmentId, AuthorityDiscoveryId, ValidatorId, ValidatorPair};
use rand::thread_rng;
use rand_distr::{Distribution, Normal, Uniform};
use sc_network_types::PeerId;
use sc_network::config::{NodeKeyConfig, Secret};
use sc_network_types::{ed25519::SecretKey, PeerId};
use serde::{Deserialize, Serialize};
use sp_consensus_babe::AuthorityId;
use sp_core::Pair;
Expand Down Expand Up @@ -199,6 +200,15 @@ impl TestConfiguration {

/// Generates the authority keys we need for the network emulation.
pub fn generate_authorities(&self) -> TestAuthorities {
let node_key_configs = (0..self.n_validators)
.map(|_| NodeKeyConfig::Ed25519(Secret::Input(SecretKey::generate())))
.collect_vec();
let peer_ids = node_key_configs
.iter()
.cloned()
.map(|node_key_config| node_key_config.into_keypair().unwrap().public().to_peer_id())
.collect_vec();

let keyring = Keyring::default();

let key_seeds = (0..self.n_validators)
Expand All @@ -210,7 +220,7 @@ impl TestConfiguration {
.map(|seed| keyring.sr25519_new(seed.as_str()))
.collect::<Vec<_>>();

// Generate keys and peers ids in each of the format needed by the tests.
// Generate keys in each of the format needed by the tests.
let validator_public: Vec<ValidatorId> =
keys.iter().map(|key| (*key).into()).collect::<Vec<_>>();

Expand All @@ -222,7 +232,6 @@ impl TestConfiguration {

let validator_assignment_id: Vec<AssignmentId> =
keys.iter().map(|key| (*key).into()).collect::<Vec<_>>();
let peer_ids: Vec<PeerId> = keys.iter().map(|_| PeerId::random()).collect::<Vec<_>>();

let peer_id_to_authority = peer_ids
.iter()
Expand All @@ -239,6 +248,7 @@ impl TestConfiguration {
keyring,
validator_public,
validator_authority_id,
node_key_configs,
peer_ids,
validator_babe_id,
validator_assignment_id,
Expand Down Expand Up @@ -275,6 +285,7 @@ pub struct TestAuthorities {
pub peer_ids: Vec<PeerId>,
pub peer_id_to_authority: HashMap<PeerId, AuthorityDiscoveryId>,
pub validator_pairs: Vec<ValidatorPair>,
pub node_key_configs: Vec<NodeKeyConfig>,
}

/// Sample latency (in milliseconds) from a normal distribution with parameters
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/subsystem-bench/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// The validator index that represents the node that is under test.
pub const NODE_UNDER_TEST: u32 = 0;
pub const SESSION_INDEX: u32 = 0;

pub mod approval;
pub mod availability;
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/subsystem-bench/src/lib/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod dummy;
pub mod network_bridge;
pub mod prospective_parachains;
pub mod runtime_api;
pub mod statement_distribution;

pub struct AlwaysSupportsParachains {}

Expand Down
Loading
Loading