Skip to content
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: add benchmark for trin #1660

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ jobs:
# parallelism level should be set to the amount of simulators we have or greater
# The reason for this is the CI code currently only supports 1 input at a time
# if we have a parallelism level of 5 and 6 sims one test runner will get 2 test sims and fail
parallelism: 19
parallelism: 20
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
.vscode/
# Ignore downloaded consensus specs test data
testing/ef-tests/mainnet*

bin/trin-bench/logs*
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]
members = [
"bin/portal-bridge",
"bin/trin",
"bin/trin",
"bin/trin-bench",
"bin/trin-execution",
"crates/ethportal-api",
"crates/e2store",
Expand All @@ -15,7 +16,7 @@ members = [
"crates/subnetworks/history",
"crates/subnetworks/state",
"crates/utils",
"crates/validation",
"crates/validation",
"testing/ef-tests",
"testing/ethportal-peertest",
"testing/utp",
Expand Down Expand Up @@ -120,3 +121,8 @@ trin-validation = { path = "crates/validation" }
#
# See: https://github.com/eira-fransham/crunchy/issues/13
crunchy = "=0.2.2"


[profile.profiling]
inherits = "release"
debug = true
29 changes: 29 additions & 0 deletions bin/trin-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "trin-bench"
authors.workspace = true
categories.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
anyhow.workspace = true
clap.workspace = true
ethportal-api.workspace = true
e2store.workspace = true
futures.workspace = true
humanize-duration.workspace = true
jsonrpsee.workspace = true
portal-bridge.workspace = true
reqwest.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
trin-execution.workspace = true
trin-utils.workspace = true
trin-validation.workspace = true
url.workspace = true
7 changes: 7 additions & 0 deletions bin/trin-bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
@echo "Running Trin Bench"
@./run-bench.sh
@echo "Down running Trin Bench"

clean:
sudo rm -r logs
16 changes: 16 additions & 0 deletions bin/trin-bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Trin Bench
Trin bench is for testing Trin performance and being able to recreate situations reliably to verify if performance improvements or regressions happen

## To run
```sh
make run
```

## Clean results
```sh
make clean
```

## View the results

The results will be available in the logs folder. After running the test there will be 2 svg's containing flamegraphs `trin_sender.svg` and `trin_receiver.svg`, please open in it a web browser for the best experience.
126 changes: 126 additions & 0 deletions bin/trin-bench/run-bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash

# Define log directories
LOG_DIR="logs"
mkdir -p "$LOG_DIR"

# Create data directories for trin instances
DATA_DIR_SENDER="./data_sender"
DATA_DIR_RECEIVER="./data_receiver"
mkdir -p "$LOG_DIR/$DATA_DIR_SENDER" "$LOG_DIR/$DATA_DIR_RECEIVER"

# Clone portal-accumulators repository if not already present
if [ ! -d "../../portal-accumulators" ]; then
git clone https://github.com/ethereum/portal-accumulators ../../portal-accumulators || { echo "Failed to clone portal-accumulators"; exit 1; }
fi

# Build trin-benchmark-cordinator with release profile
pushd ../.. || { echo "Failed to change directory"; exit 1; }
cargo build --release -p trin || { echo "Failed to build trin"; exit 1; }
cargo build --release -p trin-bench || { echo "Failed to build trin-benchmark-cordinator"; exit 1; }
popd || { echo "Failed to return to original directory"; exit 1; }

# Define process PIDs
PIDS=()

# Find available ports dynamically and ensure they are unique
find_unused_port() {
local port=$1
while ss -tuln | awk '{print $4}' | grep -q ":$port$"; do
port=$((port + 1))
done
echo $port
}

PORT_SENDER=$(find_unused_port 9050)
PORT_RECEIVER=$(find_unused_port $((PORT_SENDER + 10)))
EXT_PORT_SENDER=$(find_unused_port 9100)
EXT_PORT_RECEIVER=$(find_unused_port $((EXT_PORT_SENDER + 10)))

# Run trin sender with perf profiling
# cargo flamegraph --profile release -c "record -F 997 --call-graph dwarf,64000 -g -o $LOG_DIR/trin_sender.perf" --release --output "$LOG_DIR/trin_sender.svg" -p trin -- \
../../target/release/trin \
--web3-transport http \
--web3-http-address http://127.0.0.1:$PORT_SENDER/ \
--mb 0 \
--bootnodes none \
--external-address 127.0.0.1:$EXT_PORT_SENDER \
--discovery-port $EXT_PORT_SENDER \
--data-dir "$LOG_DIR/$DATA_DIR_SENDER" \
> "$LOG_DIR/trin_sender.log" 2>&1 &
PIDS+=("$!")

# Run trin receiver with perf profiling
# cargo flamegraph --profile release -c "record -F 997 --call-graph dwarf,64000 -g -o $LOG_DIR/trin_receiver.perf" --release --output "$LOG_DIR/trin_receiver.svg" -p trin -- \
../../target/release/trin \
--web3-transport http \
--web3-http-address http://127.0.0.1:$PORT_RECEIVER/ \
--mb 10000 \
--bootnodes none \
--external-address 127.0.0.1:$EXT_PORT_RECEIVER \
--discovery-port $EXT_PORT_RECEIVER \
--data-dir "$LOG_DIR/$DATA_DIR_RECEIVER" \
> "$LOG_DIR/trin_receiver.log" 2>&1 &
PIDS+=("$!")

# Run trin benchmark coordinator without perf profiling
../../target/release/trin-bench \
--web3-http-address-node-1 http://127.0.0.1:$PORT_SENDER/ \
--web3-http-address-node-2 http://127.0.0.1:$PORT_RECEIVER/ \
--epoch-accumulator-path ../../portal-accumulators \
--start-era1 1000 \
--end-era1 1010 \
> "$LOG_DIR/trin_benchmark.log" 2>&1 &
TRIN_BENCH_PID=$!

echo "Started Benchmark"

CLEANED_UP=false
# Function to clean up processes on SIGINT and SIGTERM
cleanup() {
if $CLEANED_UP; then
return
fi
CLEANED_UP=true
echo "Finished benchmark. Stopping processes..."

# Stop trin sender and receiver
for PID in "${PIDS[@]}"; do
if kill -0 "$PID" 2>/dev/null; then
echo "Killing process with PID $PID..."
kill -SIGINT "$PID"
pkill -SIGINT -P "$PID"
fi
done

# Wait for trin sender and receiver to finish
for PID in "${PIDS[@]}"; do
if kill -0 "$PID" 2>/dev/null; then
echo "Waiting process with PID $PID..."
wait "$PID" 2>/dev/null
fi
done

# Stop trin-bench process separately
if kill -0 "$TRIN_BENCH_PID" 2>/dev/null; then
echo "Stopping trin-bench with PID $TRIN_BENCH_PID..."
kill -SIGINT "$TRIN_BENCH_PID"
wait "$TRIN_BENCH_PID" 2>/dev/null
fi

echo "All processes stopped."

# Remove data directories
sudo rm -rf "$LOG_DIR/$DATA_DIR_SENDER" "$LOG_DIR/$DATA_DIR_RECEIVER" "$LOG_DIR/trin_sender.perf" "$LOG_DIR/trin_receiver.perf"
}

# Trap signals
trap cleanup SIGINT SIGTERM ERR

# Wait for trin-bench to finish
wait "$TRIN_BENCH_PID"

# unset the trap
trap - SIGINT SIGTERM ERR

cleanup
43 changes: 43 additions & 0 deletions bin/trin-bench/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::path::PathBuf;

use clap::Parser;
use url::Url;

pub const APP_NAME: &str = "trin-bench";
const DEFAULT_EPOCH_ACC_PATH: &str = "./portal-accumulators";

#[derive(Parser, Debug, Clone)]
#[command(
name = "Trin Bench",
about = "Benchmarks sending blocks from one trin client to another"
)]
pub struct TrinBenchConfig {
#[arg(
long = "web3-http-address-node-1",
help = "address to accept json-rpc http connections"
)]
pub web3_http_address_node_1: Url,

#[arg(
long = "web3-http-address-node-2",
help = "address to accept json-rpc http connections"
)]
pub web3_http_address_node_2: Url,

#[arg(
long,
help = "The first era to start sending blocks from",
default_value = "1"
)]
pub start_era1: u16,

#[arg(long, help = "The last era to send blocks from", default_value = "5")]
pub end_era1: u16,

#[arg(
long = "epoch-accumulator-path",
help = "Path to epoch accumulator repo for bridge mode",
default_value = DEFAULT_EPOCH_ACC_PATH
)]
pub epoch_acc_path: PathBuf,
}
1 change: 1 addition & 0 deletions bin/trin-bench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod cli;
Loading