-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench
executable file
·65 lines (54 loc) · 1.12 KB
/
bench
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
#!/usr/bin/env bash
set -eo pipefail
trap 'kill -TERM -- -$$' SIGINT
export PORT=${PORT:-8080}
echo2() {
>&2 echo "$@"
}
wait_for_server() {
local url="${1}/health"
sleep 1
until curl --output /dev/null --silent --fail "${url}"; do
echo2 "."
sleep 1
done
}
wrk_upload() {
local url="${1}"
wrk \
--threads 12 \
--connections 36 \
--duration 15s \
--script upload.lua \
"${base_url}/upload"
}
wrk_health() {
local url="${1}"
wrk \
--threads 12 \
--connections 400 \
--duration 15s \
"${base_url}/health"
}
bench_server() {
local server_name=${1}
echo ""
echo "${server_name}"
echo "---"
local base_url="http://localhost:${PORT}"
local start_script="./start"
pushd "./servers/${server_name}" > /dev/null
"${start_script}" &
# "${start_script}" > /dev/null 2>&1 &
local server_pid=$!
popd > /dev/null
# Wait for server
wait_for_server "${base_url}" # > /dev/null
wrk_health "${base_url}"
wrk_upload "${base_url}"
# terminate server
pkill -P "${server_pid}" # > /dev/null 2>&1
}
bench_server sanic
bench_server japronto
bench_server werkzeug