-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat(network): broadcast stress test #2025
Open
eitanm-starkware
wants to merge
12
commits into
main
Choose a base branch
from
eitan/broadcast_stress_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+477
−9
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6466701
fix(network): advertised_multiaddr dump
eitanm-starkware 79248c0
chore(network): stress test utils
eitanm-starkware 9365978
feat(network): broadcast stress test
eitanm-starkware a568a60
temp: test ip
eitanm-starkware 5097548
chore(network): add peer_id and increase inbound message amount
eitanm-starkware fca05b6
fix(network): increase stress test sleep
eitanm-starkware d30d447
fix(network): add peer id to test
eitanm-starkware bd3120f
chore(network): increase run time
eitanm-starkware da7bc2e
fix(network): remove sleep
eitanm-starkware b3b0213
fix(network): time to connect
eitanm-starkware 2fa6f80
fix(network): increase timeout
eitanm-starkware 77ad5e4
fix(network): increase timeout for finishing node
eitanm-starkware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
crates/papyrus_network/src/bin/network_stress_test/bootstrap_test_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": 10000 | ||
}, | ||
"output_path": { | ||
"description": "The path of the output file.", | ||
"privacy": "Public", | ||
"value": "crates/papyrus_network/src/bin/network_stress_test/bootstrap_output.csv" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
let args = std::env::args().collect::<Vec<String>>(); | ||
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 peer_id = network_manager.get_local_peer_id(); | ||
let mut network_channels = network_manager | ||
.register_broadcast_topic::<StressTestMessage>( | ||
Topic::new("stress_test_topic".to_string()), | ||
buffer_size, | ||
) | ||
.unwrap(); | ||
let mut output_vector = Vec::<Record>::new(); | ||
tokio::select! { | ||
_ = network_manager.run() => {} | ||
_ = async { | ||
let mut i = 0; | ||
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(); | ||
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(120), | ||
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 { | ||
peer_id: received_message.peer_id, | ||
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 * 4 { | ||
tokio::time::sleep(std::time::Duration::from_secs(20)).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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message parsing code should validate that
value.len() >= METADATA_SIZE
before attempting to split the message. This prevents panics from malformed messages. Consider adding:Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.