|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Define log directories |
| 4 | +LOG_DIR="logs" |
| 5 | +mkdir -p "$LOG_DIR" |
| 6 | + |
| 7 | +# Create data directories for trin instances |
| 8 | +DATA_DIR_SENDER="./data_sender" |
| 9 | +DATA_DIR_RECEIVER="./data_receiver" |
| 10 | +mkdir -p "$LOG_DIR/$DATA_DIR_SENDER" "$LOG_DIR/$DATA_DIR_RECEIVER" |
| 11 | + |
| 12 | +# Clone portal-accumulators repository if not already present |
| 13 | +if [ ! -d "../../portal-accumulators" ]; then |
| 14 | + git clone https://github.com/ethereum/portal-accumulators ../../portal-accumulators || { echo "Failed to clone portal-accumulators"; exit 1; } |
| 15 | +fi |
| 16 | + |
| 17 | +# Build trin-benchmark-cordinator with release profile |
| 18 | +pushd ../.. || { echo "Failed to change directory"; exit 1; } |
| 19 | +cargo build --release -p trin-bench || { echo "Failed to build trin-benchmark-cordinator"; exit 1; } |
| 20 | +popd || { echo "Failed to return to original directory"; exit 1; } |
| 21 | + |
| 22 | +# Define process PIDs |
| 23 | +PIDS=() |
| 24 | + |
| 25 | +# Find available ports dynamically and ensure they are unique |
| 26 | +find_unused_port() { |
| 27 | + local port=$1 |
| 28 | + while ss -tuln | awk '{print $4}' | grep -q ":$port$"; do |
| 29 | + port=$((port + 1)) |
| 30 | + done |
| 31 | + echo $port |
| 32 | +} |
| 33 | + |
| 34 | +PORT_SENDER=$(find_unused_port 9050) |
| 35 | +PORT_RECEIVER=$(find_unused_port $((PORT_SENDER + 10))) |
| 36 | +EXT_PORT_SENDER=$(find_unused_port 9100) |
| 37 | +EXT_PORT_RECEIVER=$(find_unused_port $((EXT_PORT_SENDER + 10))) |
| 38 | + |
| 39 | +# Run trin sender with perf profiling |
| 40 | +cargo flamegraph --profile profiling -c "record -F 97 --call-graph dwarf,64000 -g -o $LOG_DIR/trin_sender.perf" --root --output "$LOG_DIR/trin_sender.svg" -p trin -- \ |
| 41 | + --web3-transport http \ |
| 42 | + --web3-http-address http://127.0.0.1:$PORT_SENDER/ \ |
| 43 | + --mb 0 \ |
| 44 | + --bootnodes none \ |
| 45 | + --external-address 127.0.0.1:$EXT_PORT_SENDER \ |
| 46 | + --discovery-port $EXT_PORT_SENDER \ |
| 47 | + --data-dir "$LOG_DIR/$DATA_DIR_SENDER" \ |
| 48 | + > "$LOG_DIR/trin_sender.log" 2>&1 & |
| 49 | +PIDS+=("$!") |
| 50 | + |
| 51 | +# Run trin receiver with perf profiling |
| 52 | +cargo flamegraph --profile profiling -c "record -F 97 --call-graph dwarf,64000 -g -o $LOG_DIR/trin_receiver.perf" --root --output "$LOG_DIR/trin_receiver.svg" -p trin -- \ |
| 53 | + --web3-transport http \ |
| 54 | + --web3-http-address http://127.0.0.1:$PORT_RECEIVER/ \ |
| 55 | + --mb 10000 \ |
| 56 | + --bootnodes none \ |
| 57 | + --external-address 127.0.0.1:$EXT_PORT_RECEIVER \ |
| 58 | + --discovery-port $EXT_PORT_RECEIVER \ |
| 59 | + --data-dir "$LOG_DIR/$DATA_DIR_RECEIVER" \ |
| 60 | + > "$LOG_DIR/trin_receiver.log" 2>&1 & |
| 61 | +PIDS+=("$!") |
| 62 | + |
| 63 | +# Run trin benchmark coordinator without perf profiling |
| 64 | +../../target/release/trin-bench \ |
| 65 | + --web3-http-address-node-1 http://127.0.0.1:$PORT_SENDER/ \ |
| 66 | + --web3-http-address-node-2 http://127.0.0.1:$PORT_RECEIVER/ \ |
| 67 | + --epoch-accumulator-path ../../portal-accumulators \ |
| 68 | + --start-era1 1000 \ |
| 69 | + --end-era1 1002 \ |
| 70 | + > "$LOG_DIR/trin_benchmark.log" 2>&1 & |
| 71 | +TRIN_BENCH_PID=$! |
| 72 | + |
| 73 | +echo "Started Benchmark" |
| 74 | + |
| 75 | +CLEANED_UP=false |
| 76 | +# Function to clean up processes on SIGINT and SIGTERM |
| 77 | +cleanup() { |
| 78 | + if $CLEANED_UP; then |
| 79 | + return |
| 80 | + fi |
| 81 | + CLEANED_UP=true |
| 82 | + echo "Finished benchmark. Stopping processes..." |
| 83 | + |
| 84 | + # Stop trin sender and receiver |
| 85 | + for PID in "${PIDS[@]}"; do |
| 86 | + if kill -0 "$PID" 2>/dev/null; then |
| 87 | + echo "Killing process with PID $PID..." |
| 88 | + pkill -SIGINT -P "$PID" |
| 89 | + fi |
| 90 | + done |
| 91 | + |
| 92 | + # Wait for trin sender and receiver to finish |
| 93 | + for PID in "${PIDS[@]}"; do |
| 94 | + if kill -0 "$PID" 2>/dev/null; then |
| 95 | + echo "Waiting process with PID $PID..." |
| 96 | + wait "$PID" 2>/dev/null |
| 97 | + fi |
| 98 | + done |
| 99 | + |
| 100 | + # Stop trin-bench process separately |
| 101 | + if kill -0 "$TRIN_BENCH_PID" 2>/dev/null; then |
| 102 | + echo "Stopping trin-bench with PID $TRIN_BENCH_PID..." |
| 103 | + kill -SIGINT "$TRIN_BENCH_PID" |
| 104 | + wait "$TRIN_BENCH_PID" 2>/dev/null |
| 105 | + fi |
| 106 | + |
| 107 | + echo "All processes stopped." |
| 108 | + |
| 109 | + # Remove data directories |
| 110 | + sudo rm -rf "$LOG_DIR/$DATA_DIR_SENDER" "$LOG_DIR/$DATA_DIR_RECEIVER" "$LOG_DIR/trin_sender.perf" "$LOG_DIR/trin_receiver.perf" |
| 111 | +} |
| 112 | + |
| 113 | +# Trap signals |
| 114 | +trap cleanup SIGINT SIGTERM ERR |
| 115 | + |
| 116 | +# Wait for trin-bench to finish |
| 117 | +wait "$TRIN_BENCH_PID" |
| 118 | + |
| 119 | +# unset the trap |
| 120 | +trap - SIGINT SIGTERM ERR |
| 121 | + |
| 122 | +cleanup |
0 commit comments