Skip to content

Commit ff6f86a

Browse files
committed
Compression benchmark script
1 parent e1a21dd commit ff6f86a

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

tests/tools/benchmark/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Tools for benchmarking
2+
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/bash
2+
#
3+
4+
set -e
5+
6+
outdir=$1
7+
brokers=$2
8+
topic=$3
9+
10+
msgcnt=5000000
11+
msgsize=100
12+
modes=(batch streaming)
13+
codecs=(none gzip snappy lz4 zstd)
14+
#codecs=(none lz4)
15+
16+
function show_summary() {
17+
echo -e "Benchmark results for $outdir:\n"
18+
cat $outdir/info
19+
20+
local csv="$outdir/summary.csv"
21+
22+
echo ""
23+
printf "%-10s %-7s %6s %10s %6s %7s %5s %5s %5s %8s %8s %5s\n" \
24+
"Mode" "Codec" "Ratio" "Msgs/Batch" "MB/s" "Msgs/s" \
25+
"Elaps" "Sys" "User" "ICtx" "VCtx" "RSS"
26+
echo "==================================================================================================="
27+
28+
echo "Mode&Codec" "Ratio" "Msgs/Batch" "MB/s" "Msgs/s" \
29+
"Elaps" "Sys" "User" "ICtx" "VCtx" "RSS" "Extra" | tr ' ' ',' > $csv
30+
31+
32+
local -A res
33+
local codec=
34+
for codec in ${codecs[@]}; do
35+
local mode=
36+
for mode in ${modes[@]}; do
37+
local f=$outdir/stats_${mode}_${codec}.json
38+
local bn=$(basename $f)
39+
bn=${bn%.json}
40+
local name=${bn#stats_}
41+
local extra=""
42+
43+
local ratio=$(jq .ratio $f | tail -1)
44+
local batchcnt=$(jq .batchcnt $f | tail -1)
45+
local mbrate=$(egrep -io '[0-9.]+ MB/s' $outdir/out_${name} | tail -1 | awk '{print $1}')
46+
local msgrate=$(egrep -io '[0-9.]+ msgs/s' $outdir/out_${name} | tail -1 | awk '{print $1}')
47+
48+
local -A times
49+
local kv=
50+
for kv in $(cat $outdir/time_${mode}_${codec}); do
51+
local k=${kv%=*}
52+
local v=${kv#*=}
53+
times[$k]=$v
54+
done
55+
56+
res[$name]=$mbrate
57+
if [[ $mode == streaming ]]; then
58+
local prev=${res[batch_${codec}]}
59+
#echo "compare $prev to $mbrate"
60+
local diff=$(echo "scale=2; ($mbrate / $prev * 100.0) - 100.0" | bc -l)
61+
if [[ $diff != -* ]]; then
62+
diff=+$diff
63+
fi
64+
extra="$diff% MB/s"
65+
fi
66+
67+
printf "%-10s %-6s %6sx %10s %6s %7s %5s %5s %5s %8s %8s %5s %s\n" \
68+
$mode $codec $ratio $batchcnt $mbrate $msgrate \
69+
${times[e]} ${times[S]} ${times[U]} ${times[c]} \
70+
${times[w]} "${times[M]}" \
71+
"$extra"
72+
73+
echo $mode $codec, $ratio, $batchcnt, $mbrate, $msgrate, \
74+
${times[e]}, ${times[S]}, ${times[U]}, ${times[c]}, \
75+
${times[w]}, ${times[M]}, \
76+
"$extra" >> $csv
77+
done
78+
done
79+
}
80+
81+
if [[ -z $outdir ]]; then
82+
echo "Usage: $0 <report-dir> [<brokers> <topic>]"
83+
exit 1
84+
fi
85+
86+
if [[ -f $outdir/info ]]; then
87+
if [[ -n $brokers ]]; then
88+
echo "$0: report directory $outdir already exists"
89+
exit 1
90+
fi
91+
show_summary
92+
exit 0
93+
fi
94+
95+
if [[ -z $topic ]]; then
96+
echo "Usage: $0 <report-dir> [<brokers> <topic>]"
97+
exit 1
98+
fi
99+
100+
if [[ ! -x examples/rdkafka_performance ]]; then
101+
echo "$0: this tool needs to be run from the librdkafka top level directory"
102+
exit 1
103+
fi
104+
105+
mkdir -p "$outdir"
106+
107+
set -u
108+
109+
110+
version=$(examples/rdkafka_performance -h 2>&1 | grep librdkafka.version)
111+
112+
cat >$outdir/info <<EOF
113+
version=$version
114+
msgcnt=$msgcnt
115+
msgsize=$msgsize
116+
EOF
117+
118+
echo "$version"
119+
120+
# Prime topic with a single message to avoid auto-creation costs in benchmarks.
121+
echo "Priming topic $topic"
122+
examples/rdkafka_performance -b $brokers -P -t "$topic" -p 0 -c 1 -q
123+
124+
function run_benchmark() {
125+
local mode=
126+
for mode in ${modes[@]}; do
127+
if [[ $mode == streaming ]]; then
128+
streamconf=true
129+
else
130+
streamconf=false
131+
fi
132+
133+
local codec=
134+
for codec in ${codecs[@]}; do
135+
echo "Start: $mode $codec"
136+
137+
statsfile="$outdir/stats_${mode}_${codec}.json"
138+
139+
$(which time) \
140+
-o $outdir/time_${mode}_${codec} \
141+
-f 'F=%F S=%S U=%U c=%c e=%e r=%r s=%s w=%w t=%t M=%M' \
142+
examples/rdkafka_performance \
143+
-b $brokers \
144+
-X test.mock.num.brokers=3 \
145+
-X test.mock.broker.rtt=200 \
146+
-P \
147+
-a 1 \
148+
-t "$topic" \
149+
-p 0 \
150+
-c $msgcnt \
151+
-s $msgsize \
152+
-S 1231241245 \
153+
-T 1000 \
154+
-Y "tee $outdir/all_stats.json | jq '.topics[] | {batchcnt: .batchcnt.p99, ratio: (.batchcompratio.p99 / 100.0)'} > $statsfile" \
155+
-X linger.ms=1000 \
156+
-X batch.num.messages=1000000 \
157+
-X enable.streaming.compression=$streamconf \
158+
-z $codec > "$outdir/out_${mode}_${codec}"
159+
done
160+
161+
done
162+
}
163+
164+
run_benchmark
165+
166+
show_summary

0 commit comments

Comments
 (0)