From 2d9e8fd834f25197726289c203bf5fb816a887b8 Mon Sep 17 00:00:00 2001 From: Dylan Socolobsky Date: Mon, 2 Dec 2024 14:38:38 -0300 Subject: [PATCH] Make load test retry if connection failed --- .github/scripts/flamegraph.sh | 21 +++--- .github/workflows/flamegraph_reporter.yaml | 46 +++++++++++-- cmd/ethrex_l2/src/commands/test.rs | 78 ++++++++++++++-------- 3 files changed, 99 insertions(+), 46 deletions(-) diff --git a/.github/scripts/flamegraph.sh b/.github/scripts/flamegraph.sh index 0810f40de3..4d41d1dea1 100644 --- a/.github/scripts/flamegraph.sh +++ b/.github/scripts/flamegraph.sh @@ -1,24 +1,19 @@ #!/bin/bash +iterations=3 +value=10000000 account=0x33c6b73432B3aeA0C1725E415CC40D04908B85fd -end_val=$((172 * 1000 * 10000000)) +end_val=$((172 * $iterations * $value)) -#echo "Running ethrex..." -#CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin ethrex --features dev -- --network test_data/genesis-l2.json --http.port 1729 & -#echo "Sleeping 10s before running test..." -#sleep 10 echo "Sending to account $account" -ethrex_l2 test load --path ./test_data/private_keys.txt -i 1000 -v --value 10000000 --to $account +ethrex_l2 test load --path ./test_data/private_keys.txt -i $iterations -v --value $value --to $account -echo "Monitoring..." +echo "Waiting for transactions to be processed..." output=$(cast balance $account --rpc-url=http://localhost:1729 2>&1) -echo "ini $output" -echo "end $end_val" while [[ $output -le $end_val ]]; do sleep 5 output=$(cast balance $account --rpc-url=http://localhost:1729 2>&1) - echo "out $output" done -echo "Balance of $output reached, killing process ethrex" - -sudo pkill ethrex && while pgrep -l cargo flamegraph; do sleep 1;done; +echo "Done. Balance of $output reached, killing process ethrex" +sudo pkill ethrex && while pgrep -l "cargo-flamegraph"; do sleep 1;done; +echo "ethrex killed" diff --git a/.github/workflows/flamegraph_reporter.yaml b/.github/workflows/flamegraph_reporter.yaml index 3ad4eb298c..99dcf2faca 100644 --- a/.github/workflows/flamegraph_reporter.yaml +++ b/.github/workflows/flamegraph_reporter.yaml @@ -26,22 +26,54 @@ jobs: - name: Caching uses: Swatinem/rust-cache@v2 + - name: Change perf settings + run: | + sudo sysctl kernel.perf_event_paranoid=-1 + sudo perf list hw + - name: Install flamegraph run: cargo install flamegraph + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Install ethrex_l2 cli run: | cargo install --path cmd/ethrex_l2 ethrex_l2 config create default --default ethrex_l2 config set default - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + - name: Build ethrex + run: CARGO_PROFILE_RELEASE_DEBUG=true cargo build --release --bin ethrex --features dev - - name: Generate Flamegraph for Ethrex + - name: Generate Flamegraph data for Ethrex shell: bash run: | - CARGO_PROFILE_RELEASE_DEBUG=true cargo build --release --bin ethrex --features dev && - CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin ethrex --features dev -- --network test_data/genesis-l2.json --http.port 1729 & - sleep 10 && - bash .github/scripts/flamegraph.sh + CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph -c "record -o perf.data -F997 --call-graph dwarf,16384 -g" --bin ethrex --features dev -- --network test_data/genesis-l2.json --http.port 1729 & + echo "waiting to execute load test..." + sleep 30 && + echo "executing load test..." + bash .github/scripts/flamegraph.sh && + echo "Load test finished" + + - name: Generate SVG + run: | + wget https://raw.githubusercontent.com/brendangregg/FlameGraph/refs/heads/master/stackcollapse-perf.pl + wget https://raw.githubusercontent.com/brendangregg/FlameGraph/refs/heads/master/flamegraph.pl + chmod +x ./stackcollapse-perf.pl + chmod +x ./flamegraph.pl + ./stackcollapse-perf.pl perf.data > perf.folded + ./flamegraph.pl perf.folded > flamegraph.svg + + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: perf.data + path: ./perf.data + + - name: Upload artifacts - flamegraph.svg + uses: actions/upload-artifact@v4 + with: + name: flamegraph.svg + path: ./flamegraph.svg diff --git a/cmd/ethrex_l2/src/commands/test.rs b/cmd/ethrex_l2/src/commands/test.rs index 3551fa423e..8be1b4928d 100644 --- a/cmd/ethrex_l2/src/commands/test.rs +++ b/cmd/ethrex_l2/src/commands/test.rs @@ -115,6 +115,25 @@ async fn transfer_from( retries } +async fn test_connection(cfg: EthrexL2Config) -> bool { + let client = EthClient::new(&cfg.network.l2_rpc_url); + let mut retries = 0; + while retries < 50 { + match client.get_chain_id().await { + Ok(_) => { + return true; + } + Err(err) => { + println!("Connection to server failed: {err}, retrying ({retries}/50)"); + retries += 1; + sleep(std::time::Duration::from_secs(30)); + } + } + } + println!("Failed to establish connection to the server"); + false +} + impl Command { pub async fn run(self, cfg: EthrexL2Config) -> eyre::Result<()> { match self { @@ -125,34 +144,41 @@ impl Command { iterations, verbose, } => { - if let Ok(lines) = read_lines(path) { - let to_address = match to { - Some(address) => address, - None => Address::random(), - }; - println!("Sending to: {to_address:#x}"); - - let mut threads = vec![]; - for pk in lines.map_while(Result::ok) { - let thread = tokio::spawn(transfer_from( - pk, - to_address, - value, - iterations, - verbose, - cfg.clone(), - )); - threads.push(thread); - } - - let mut retries = 0; - for thread in threads { - retries += thread.await?; - } - - println!("Total retries: {retries}"); + let Ok(lines) = read_lines(path) else { + return Ok(()); + }; + + if !test_connection(cfg.clone()).await { + println!("Test failed to establish connection to server"); + return Ok(()); + } + + let to_address = match to { + Some(address) => address, + None => Address::random(), + }; + println!("Sending to: {to_address:#x}"); + + let mut threads = vec![]; + for pk in lines.map_while(Result::ok) { + let thread = tokio::spawn(transfer_from( + pk, + to_address, + value, + iterations, + verbose, + cfg.clone(), + )); + threads.push(thread); } + let mut retries = 0; + for thread in threads { + retries += thread.await?; + } + + println!("Total retries: {retries}"); + Ok(()) } }