Skip to content

Commit 9d52037

Browse files
committed
feat: add a benchmark tool for aggregator prover
1 parent 37d0390 commit 9d52037

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Debug mode
6+
if [ -v DEBUG ]; then
7+
set -x
8+
fi
9+
10+
# Check if all env vars are set
11+
if [ -z "${AGGREGATOR_ENDPOINT}" ]; then
12+
echo "Missing environment variable: AGGREGATOR_ENDPOINT" >/dev/stderr
13+
exit 1
14+
fi
15+
16+
if [ -z "${TRANSACTIONS_FILE}" ]; then
17+
echo "Missing environment variable: TRANSACTIONS_FILE" >/dev/stderr
18+
exit 1
19+
fi
20+
21+
if [ -z "${TRANSACTIONS_PER_REQUEST_MIN}" ]; then
22+
TRANSACTIONS_PER_REQUEST_MIN=0
23+
fi
24+
25+
if [ -z "${TRANSACTIONS_PER_REQUEST_MAX}" ]; then
26+
TRANSACTIONS_PER_REQUEST_MAX=100
27+
fi
28+
TRANSACTIONS=$(cat $TRANSACTIONS_FILE | tr "\n" " ")
29+
TRANSACTIONS_AVAILABLE=$(echo $TRANSACTIONS | wc -w)
30+
TRANSACTIONS_PER_REQUEST_MAX=$(( TRANSACTIONS_AVAILABLE < TRANSACTIONS_PER_REQUEST_MAX ? TRANSACTIONS_AVAILABLE : TRANSACTIONS_PER_REQUEST_MAX ))
31+
32+
if [ -z "${TRANSACTIONS_PER_REQUEST_STEP}" ]; then
33+
TRANSACTIONS_PER_REQUEST_STEP=5
34+
fi
35+
36+
if [ -z "${AB_TOTAL_REQUESTS}" ]; then
37+
AB_TOTAL_REQUESTS=1000
38+
fi
39+
40+
if [ -z "${AB_CONCURRENCY_MIN}" ]; then
41+
AB_CONCURRENCY_MIN=0
42+
fi
43+
44+
if [ -z "${AB_CONCURRENCY_MAX}" ]; then
45+
AB_CONCURRENCY_MAX=100
46+
fi
47+
48+
if [ -z "${AB_CONCURRENCY_STEP}" ]; then
49+
AB_CONCURRENCY_STEP=10
50+
fi
51+
52+
if [ -z "${AB_TIMEOUT}" ]; then
53+
AB_TIMEOUT=180
54+
fi
55+
56+
if [ -z "${OUT_FILE}" ]; then
57+
OUT_FILE="benchmark.csv"
58+
rm -f $OUT_FILE
59+
echo "Using the default OUT_FILE: $OUT_FILE"
60+
fi
61+
mkdir -p $(dirname "$OUT_FILE")
62+
63+
# Run stress test
64+
RUN_STRESS_TEST() {
65+
AGGREGATOR_ENDPOINT=$1
66+
TRANSACTIONS_PER_REQUEST=$2
67+
TRANSACTIONS_PER_REQUEST=$(( TRANSACTIONS_PER_REQUEST > 0 ? TRANSACTIONS_PER_REQUEST : 1 ))
68+
AB_TOTAL_REQUESTS=$3
69+
AB_CONCURRENCY=$4
70+
AB_CONCURRENCY=$(( AB_CONCURRENCY > 0 ? AB_CONCURRENCY : 0 ))
71+
AB_TOTAL_REQUESTS=$(( AB_TOTAL_REQUESTS > AB_CONCURRENCY ? AB_TOTAL_REQUESTS : AB_CONCURRENCY ))
72+
OUT_FILE=$5
73+
INDEX_RUN=$6
74+
TOTAL_RUN=$7
75+
TRANSACTIONS_FILE=$8
76+
TMP_FILE="test.tmp"
77+
echo ">> [#$INDEX_RUN/$TOTAL_RUN] Running stress test with $AB_TOTAL_REQUESTS requests with $TRANSACTIONS_PER_REQUEST transactions per request and $AB_CONCURRENCY concurrency"
78+
TRANSACTIONS_LIST=$(head -n $TRANSACTIONS_PER_REQUEST $TRANSACTIONS_FILE | tr "\n" ",")
79+
AGGREGATOR_PROVER_URL="$AGGREGATOR_ENDPOINT/proof/cardano-transaction?transaction_hashes=$TRANSACTIONS_LIST"
80+
if $(ab -n $AB_TOTAL_REQUESTS -c $AB_CONCURRENCY -s $AB_TIMEOUT $AGGREGATOR_PROVER_URL > $TMP_FILE) ; then
81+
REQUESTS_PER_SECOND=$(cat $TMP_FILE | awk '/Requests per second:/ {print $4}')
82+
if [[ $INDEX_RUN -eq 1 ]] ; then
83+
echo "total_requests,concurrency,transactions/request,requests/s" >> $OUT_FILE
84+
fi
85+
echo "$AB_TOTAL_REQUESTS,$AB_CONCURRENCY,$TRANSACTIONS_PER_REQUEST,$REQUESTS_PER_SECOND" >> $OUT_FILE
86+
echo ">>>> Success ($REQUESTS_PER_SECOND requests/s)"
87+
else
88+
echo ">>>> Failure"
89+
exit
90+
fi
91+
rm -f $TMP_FILE
92+
echo ""
93+
}
94+
95+
# Run aggregator benchmark over a range of transactions and concurrency levels
96+
TRANSACTIONS_PER_REQUEST_RANGE=$(seq -s ' ' $TRANSACTIONS_PER_REQUEST_MIN $TRANSACTIONS_PER_REQUEST_STEP $TRANSACTIONS_PER_REQUEST_MAX)
97+
AB_CONCURRENCY_RANGE=$(seq -s ' ' $AB_CONCURRENCY_MIN $AB_CONCURRENCY_STEP $AB_CONCURRENCY_MAX)
98+
TRANSACTIONS_PER_REQUEST_RANGE_LENGTH=$(( $(echo $TRANSACTIONS_PER_REQUEST_RANGE | grep -o " " | wc -l) + 1 ))
99+
AB_CONCURRENCY_RANGE_LENGTH=$(( $(echo $AB_CONCURRENCY_RANGE | grep -o " " | wc -l) + 1 ))
100+
TOTAL_RUN=$(( $TRANSACTIONS_PER_REQUEST_RANGE_LENGTH * $AB_CONCURRENCY_RANGE_LENGTH ))
101+
echo ""
102+
echo "Run aggregator prover benchmark with:"
103+
echo ">> Aggregator endpoint: [$AGGREGATOR_ENDPOINT]"
104+
echo ">> Transactions file: [$TRANSACTIONS_FILE]"
105+
echo ">> Transactions available: [$TRANSACTIONS_AVAILABLE]"
106+
echo ">> Transactions per request range: [$TRANSACTIONS_PER_REQUEST_RANGE]"
107+
echo ">> AB concurrency range: [$AB_CONCURRENCY_RANGE]"
108+
echo ">> AB total requests per run: [$AB_TOTAL_REQUESTS]"
109+
echo ">> AB total runs: [$TOTAL_RUN]"
110+
echo ">> Output file: [$OUT_FILE]"
111+
echo ""
112+
113+
INDEX_RUN=1
114+
for TRANSACTIONS_PER_REQUEST in $TRANSACTIONS_PER_REQUEST_RANGE; do
115+
for AB_CONCURRENCY in $AB_CONCURRENCY_RANGE; do
116+
RUN_STRESS_TEST $AGGREGATOR_ENDPOINT $TRANSACTIONS_PER_REQUEST $AB_TOTAL_REQUESTS $AB_CONCURRENCY $OUT_FILE $INDEX_RUN $TOTAL_RUN $TRANSACTIONS_FILE
117+
INDEX_RUN=$(( ${INDEX_RUN} + 1))
118+
done
119+
done
120+
121+
echo ">> Benchmark completed:"
122+
echo ""
123+
cat $OUT_FILE
124+
125+

0 commit comments

Comments
 (0)