From 64667010f442c985eac52f53b94e67ea39517a91 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Wed, 13 Nov 2024 14:44:02 +0200 Subject: [PATCH 01/12] fix(network): advertised_multiaddr dump --- crates/papyrus_network/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/papyrus_network/src/lib.rs b/crates/papyrus_network/src/lib.rs index 2d0954b128..136010f92e 100644 --- a/crates/papyrus_network/src/lib.rs +++ b/crates/papyrus_network/src/lib.rs @@ -107,7 +107,7 @@ impl SerializeConfig for NetworkConfig { ParamPrivacyInput::Private, )]); config.extend(ser_optional_param( - &self.bootstrap_peer_multiaddr, + &self.advertised_multiaddr, Multiaddr::empty(), "advertised_multiaddr", "The external address other peers see this node. If this is set, the node will not \ From 79248c080bcbdda72bf49177d5a85c71085ba463 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Tue, 12 Nov 2024 17:00:10 +0200 Subject: [PATCH 02/12] chore(network): stress test utils --- .../src/bin/network_stress_test/converters.rs | 20 ++- .../src/bin/network_stress_test/utils.rs | 131 ++++++++++++++++++ 2 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 crates/papyrus_network/src/bin/network_stress_test/utils.rs diff --git a/crates/papyrus_network/src/bin/network_stress_test/converters.rs b/crates/papyrus_network/src/bin/network_stress_test/converters.rs index d3b8ae628b..18351e0abc 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/converters.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/converters.rs @@ -1,9 +1,19 @@ +use std::mem::size_of; use std::time::{Duration, SystemTime}; -struct StressTestMessage { - id: u32, - payload: Vec, - time: SystemTime, +pub const METADATA_SIZE: usize = size_of::() + size_of::() + size_of::(); + +#[derive(Debug, Clone)] +pub struct StressTestMessage { + pub id: u32, + pub payload: Vec, + pub time: SystemTime, +} + +impl StressTestMessage { + pub fn new(id: u32, payload: Vec) -> Self { + StressTestMessage { id, payload, time: SystemTime::now() } + } } impl From for Vec { @@ -24,7 +34,7 @@ impl From> for StressTestMessage { // This auto implements TryFrom> for StressTestMessage fn from(mut value: Vec) -> Self { let vec_size = value.len(); - let payload_size = vec_size - 12; + let payload_size = vec_size - METADATA_SIZE; let id_and_time = value.split_off(payload_size); let id = u32::from_be_bytes(id_and_time[0..4].try_into().unwrap()); let seconds = u64::from_be_bytes(id_and_time[4..12].try_into().unwrap()); diff --git a/crates/papyrus_network/src/bin/network_stress_test/utils.rs b/crates/papyrus_network/src/bin/network_stress_test/utils.rs new file mode 100644 index 0000000000..9e639863fd --- /dev/null +++ b/crates/papyrus_network/src/bin/network_stress_test/utils.rs @@ -0,0 +1,131 @@ +use std::collections::{BTreeMap, HashSet}; +use std::str::FromStr; +use std::time::{SystemTime, UNIX_EPOCH}; +use std::vec; + +use libp2p::identity::Keypair; +use libp2p::Multiaddr; +use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; +use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; +use papyrus_network::NetworkConfig; +use serde::{Deserialize, Serialize, Serializer}; + +pub const BOOTSTRAP_CONFIG_FILE_PATH: &str = + "crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json"; +pub const BOOTSTRAP_OUTPUT_FILE_PATH: &str = + "crates/papyrus_network/src/bin/network_stress_test/bootstrap_output.csv"; +pub const DEFAULT_CONFIG_FILE_PATH: &str = + "crates/papyrus_network/src/bin/network_stress_test/test_config.json"; +pub const DEFAULT_OUTPUT_FILE_PATH: &str = + "crates/papyrus_network/src/bin/network_stress_test/output.csv"; + +#[derive(Debug, Deserialize, Serialize)] +pub struct TestConfig { + pub network_config: NetworkConfig, + pub buffer_size: usize, + pub message_size: usize, + pub num_messages: u32, + pub output_path: String, +} + +impl SerializeConfig for TestConfig { + fn dump(&self) -> BTreeMap { + let mut config = BTreeMap::from_iter([ + ser_param( + "buffer_size", + &self.buffer_size, + "The buffer size for the network receiver.", + ParamPrivacyInput::Public, + ), + ser_param( + "message_size", + &self.message_size, + "The size of the payload for the test messages.", + ParamPrivacyInput::Public, + ), + ser_param( + "num_messages", + &self.num_messages, + "The amount of messages to send and receive.", + ParamPrivacyInput::Public, + ), + ser_param( + "output_path", + &self.output_path, + "The path of the output file.", + ParamPrivacyInput::Public, + ), + ]); + config.extend(append_sub_config_name(self.network_config.dump(), "network_config")); + config + } +} + +impl Default for TestConfig { + fn default() -> Self { + Self { + network_config: NetworkConfig::default(), + buffer_size: 1000, + message_size: 1000, + num_messages: 100000, + output_path: BOOTSTRAP_OUTPUT_FILE_PATH.to_string(), + } + } +} + +impl TestConfig { + #[allow(dead_code)] + pub fn create_config_files() { + let secret_key = vec![0; 32]; + let keypair = Keypair::ed25519_from_bytes(secret_key.clone()).unwrap(); + let peer_id = keypair.public().to_peer_id(); + + let _ = TestConfig { + network_config: NetworkConfig { + tcp_port: 10000, + quic_port: 10001, + secret_key: Some(secret_key), + ..Default::default() + }, + ..Default::default() + } + .dump_to_file(&vec![], &HashSet::new(), BOOTSTRAP_CONFIG_FILE_PATH); + let _ = TestConfig { + network_config: NetworkConfig { + tcp_port: 10002, + quic_port: 10003, + bootstrap_peer_multiaddr: Some( + Multiaddr::from_str(&format!("/ip4/127.0.0.1/tcp/10000/p2p/{}", peer_id)) + .unwrap(), + ), + ..Default::default() + }, + output_path: DEFAULT_OUTPUT_FILE_PATH.to_string(), + ..Default::default() + } + .dump_to_file(&vec![], &HashSet::new(), DEFAULT_CONFIG_FILE_PATH); + } +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct Record { + pub id: u32, + #[serde(serialize_with = "serialize_system_time_as_u128_millis")] + pub start_time: SystemTime, + #[serde(serialize_with = "serialize_system_time_as_u128_millis")] + pub end_time: SystemTime, + pub duration: u128, +} + +pub fn serialize_system_time_as_u128_millis( + time: &SystemTime, + serializer: S, +) -> Result +where + S: Serializer, +{ + let duration_since_epoch = + time.duration_since(UNIX_EPOCH).map_err(serde::ser::Error::custom)?; + let millis = duration_since_epoch.as_millis(); + serializer.serialize_u128(millis) +} From 9365978d3f1e8c11ad103ab8fe37d55ebc1592f1 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Wed, 13 Nov 2024 16:26:06 +0200 Subject: [PATCH 03/12] feat(network): broadcast stress test --- Cargo.lock | 23 ++++ Cargo.toml | 1 + crates/papyrus_network/Cargo.toml | 5 + .../bootstrap_test_config.json | 102 ++++++++++++++++++ .../src/bin/network_stress_test/main.rs | 88 ++++++++++++++- .../bin/network_stress_test/test_config.json | 102 ++++++++++++++++++ 6 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json create mode 100644 crates/papyrus_network/src/bin/network_stress_test/test_config.json diff --git a/Cargo.lock b/Cargo.lock index c23bd61159..596efcd86d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2917,6 +2917,27 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + [[package]] name = "ctr" version = "0.9.2" @@ -7359,6 +7380,8 @@ dependencies = [ "async-stream", "async-trait", "bytes", + "clap", + "csv", "deadqueue", "defaultmap", "derive_more 0.99.18", diff --git a/Cargo.toml b/Cargo.toml index 53bfa5ade9..085177cd2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,6 +106,7 @@ clap = "4.5.4" colored = "2.1.0" const_format = "0.2.30" criterion = "0.5.1" +csv = "1.3.1" deadqueue = "0.2.4" defaultmap = "0.5.0" derive_more = "0.99.17" diff --git a/crates/papyrus_network/Cargo.toml b/crates/papyrus_network/Cargo.toml index 04a22212a7..8a1497b0de 100644 --- a/crates/papyrus_network/Cargo.toml +++ b/crates/papyrus_network/Cargo.toml @@ -12,6 +12,8 @@ testing = [] async-stream.workspace = true async-trait.workspace = true bytes.workspace = true +clap.workspace = true +csv.workspace = true derive_more.workspace = true futures.workspace = true lazy_static.workspace = true @@ -54,5 +56,8 @@ tokio = { workspace = true, features = ["full", "sync", "test-util"] } tokio-stream.workspace = true void.workspace = true +[build-dependencies] + + [lints] workspace = true diff --git a/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json b/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json new file mode 100644 index 0000000000..a83e4da9b8 --- /dev/null +++ b/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json @@ -0,0 +1,102 @@ +{ + "buffer_size": { + "description": "The buffer size for the network receiver.", + "privacy": "Public", + "value": 1000 + }, + "message_size": { + "description": "The size of the payload for the test messages.", + "privacy": "Public", + "value": 1000 + }, + "network_config.advertised_multiaddr": { + "description": "The external address other peers see this node. If this is set, the node will not try to find out which addresses it has and will write this address as external instead", + "privacy": "Public", + "value": "" + }, + "network_config.advertised_multiaddr.#is_none": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "network_config.bootstrap_peer_multiaddr": { + "description": "The multiaddress of the peer node. It should include the peer's id. For more info: https://docs.libp2p.io/concepts/fundamentals/peers/", + "privacy": "Public", + "value": "" + }, + "network_config.bootstrap_peer_multiaddr.#is_none": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "network_config.chain_id": { + "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", + "privacy": "Public", + "value": "SN_MAIN" + }, + "network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": { + "description": "The base delay in milliseconds for the exponential backoff strategy.", + "privacy": "Public", + "value": 2 + }, + "network_config.discovery_config.bootstrap_dial_retry_config.factor": { + "description": "The factor for the exponential backoff strategy.", + "privacy": "Public", + "value": 5 + }, + "network_config.discovery_config.bootstrap_dial_retry_config.max_delay_seconds": { + "description": "The maximum delay in seconds for the exponential backoff strategy.", + "privacy": "Public", + "value": 5 + }, + "network_config.discovery_config.heartbeat_interval": { + "description": "The interval between each discovery (Kademlia) query in milliseconds.", + "privacy": "Public", + "value": 100 + }, + "network_config.idle_connection_timeout": { + "description": "Amount of time in seconds that a connection with no active sessions will stay alive.", + "privacy": "Public", + "value": 120 + }, + "network_config.peer_manager_config.malicious_timeout_seconds": { + "description": "The duration in seconds a peer is blacklisted after being marked as malicious.", + "privacy": "Public", + "value": 31536000 + }, + "network_config.peer_manager_config.unstable_timeout_millis": { + "description": "The duration in milliseconds a peer blacklisted after being reported as unstable.", + "privacy": "Public", + "value": 1000 + }, + "network_config.quic_port": { + "description": "The port that the node listens on for incoming quic connections.", + "privacy": "Public", + "value": 10001 + }, + "network_config.secret_key": { + "description": "The secret key used for building the peer id. If it's an empty string a random one will be used.", + "privacy": "Private", + "value": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "network_config.session_timeout": { + "description": "Maximal time in seconds that each session can take before failing on timeout.", + "privacy": "Public", + "value": 120 + }, + "network_config.tcp_port": { + "description": "The port that the node listens on for incoming tcp connections.", + "privacy": "Public", + "value": 10000 + }, + "num_messages": { + "description": "The amount of messages to send and receive.", + "privacy": "Public", + "value": 100000 + }, + "output_path": { + "description": "The path of the output file.", + "privacy": "Public", + "value": "crates/papyrus_network/src/bin/network_stress_test/bootstrap_output.csv" + } +} diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 1591c86df9..0afeb4d927 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -1,3 +1,89 @@ +use std::time::SystemTime; +use std::vec; + +use clap::Command; +use converters::{StressTestMessage, METADATA_SIZE}; +use futures::StreamExt; +use libp2p::gossipsub::Topic; +use papyrus_config::loading::load_and_process_config; +use papyrus_network::network_manager::{BroadcastTopicClientTrait, NetworkManager}; +use tokio::time::timeout; +use utils::{Record, TestConfig, BOOTSTRAP_CONFIG_FILE_PATH}; + mod converters; +mod utils; -fn main() {} +#[tokio::main] +async fn main() { + TestConfig::create_config_files(); + let args = std::env::args().collect::>(); + let default_path = BOOTSTRAP_CONFIG_FILE_PATH.to_string(); + let config_path = args.get(1).unwrap_or(&default_path); + let file = std::fs::File::open(config_path).unwrap(); + let TestConfig { network_config, buffer_size, message_size, num_messages, output_path } = + load_and_process_config(file, Command::new("Stress Test"), vec![]).unwrap(); + let mut network_manager = NetworkManager::new(network_config, None); + let mut network_channels = network_manager + .register_broadcast_topic::( + Topic::new("stress_test_topic".to_string()), + buffer_size, + ) + .unwrap(); + let mut output_vector = Vec::::new(); + tokio::select! { + _ = network_manager.run() => {} + _ = async { + let mut i = 0; + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + loop { + let message = StressTestMessage::new(i, vec![0; message_size - METADATA_SIZE]); + network_channels.broadcast_topic_client.broadcast_message(message).await.unwrap(); + i += 1; + if i == num_messages { + println!("Finished sending messages"); + futures::future::pending::<()>().await; + } + } + } => {} + _ = async { + let mut i = 0; + loop { + let maybe_response = timeout( + std::time::Duration::from_secs(60), + network_channels.broadcasted_messages_receiver.next(), + ).await; + match maybe_response { + Err(_) => { + println!("Timeout on message {}", i); + break; + } + Ok(None) => break, + Ok(Some((received_message, _report_callback))) => { + let received_message = received_message.unwrap(); + output_vector.push(Record { + id: received_message.id, + start_time: received_message.time, + end_time: SystemTime::now(), + duration: SystemTime::now() + .duration_since(received_message.time) + .unwrap() + .as_micros(), + }); + i += 1; + if i == num_messages { + tokio::time::sleep(std::time::Duration::from_secs(60)).await; + break; + } + } + } + } + } => { + println!("Finished receiving messages"); + let mut wtr = csv::Writer::from_path(output_path).unwrap(); + for record in output_vector { + wtr.serialize(record).unwrap(); + } + tokio::time::sleep(std::time::Duration::from_secs(60)).await; + } + } +} diff --git a/crates/papyrus_network/src/bin/network_stress_test/test_config.json b/crates/papyrus_network/src/bin/network_stress_test/test_config.json new file mode 100644 index 0000000000..88dffda545 --- /dev/null +++ b/crates/papyrus_network/src/bin/network_stress_test/test_config.json @@ -0,0 +1,102 @@ +{ + "buffer_size": { + "description": "The buffer size for the network receiver.", + "privacy": "Public", + "value": 1000 + }, + "message_size": { + "description": "The size of the payload for the test messages.", + "privacy": "Public", + "value": 1000 + }, + "network_config.advertised_multiaddr": { + "description": "The external address other peers see this node. If this is set, the node will not try to find out which addresses it has and will write this address as external instead", + "privacy": "Public", + "value": "" + }, + "network_config.advertised_multiaddr.#is_none": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "network_config.bootstrap_peer_multiaddr": { + "description": "The multiaddress of the peer node. It should include the peer's id. For more info: https://docs.libp2p.io/concepts/fundamentals/peers/", + "privacy": "Public", + "value": "/ip4/127.0.0.1/tcp/10000/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN" + }, + "network_config.bootstrap_peer_multiaddr.#is_none": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": false + }, + "network_config.chain_id": { + "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", + "privacy": "Public", + "value": "SN_MAIN" + }, + "network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": { + "description": "The base delay in milliseconds for the exponential backoff strategy.", + "privacy": "Public", + "value": 2 + }, + "network_config.discovery_config.bootstrap_dial_retry_config.factor": { + "description": "The factor for the exponential backoff strategy.", + "privacy": "Public", + "value": 5 + }, + "network_config.discovery_config.bootstrap_dial_retry_config.max_delay_seconds": { + "description": "The maximum delay in seconds for the exponential backoff strategy.", + "privacy": "Public", + "value": 5 + }, + "network_config.discovery_config.heartbeat_interval": { + "description": "The interval between each discovery (Kademlia) query in milliseconds.", + "privacy": "Public", + "value": 100 + }, + "network_config.idle_connection_timeout": { + "description": "Amount of time in seconds that a connection with no active sessions will stay alive.", + "privacy": "Public", + "value": 120 + }, + "network_config.peer_manager_config.malicious_timeout_seconds": { + "description": "The duration in seconds a peer is blacklisted after being marked as malicious.", + "privacy": "Public", + "value": 31536000 + }, + "network_config.peer_manager_config.unstable_timeout_millis": { + "description": "The duration in milliseconds a peer blacklisted after being reported as unstable.", + "privacy": "Public", + "value": 1000 + }, + "network_config.quic_port": { + "description": "The port that the node listens on for incoming quic connections.", + "privacy": "Public", + "value": 10003 + }, + "network_config.secret_key": { + "description": "The secret key used for building the peer id. If it's an empty string a random one will be used.", + "privacy": "Private", + "value": "" + }, + "network_config.session_timeout": { + "description": "Maximal time in seconds that each session can take before failing on timeout.", + "privacy": "Public", + "value": 120 + }, + "network_config.tcp_port": { + "description": "The port that the node listens on for incoming tcp connections.", + "privacy": "Public", + "value": 10002 + }, + "num_messages": { + "description": "The amount of messages to send and receive.", + "privacy": "Public", + "value": 100000 + }, + "output_path": { + "description": "The path of the output file.", + "privacy": "Public", + "value": "crates/papyrus_network/src/bin/network_stress_test/output.csv" + } +} From a568a603d731f79628519267fa3f261529cf72f8 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Wed, 13 Nov 2024 17:10:54 +0200 Subject: [PATCH 04/12] temp: test ip --- .../src/bin/network_stress_test/bootstrap_test_config.json | 4 ++-- crates/papyrus_network/src/bin/network_stress_test/main.rs | 1 - .../src/bin/network_stress_test/test_config.json | 6 +++--- crates/papyrus_network/src/bin/network_stress_test/utils.rs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json b/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json index a83e4da9b8..a5fdce5ea8 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json +++ b/crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json @@ -92,11 +92,11 @@ "num_messages": { "description": "The amount of messages to send and receive.", "privacy": "Public", - "value": 100000 + "value": 10000 }, "output_path": { "description": "The path of the output file.", "privacy": "Public", "value": "crates/papyrus_network/src/bin/network_stress_test/bootstrap_output.csv" } -} +} \ No newline at end of file diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 0afeb4d927..2489287f0c 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -15,7 +15,6 @@ mod utils; #[tokio::main] async fn main() { - TestConfig::create_config_files(); let args = std::env::args().collect::>(); let default_path = BOOTSTRAP_CONFIG_FILE_PATH.to_string(); let config_path = args.get(1).unwrap_or(&default_path); diff --git a/crates/papyrus_network/src/bin/network_stress_test/test_config.json b/crates/papyrus_network/src/bin/network_stress_test/test_config.json index 88dffda545..dc9852fe3b 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/test_config.json +++ b/crates/papyrus_network/src/bin/network_stress_test/test_config.json @@ -22,7 +22,7 @@ "network_config.bootstrap_peer_multiaddr": { "description": "The multiaddress of the peer node. It should include the peer's id. For more info: https://docs.libp2p.io/concepts/fundamentals/peers/", "privacy": "Public", - "value": "/ip4/127.0.0.1/tcp/10000/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN" + "value": "/ip4/10.20.20.26/tcp/10000/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN" }, "network_config.bootstrap_peer_multiaddr.#is_none": { "description": "Flag for an optional field.", @@ -92,11 +92,11 @@ "num_messages": { "description": "The amount of messages to send and receive.", "privacy": "Public", - "value": 100000 + "value": 10000 }, "output_path": { "description": "The path of the output file.", "privacy": "Public", "value": "crates/papyrus_network/src/bin/network_stress_test/output.csv" } -} +} \ No newline at end of file diff --git a/crates/papyrus_network/src/bin/network_stress_test/utils.rs b/crates/papyrus_network/src/bin/network_stress_test/utils.rs index 9e639863fd..23f5c9e141 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/utils.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/utils.rs @@ -67,7 +67,7 @@ impl Default for TestConfig { network_config: NetworkConfig::default(), buffer_size: 1000, message_size: 1000, - num_messages: 100000, + num_messages: 10000, output_path: BOOTSTRAP_OUTPUT_FILE_PATH.to_string(), } } From 5097548a2ad921c0a3b7d5f7721219f3c03e8618 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 10:44:37 +0200 Subject: [PATCH 05/12] chore(network): add peer_id and increase inbound message amount --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 4 +++- crates/papyrus_network/src/bin/network_stress_test/utils.rs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 2489287f0c..7adca0125a 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -22,6 +22,7 @@ async fn main() { let TestConfig { network_config, buffer_size, message_size, num_messages, output_path } = load_and_process_config(file, Command::new("Stress Test"), vec![]).unwrap(); let mut network_manager = NetworkManager::new(network_config, None); + let peer_id = network_manager.get_local_peer_id(); let mut network_channels = network_manager .register_broadcast_topic::( Topic::new("stress_test_topic".to_string()), @@ -60,6 +61,7 @@ async fn main() { Ok(Some((received_message, _report_callback))) => { let received_message = received_message.unwrap(); output_vector.push(Record { + peer_id: peer_id.clone(), id: received_message.id, start_time: received_message.time, end_time: SystemTime::now(), @@ -69,7 +71,7 @@ async fn main() { .as_micros(), }); i += 1; - if i == num_messages { + if i == num_messages * 4 { tokio::time::sleep(std::time::Duration::from_secs(60)).await; break; } diff --git a/crates/papyrus_network/src/bin/network_stress_test/utils.rs b/crates/papyrus_network/src/bin/network_stress_test/utils.rs index 23f5c9e141..734b512ec0 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/utils.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/utils.rs @@ -109,6 +109,7 @@ impl TestConfig { #[derive(Debug, Deserialize, Serialize)] pub struct Record { + pub peer_id: String, pub id: u32, #[serde(serialize_with = "serialize_system_time_as_u128_millis")] pub start_time: SystemTime, From fca05b64e1a8ddb0a051e43cfdfb1394d60c1740 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 11:12:38 +0200 Subject: [PATCH 06/12] fix(network): increase stress test sleep --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 7adca0125a..fdad868596 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -49,7 +49,7 @@ async fn main() { let mut i = 0; loop { let maybe_response = timeout( - std::time::Duration::from_secs(60), + std::time::Duration::from_secs(120), network_channels.broadcasted_messages_receiver.next(), ).await; match maybe_response { @@ -72,7 +72,6 @@ async fn main() { }); i += 1; if i == num_messages * 4 { - tokio::time::sleep(std::time::Duration::from_secs(60)).await; break; } } @@ -84,7 +83,7 @@ async fn main() { for record in output_vector { wtr.serialize(record).unwrap(); } - tokio::time::sleep(std::time::Duration::from_secs(60)).await; + tokio::time::sleep(std::time::Duration::from_secs(120)).await; } } } From d30d44799538d58e11b96e1ceec99c4446449002 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 15:17:19 +0200 Subject: [PATCH 07/12] fix(network): add peer id to test --- .../src/bin/network_stress_test/converters.rs | 17 ++++++++++++----- .../src/bin/network_stress_test/main.rs | 8 ++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/converters.rs b/crates/papyrus_network/src/bin/network_stress_test/converters.rs index 18351e0abc..b0eca85211 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/converters.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/converters.rs @@ -1,31 +1,37 @@ use std::mem::size_of; +use std::str::FromStr; use std::time::{Duration, SystemTime}; -pub const METADATA_SIZE: usize = size_of::() + size_of::() + size_of::(); +use libp2p::PeerId; + +pub const METADATA_SIZE: usize = size_of::() + size_of::() + size_of::() + 38; #[derive(Debug, Clone)] pub struct StressTestMessage { pub id: u32, pub payload: Vec, pub time: SystemTime, + pub peer_id: String, } impl StressTestMessage { - pub fn new(id: u32, payload: Vec) -> Self { - StressTestMessage { id, payload, time: SystemTime::now() } + pub fn new(id: u32, payload: Vec, peer_id: String) -> Self { + StressTestMessage { id, payload, time: SystemTime::now(), peer_id } } } impl From for Vec { fn from(value: StressTestMessage) -> Self { - let StressTestMessage { id, mut payload, time } = value; + let StressTestMessage { id, mut payload, time, peer_id } = value; let id = id.to_be_bytes().to_vec(); let time = time.duration_since(SystemTime::UNIX_EPOCH).unwrap(); let seconds = time.as_secs().to_be_bytes().to_vec(); let nanos = time.subsec_nanos().to_be_bytes().to_vec(); + let peer_id = PeerId::from_str(&peer_id).unwrap().to_bytes(); payload.extend(id); payload.extend(seconds); payload.extend(nanos); + payload.extend(peer_id); payload } } @@ -40,6 +46,7 @@ impl From> for StressTestMessage { let seconds = u64::from_be_bytes(id_and_time[4..12].try_into().unwrap()); let nanos = u32::from_be_bytes(id_and_time[12..16].try_into().unwrap()); let time = SystemTime::UNIX_EPOCH + Duration::new(seconds, nanos); - StressTestMessage { id, payload: value, time } + let peer_id = PeerId::from_bytes(&id_and_time[16..]).unwrap().to_string(); + StressTestMessage { id, payload: value, time, peer_id } } } diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index fdad868596..4e35f1117b 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -36,7 +36,7 @@ async fn main() { let mut i = 0; tokio::time::sleep(std::time::Duration::from_secs(5)).await; loop { - let message = StressTestMessage::new(i, vec![0; message_size - METADATA_SIZE]); + let message = StressTestMessage::new(i, vec![0; message_size - METADATA_SIZE], peer_id.clone()); network_channels.broadcast_topic_client.broadcast_message(message).await.unwrap(); i += 1; if i == num_messages { @@ -61,7 +61,7 @@ async fn main() { Ok(Some((received_message, _report_callback))) => { let received_message = received_message.unwrap(); output_vector.push(Record { - peer_id: peer_id.clone(), + peer_id: received_message.peer_id, id: received_message.id, start_time: received_message.time, end_time: SystemTime::now(), @@ -71,7 +71,8 @@ async fn main() { .as_micros(), }); i += 1; - if i == num_messages * 4 { + if i == num_messages * 4{ + tokio::time::sleep(std::time::Duration::from_secs(90)).await; break; } } @@ -83,7 +84,6 @@ async fn main() { for record in output_vector { wtr.serialize(record).unwrap(); } - tokio::time::sleep(std::time::Duration::from_secs(120)).await; } } } From bd3120f0272894624c6db2466d0ee136d398344d Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 15:51:02 +0200 Subject: [PATCH 08/12] chore(network): increase run time --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 4e35f1117b..026f2c3365 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -71,8 +71,8 @@ async fn main() { .as_micros(), }); i += 1; - if i == num_messages * 4{ - tokio::time::sleep(std::time::Duration::from_secs(90)).await; + if i == num_messages * 4 { + tokio::time::sleep(std::time::Duration::from_secs(150)).await; break; } } From da7bc2ed83a9d5e66f4e1c233620eb5ad9380819 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 16:05:43 +0200 Subject: [PATCH 09/12] fix(network): remove sleep --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 026f2c3365..c9ff11e8ea 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -49,7 +49,7 @@ async fn main() { let mut i = 0; loop { let maybe_response = timeout( - std::time::Duration::from_secs(120), + std::time::Duration::from_secs(60), network_channels.broadcasted_messages_receiver.next(), ).await; match maybe_response { @@ -72,7 +72,6 @@ async fn main() { }); i += 1; if i == num_messages * 4 { - tokio::time::sleep(std::time::Duration::from_secs(150)).await; break; } } From b3b0213d3b174cce81e677a568d29d0f5b3e2341 Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 16:25:47 +0200 Subject: [PATCH 10/12] fix(network): time to connect --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index c9ff11e8ea..c00afb99de 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -34,7 +34,7 @@ async fn main() { _ = network_manager.run() => {} _ = async { let mut i = 0; - tokio::time::sleep(std::time::Duration::from_secs(5)).await; + tokio::time::sleep(std::time::Duration::from_secs(20)).await; loop { let message = StressTestMessage::new(i, vec![0; message_size - METADATA_SIZE], peer_id.clone()); network_channels.broadcast_topic_client.broadcast_message(message).await.unwrap(); From 2fa6f8049ac8e33b41d65a6c72beab4e8793e16c Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 16:54:08 +0200 Subject: [PATCH 11/12] fix(network): increase timeout --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index c00afb99de..351354e48d 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -49,7 +49,7 @@ async fn main() { let mut i = 0; loop { let maybe_response = timeout( - std::time::Duration::from_secs(60), + std::time::Duration::from_secs(120), network_channels.broadcasted_messages_receiver.next(), ).await; match maybe_response { From 77ad5e41372a7f65a2fa4dd11aba271ea5e60e3d Mon Sep 17 00:00:00 2001 From: eitanm-starkware Date: Thu, 14 Nov 2024 17:18:26 +0200 Subject: [PATCH 12/12] fix(network): increase timeout for finishing node --- crates/papyrus_network/src/bin/network_stress_test/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/papyrus_network/src/bin/network_stress_test/main.rs b/crates/papyrus_network/src/bin/network_stress_test/main.rs index 351354e48d..546b84bc40 100644 --- a/crates/papyrus_network/src/bin/network_stress_test/main.rs +++ b/crates/papyrus_network/src/bin/network_stress_test/main.rs @@ -72,6 +72,7 @@ async fn main() { }); i += 1; if i == num_messages * 4 { + tokio::time::sleep(std::time::Duration::from_secs(20)).await; break; } }