diff --git a/crates/papyrus_network/src/bin/network_stress_test/README.md b/crates/papyrus_network/src/bin/network_stress_test/README.md new file mode 100644 index 00000000000..145b759cc4f --- /dev/null +++ b/crates/papyrus_network/src/bin/network_stress_test/README.md @@ -0,0 +1,36 @@ +## Network Stress Test + +# Setup and Run Stress Test + +1. **Create Remote Engines** + + Create 5 gcloud VM instances. Make sure to have the necessary RAM and disk space. Each instance should be named in the following pattern: + + ``` + -0, ... ,-4 + ``` + +2. **Set Bootstrap Node** + + Find the internal IP of your bootstrap node in the VM instances chart on google cloud console. Paste it into the test_config.json file into the bootstrap_peer_multaddr value instead of it's placeholder. + +3. **Install Rust and clone repository** + + For all 5 instances run: + + ``` + gcloud compute ssh -0 --project -- 'cd && sudo apt install -y git unzip clang && curl https://sh.rustup.rs -sSf | sh -s -- -y && source "$HOME/.cargo/env" && git clone https://github.com/starkware-libs/sequencer.git; cd sequencer && sudo scripts/dependencies.sh cargo build --release -p papyrus_network --bin network_stress_test' + ``` +4. **Run test** + + ``` + PROJECT_ID= BASE_INSTANCE_NAME= BASE_PATH= ZONE= ./run_nw_stress_test.sh + ``` + +# Pull repo updates to virtual machines + + Run: + + ``` + PROJECT_ID= BASE_INSTANCE_NAME= BASE_PATH= ZONE= ./pull_stress_test.sh + ``` diff --git a/crates/papyrus_network/src/bin/network_stress_test/pull_stress_test.sh b/crates/papyrus_network/src/bin/network_stress_test/pull_stress_test.sh new file mode 100755 index 00000000000..49b39c85eda --- /dev/null +++ b/crates/papyrus_network/src/bin/network_stress_test/pull_stress_test.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [[ -z "$BASE_INSTANCE_NAME" || -z "$PROJECT_ID" || -z "$BASE_PATH" || -z "$ZONE" ]]; then + echo "Error: BASE_INSTANCE_NAME, PROJECT_ID, and PATH must be set." + echo "Instance name must be set in the format 'base-instance-name-0'... 'base-instance-name-4'." + exit 1 +fi + +PATH_TO_REPO="$BASE_PATH/sequencer" + +# Loop over instances from 0 to 4 +for i in {0..4}; do +( + INSTANCE_NAME="${BASE_INSTANCE_NAME}-${i}" + echo "Connecting to $INSTANCE_NAME..." + + gcloud compute ssh "$INSTANCE_NAME" --project "$PROJECT_ID" --zone "$ZONE" -- "cd $PATH_TO_REPO && git pull" + + echo "Finished with $INSTANCE_NAME." +) & +done diff --git a/crates/papyrus_network/src/bin/network_stress_test/run_nw_stress_test.sh b/crates/papyrus_network/src/bin/network_stress_test/run_nw_stress_test.sh new file mode 100755 index 00000000000..8464a99b454 --- /dev/null +++ b/crates/papyrus_network/src/bin/network_stress_test/run_nw_stress_test.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +if [[ -z "$BASE_INSTANCE_NAME" || -z "$PROJECT_ID" || -z "$BASE_PATH" || -z "$ZONE" ]]; then + echo "Error: BASE_INSTANCE_NAME, PROJECT_ID, ZONE, and PATH must be set." + echo "Instance name must be set in the format 'base-instance-name-0'... 'base-instance-name-4'." + exit 1 +fi + +# Project ID and base instance name +PATH_TO_REPO="$BASE_PATH/sequencer" +PATH_TO_ENV="$BASE_PATH/.cargo/env" + +# Commands to execute on each instance +COMMAND_PATH_BOOT="cd ${PATH_TO_REPO} && source ${PATH_TO_ENV} && cargo run --release -p papyrus_network --bin network_stress_test" +COMMAND_PATH="cd ${PATH_TO_REPO} && source ${PATH_TO_ENV} && cargo run --release -p papyrus_network --bin network_stress_test -- crates/papyrus_network/src/bin/network_stress_test/test_config.json" + + +# Store the process IDs of all opened processes +declare -a process_pids + +# Start the boot command on the first instance (instance 0) +( + echo "Starting boot command on ${BASE_INSTANCE_NAME}-0..." + gcloud compute ssh "${BASE_INSTANCE_NAME}-0" --project "${PROJECT_ID}" --zone "${ZONE}" -- "${COMMAND_PATH_BOOT}" + echo "Boot command finished on ${BASE_INSTANCE_NAME}-0." +) & +process_pids+=($!) # Store the PID of the background process + +# Run the command on instances 1 to 4 +for i in {1..4}; do + ( + echo "Starting command on ${BASE_INSTANCE_NAME}-${i}..." + gcloud compute ssh "${BASE_INSTANCE_NAME}-${i}" --project "${PROJECT_ID}" --zone "${ZONE}" -- "${COMMAND_PATH}" + echo "Command finished on ${BASE_INSTANCE_NAME}-${i}." + ) & + process_pids+=($!) # Store the PID of the background process +done + +# Wait for all commands to complete +for pid in "${process_pids[@]}"; do + wait "$pid" +done +echo "All commands completed." + +# Retrieve the bootstrap output from instance 0 +echo "Retrieving bootstrap output from ${BASE_INSTANCE_NAME}-0..." +gcloud compute ssh "${BASE_INSTANCE_NAME}-0" --project "${PROJECT_ID}" --zone "${ZONE}" -- "cat ${PATH_TO_REPO}/crates/papyrus_network/src/bin/network_stress_test/bootstrap_output.csv" > output.csv +echo "Bootstrap output saved as bootstrap_output.csv." + +# Retrieve output.csv files from each instance with an incremented filename +for i in {1..4}; do + ( + echo "Retrieving output.csv from ${BASE_INSTANCE_NAME}-${i}..." + gcloud compute ssh "${BASE_INSTANCE_NAME}-${i}" --project "${PROJECT_ID}" --zone "${ZONE}" -- "cat ${PATH_TO_REPO}/crates/papyrus_network/src/bin/network_stress_test/output.csv" > output${i}.csv + echo "Retrieved output.csv from ${BASE_INSTANCE_NAME}-${i} and saved as output${i}.csv." + ) & +done + +# Wait for file retrieval processes to complete +wait +echo "All output files retrieved." +# #!/bin/bash + +# # Project ID and base instance name +# PROJECT_ID="starkware-dev" +# BASE_INSTANCE_NAME="eitan-m-broadcast-stress-test" + +# # Commands to execute on each instance +# COMMAND_PATH_BOOT="cd /home/eitan_m_starkware_co/sequencer && source /home/eitan_m_starkware_co/.cargo/env && cargo run --release -p papyrus_network --bin network_stress_test" +# COMMAND_PATH="cd /home/eitan_m_starkware_co/sequencer && source /home/eitan_m_starkware_co/.cargo/env && cargo run --release -p papyrus_network --bin network_stress_test -- crates/papyrus_network/src/bin/network_stress_test/test_config.json" + +# # Zone for the instances +# ZONE="us-central1-c" + +# # Store the process IDs of all opened processes +# declare -a process_pids + +# # Start the boot command on the first instance (instance 0) +# ( +# echo "Starting boot command on ${BASE_INSTANCE_NAME}-0..." +# gcloud compute ssh "${BASE_INSTANCE_NAME}-0" --project "${PROJECT_ID}" --zone "${ZONE}" -- "${COMMAND_PATH_BOOT}" +# echo "Boot command finished on ${BASE_INSTANCE_NAME}-0." +# ) & +# process_pids+=($!) # Store the PID of the background process + +# # Run the command on instances 1 to 4 +# for i in {1..4}; do +# ( +# echo "Starting command on ${BASE_INSTANCE_NAME}-${i}..." +# gcloud compute ssh "${BASE_INSTANCE_NAME}-${i}" --project "${PROJECT_ID}" --zone "${ZONE}" -- "${COMMAND_PATH}" +# echo "Command finished on ${BASE_INSTANCE_NAME}-${i}." +# ) & +# process_pids+=($!) # Store the PID of the background process +# done + +# # Wait for all commands to complete +# for pid in "${process_pids[@]}"; do +# wait "$pid" +# done +# echo "All commands completed." + +# # Retrieve the bootstrap output from instance 0 +# echo "Retrieving bootstrap output from ${BASE_INSTANCE_NAME}-0..." +# gcloud compute ssh "${BASE_INSTANCE_NAME}-0" --project "${PROJECT_ID}" --zone "${ZONE}" -- 'cat /home/eitan_m_starkware_co/sequencer/crates/papyrus_network/src/bin/network_stress_test/bootstrap_output.csv' > bootstrap_output.csv +# echo "Bootstrap output saved as bootstrap_output.csv." + +# # Retrieve output.csv files from each instance with an incremented filename +# for i in {1..4}; do +# ( +# echo "Retrieving output.csv from ${BASE_INSTANCE_NAME}-${i}..." +# gcloud compute ssh "${BASE_INSTANCE_NAME}-${i}" --project "${PROJECT_ID}" --zone "${ZONE}" -- 'cat /home/eitan_m_starkware_co/sequencer/crates/papyrus_network/src/bin/network_stress_test/output.csv' > output${i}.csv +# echo "Retrieved output.csv from ${BASE_INSTANCE_NAME}-${i} and saved as output${i}.csv." +# ) & +# done + +# # Wait for file retrieval processes to complete +# wait +# echo "All output files retrieved." \ No newline at end of file