forked from LesnyRumcajs/grpc_bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.sh
executable file
·72 lines (62 loc) · 2.42 KB
/
bench.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
68
69
70
71
72
#!/bin/sh
## The list of benchmarks to run
BENCHMARKS_TO_RUN="${@}"
## ...or use all the *_bench dirs by default
BENCHMARKS_TO_RUN="${BENCHMARKS_TO_RUN:-$(find . -maxdepth 1 -name '*_bench' -type d | sort)}"
RESULTS_DIR="results/$(date '+%y%d%mT%H%M%S')"
GRPC_BENCHMARK_DURATION=${GRPC_BENCHMARK_DURATION:-"30s"}
GRPC_SERVER_CPUS=${GRPC_SERVER_CPUS:-"1"}
GRPC_SERVER_RAM=${GRPC_SERVER_RAM:-"512m"}
GRPC_CLIENT_CONNECTIONS=${GRPC_CLIENT_CONNECTIONS:-"50"}
GRPC_CLIENT_CONCURRENCY=${GRPC_CLIENT_CONCURRENCY:-"1000"}
GRPC_CLIENT_QPS=${GRPC_CLIENT_QPS:-"0"}
GRPC_CLIENT_QPS=$(( GRPC_CLIENT_QPS / GRPC_CLIENT_CONCURRENCY ))
GRPC_CLIENT_CPUS=${GRPC_CLIENT_CPUS:-"1"}
GRPC_REQUEST_PAYLOAD=${GRPC_REQUEST_PAYLOAD:-"100B"}
# Let containers know how many CPUs they will be running on
export GRPC_SERVER_CPUS
export GRPC_CLIENT_CPUS
docker pull infoblox/ghz:0.0.1
for benchmark in ${BENCHMARKS_TO_RUN}; do
NAME="${benchmark##*/}"
echo "==> Running benchmark for ${NAME}..."
mkdir -p "${RESULTS_DIR}"
docker run --name "${NAME}" --rm \
--cpus "${GRPC_SERVER_CPUS}" \
--memory "${GRPC_SERVER_RAM}" \
-e GRPC_SERVER_CPUS \
--network=host --detach --tty "${NAME}" >/dev/null
sleep 5
./collect_stats.sh "${NAME}" "${RESULTS_DIR}" &
docker run --name ghz --rm --network=host -v "${PWD}/proto:/proto:ro"\
-v "${PWD}/payload:/payload:ro"\
--cpus $GRPC_CLIENT_CPUS \
--entrypoint=ghz infoblox/ghz:0.0.1 \
--proto=/proto/helloworld/helloworld.proto \
--call=helloworld.Greeter.SayHello \
--insecure \
--concurrency="${GRPC_CLIENT_CONCURRENCY}" \
--connections="${GRPC_CLIENT_CONNECTIONS}" \
--qps="${GRPC_CLIENT_QPS}" \
--duration "${GRPC_BENCHMARK_DURATION}" \
--data-file /payload/"${GRPC_REQUEST_PAYLOAD}" \
127.0.0.1:50051 >"${RESULTS_DIR}/${NAME}".report
cat "${RESULTS_DIR}/${NAME}".report | grep "Requests/sec" | sed -E 's/^ +/ /'
kill -INT %1 2>/dev/null
docker container stop "${NAME}" >/dev/null
done
tee $RESULTS_DIR/bench.info <<EOF
Benchmark info:
$(git log -1 --pretty="%h %cD %cn %s")
Benchmarks run: $BENCHMARKS_TO_RUN
GRPC_BENCHMARK_DURATION=$GRPC_BENCHMARK_DURATION
GRPC_SERVER_CPUS=$GRPC_SERVER_CPUS
GRPC_SERVER_RAM=$GRPC_SERVER_RAM
GRPC_CLIENT_CONNECTIONS=$GRPC_CLIENT_CONNECTIONS
GRPC_CLIENT_CONCURRENCY=$GRPC_CLIENT_CONCURRENCY
GRPC_CLIENT_QPS=$GRPC_CLIENT_QPS
GRPC_CLIENT_CPUS=$GRPC_CLIENT_CPUS
GRPC_REQUEST_PAYLOAD=$GRPC_REQUEST_PAYLOAD
EOF
sh analyze.sh $RESULTS_DIR
echo "All done."