-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbenchmark.sh
executable file
·77 lines (64 loc) · 1.9 KB
/
benchmark.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
73
74
75
76
77
#!/bin/bash
CONTAINER=
STATS_PID=
IP=
PORT=9808
CONNECTIONS=(100 200 300 400 500 600 700 800 900 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000)
BASE=$1
ulimit -n 10240
function start() {
local id=$1
shift
echo "Starting $id ($*)"
CONTAINER=$(docker run --detach --memory 512MB --cpuset-cpus 0,1 --workdir /home/www/wsgi_benchmark -p $PORT:$PORT wsgi_benchmark "$@")
while true; do
echo " Waiting for container ..."
IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$CONTAINER")
result=$(curl --silent "http://$IP:$PORT")
if [[ "$result" == "OK" ]]; then
break
fi
sleep 1
done
}
function stop() {
echo " Shutting down $1 ..."
docker kill "$CONTAINER"
}
function perf() {
docker stats > "$BASE/$1.$2.stats" &
STATS_PID=$!
echo " Testing $1 with $2 connections ..."
taskset -c 2,3 wrk --duration 30s --threads 4 --connections "$2" "http://$IP:$PORT" > "$BASE/$1.$2.log"
sleep 1
kill $STATS_PID
}
# Install docker image (if needed)
docker inspect wsgi_benchmark > /dev/null 2>&1
[ $? -gt 0 ] && docker build -t wsgi_benchmark:latest .
for connections in "${CONNECTIONS[@]}"; do
for server in $(find src/* | shuf); do
filename=$(basename "$server")
base="${filename%.*}"
ext="${filename##*.}"
case "$ext" in
py|pyc)
# ignore, this is the base application that the WSGI servers wrap around
continue
;;
wsgi)
start "$base" python "$filename"
;;
sh)
start "$base" bash "$filename"
;;
*)
echo "!! Unknown file type: $filename !!"
continue
;;
esac
perf "$base" "$connections"
stop "$base"
sleep 1
done
done