-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
run.sh
executable file
·155 lines (117 loc) · 3.74 KB
/
run.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#! /bin/bash -x
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
if [ -n "$1" ]; then
worker_cnt=$1
else
worker_cnt=1
fi
if [ -n "$2" ]; then
upstream_cnt=$2
else
upstream_cnt=1
fi
mkdir -p benchmark/server/logs
mkdir -p benchmark/fake-apisix/logs
make init
fake_apisix_cmd="openresty -p $PWD/benchmark/fake-apisix -c $PWD/benchmark/fake-apisix/conf/nginx.conf"
server_cmd="openresty -p $PWD/benchmark/server -c $PWD/benchmark/server/conf/nginx.conf"
trap 'onCtrlC' INT
function onCtrlC () {
sudo killall wrk
sudo killall openresty
sudo ${fake_apisix_cmd} -s stop || exit 1
sudo ${server_cmd} -s stop || exit 1
}
for up_cnt in $(seq 1 $upstream_cnt);
do
port=$((1979+$up_cnt))
nginx_listen=$nginx_listen"listen $port;"
upstream_nodes=$upstream_nodes"\"127.0.0.1:$port\":1"
if [ $up_cnt -lt $upstream_cnt ]; then
upstream_nodes=$upstream_nodes","
fi
done
sed -i "s/\- proxy-mirror/#\- proxy-mirror/g" conf/config-default.yaml
sed -i "s/\- proxy-cache/#\- proxy-cache/g" conf/config-default.yaml
sed -i "s/listen .*;/$nginx_listen/g" benchmark/server/conf/nginx.conf
echo "
nginx_config:
worker_processes: ${worker_cnt}
" > conf/config.yaml
sudo ${server_cmd} || exit 1
make run
sleep 3
#############################################
echo -e "\n\napisix: $worker_cnt worker + $upstream_cnt upstream + no plugin"
admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g')
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '
{
"uri": "/hello",
"plugins": {
},
"upstream": {
"type": "roundrobin",
"nodes": {
'$upstream_nodes'
}
}
}'
sleep 1
wrk -d 5 -c 16 http://127.0.0.1:9080/hello
sleep 1
wrk -d 5 -c 16 http://127.0.0.1:9080/hello
sleep 1
#############################################
echo -e "\n\napisix: $worker_cnt worker + $upstream_cnt upstream + 2 plugins (limit-count + prometheus)"
admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g')
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '
{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2000000000000,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr"
},
"prometheus": {}
},
"upstream": {
"type": "roundrobin",
"nodes": {
'$upstream_nodes'
}
}
}'
sleep 3
wrk -d 5 -c 16 http://127.0.0.1:9080/hello
sleep 1
wrk -d 5 -c 16 http://127.0.0.1:9080/hello
sleep 1
make stop
#############################################
echo -e "\n\nfake empty apisix server: $worker_cnt worker"
sleep 1
sed -i "s/worker_processes [0-9]*/worker_processes $worker_cnt/g" benchmark/fake-apisix/conf/nginx.conf
sudo ${fake_apisix_cmd} || exit 1
sleep 1
wrk -d 5 -c 16 http://127.0.0.1:9080/hello
sleep 1
wrk -d 5 -c 16 http://127.0.0.1:9080/hello
sudo ${fake_apisix_cmd} -s stop || exit 1
sudo ${server_cmd} -s stop || exit 1