Skip to content

Commit 0d8c413

Browse files
committed
feat: add benchmark for trin
1 parent 9c13906 commit 0d8c413

File tree

11 files changed

+487
-4
lines changed

11 files changed

+487
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ jobs:
235235
# parallelism level should be set to the amount of simulators we have or greater
236236
# The reason for this is the CI code currently only supports 1 input at a time
237237
# if we have a parallelism level of 5 and 6 sims one test runner will get 2 test sims and fail
238-
parallelism: 19
238+
parallelism: 20
239239
steps:
240240
- checkout
241241
- run:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
.vscode/
88
# Ignore downloaded consensus specs test data
99
testing/ef-tests/mainnet*
10-
10+
bin/trin-bench/logs

Cargo.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[workspace]
22
members = [
33
"bin/portal-bridge",
4-
"bin/trin",
4+
"bin/trin",
5+
"bin/trin-bench",
56
"bin/trin-execution",
67
"crates/ethportal-api",
78
"crates/e2store",
@@ -15,7 +16,7 @@ members = [
1516
"crates/subnetworks/history",
1617
"crates/subnetworks/state",
1718
"crates/utils",
18-
"crates/validation",
19+
"crates/validation",
1920
"testing/ef-tests",
2021
"testing/ethportal-peertest",
2122
"testing/utp",
@@ -120,3 +121,18 @@ trin-validation = { path = "crates/validation" }
120121
#
121122
# See: https://github.com/eira-fransham/crunchy/issues/13
122123
crunchy = "=0.2.2"
124+
125+
[profile.release]
126+
opt-level = 3
127+
lto = "thin"
128+
debug = "none"
129+
strip = "symbols"
130+
panic = "unwind"
131+
codegen-units = 16
132+
133+
# Use the `--profile profiling` flag to show symbols in release mode.
134+
# e.g. `cargo build --profile profiling`
135+
[profile.profiling]
136+
inherits = "release"
137+
debug = "full"
138+
strip = "none"

bin/trin-bench/Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "trin-bench"
3+
authors.workspace = true
4+
categories.workspace = true
5+
edition.workspace = true
6+
keywords.workspace = true
7+
license.workspace = true
8+
readme.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
version.workspace = true
12+
13+
[dependencies]
14+
anyhow.workspace = true
15+
clap.workspace = true
16+
ethportal-api.workspace = true
17+
e2store.workspace = true
18+
futures.workspace = true
19+
humanize-duration.workspace = true
20+
jsonrpsee.workspace = true
21+
portal-bridge.workspace = true
22+
reqwest.workspace = true
23+
tokio.workspace = true
24+
tracing.workspace = true
25+
tracing-subscriber.workspace = true
26+
trin-execution.workspace = true
27+
trin-utils.workspace = true
28+
trin-validation.workspace = true
29+
url.workspace = true

bin/trin-bench/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test:
2+
@echo "Running Trin Bench"
3+
@./run-bench.sh
4+
@echo "Down running Trin Bench"
5+
6+
clean:
7+
sudo rm -r logs

bin/trin-bench/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Trin Bench
2+
Trin bench is for testing Trin performance and being able to recreate situations reliably to verify if performance improvements or regressions happen
3+
4+
## To run
5+
```sh
6+
make run
7+
```
8+
9+
## Clean results
10+
```sh
11+
make clean
12+
```
13+
14+
## View the results
15+
16+
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.

bin/trin-bench/run-bench.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

bin/trin-bench/src/cli.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::path::PathBuf;
2+
3+
use clap::Parser;
4+
use url::Url;
5+
6+
pub const APP_NAME: &str = "trin-bench";
7+
const DEFAULT_EPOCH_ACC_PATH: &str = "./portal-accumulators";
8+
9+
#[derive(Parser, Debug, Clone)]
10+
#[command(
11+
name = "Trin Bench",
12+
about = "Benchmarks sending blocks from one trin client to another"
13+
)]
14+
pub struct TrinBenchConfig {
15+
#[arg(
16+
long = "web3-http-address-node-1",
17+
help = "address to accept json-rpc http connections"
18+
)]
19+
pub web3_http_address_node_1: Url,
20+
21+
#[arg(
22+
long = "web3-http-address-node-2",
23+
help = "address to accept json-rpc http connections"
24+
)]
25+
pub web3_http_address_node_2: Url,
26+
27+
#[arg(
28+
long,
29+
help = "The first era to start sending blocks from",
30+
default_value = "1"
31+
)]
32+
pub start_era1: u16,
33+
34+
#[arg(long, help = "The last era to send blocks from", default_value = "5")]
35+
pub end_era1: u16,
36+
37+
#[arg(
38+
long = "epoch-accumulator-path",
39+
help = "Path to epoch accumulator repo for bridge mode",
40+
default_value = DEFAULT_EPOCH_ACC_PATH
41+
)]
42+
pub epoch_acc_path: PathBuf,
43+
}

bin/trin-bench/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod cli;

0 commit comments

Comments
 (0)