Skip to content

Commit

Permalink
Make load test retry if connection failed
Browse files Browse the repository at this point in the history
  • Loading branch information
dsocolobsky committed Dec 2, 2024
1 parent f9cb7bc commit 2d9e8fd
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 46 deletions.
21 changes: 8 additions & 13 deletions .github/scripts/flamegraph.sh
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 39 additions & 7 deletions .github/workflows/flamegraph_reporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
78 changes: 52 additions & 26 deletions cmd/ethrex_l2/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(())
}
}
Expand Down

0 comments on commit 2d9e8fd

Please sign in to comment.