-
Notifications
You must be signed in to change notification settings - Fork 4
/
bench-latency.sh
executable file
·67 lines (53 loc) · 1.69 KB
/
bench-latency.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
readonly TOOL="./build/tools/bench-latency"
usage() {
echo "$0 <BINARY-PATH> <HOST-IPV4> <START-PORT> <SERVER-THREADS> <TOOL-THREADS> <TOOL-CONNS> <TOOL-REQS> <TOOL-DELAY> <WARMUP-ROUNDS> <NORMAL-ROUNDS>"
exit 1
}
if [[ $# -ne 10 ]]; then
usage
fi
readonly BINARY_PATH="$1"
readonly HOST_IPV4="$2"
readonly START_PORT="$3"
readonly SERVER_THREADS="$4"
readonly TOOL_THREADS="$5"
readonly TOOL_CONNS="$6"
readonly TOOL_REQS="$7"
readonly TOOL_DELAY="$8"
readonly WARMUP_ROUNDS="$9"
readonly NORMAL_ROUNDS="${10}"
keys=(mean median "q 0.9" "q 0.99" "q 0.999" "q 0.9999")
declare -A total
for key in "${keys[@]}"; do
total["$key"]=0
done
for ((i = 1; i <= $((WARMUP_ROUNDS + NORMAL_ROUNDS)); i++)); do
# Workaround for io_uring bug
PORT=$((START_PORT + i))
# for threads use:
# taskset -c 0-5 "$BINARY_PATH" "$HOST_IPV4" "$PORT" &>/dev/null &
"$BINARY_PATH" "$HOST_IPV4" "$PORT" "$SERVER_THREADS" &>/dev/null &
pid=$!
echo "Created server with pid $pid"
sleep 1
result=$("$TOOL" -w "$TOOL_THREADS" -c "$TOOL_CONNS" -r "$TOOL_REQS" -d "$TOOL_DELAY" "$HOST_IPV4" "$PORT")
if [[ $i -le $WARMUP_ROUNDS ]]; then
echo "$i/$WARMUP_ROUNDS warm up"
else
n=$((i - WARMUP_ROUNDS))
echo "$n/$NORMAL_ROUNDS"
for key in "${keys[@]}"; do
value=$(echo "$result" | grep "$key:" | grep -Eo '[+-]?[0-9]+([.][0-9]+)?' | tail -n1)
total["$key"]=$(echo "${total[$key]}" "$value" | awk '{ printf "%f", $1 + $2 }')
avg=$(echo "${total[$key]}" $n | awk '{ printf "%.02f", $1 / $2 }')
printf "%-12s cur=%-12.f avg=%-12.f\n" "$key:" "$value" "$avg"
done
fi
echo "Killing $pid"
if ! kill $pid; then
echo "Server failed"
exit 1
fi
wait
done