forked from apache/apisix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: added benchmark scripts. (apache#188)
* benchmark: added benchmark scripts. * feature: added fake apisix, compare the result with this fake apisix server.
- Loading branch information
Showing
8 changed files
with
374 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ luac.out | |
*.hex | ||
|
||
# develop | ||
logs/*.log | ||
logs/*.pid | ||
*.log | ||
*.pid | ||
t/servroot | ||
go | ||
\.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIEojCCAwqgAwIBAgIJAK253pMhgCkxMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV | ||
BAYTAkNOMRIwEAYDVQQIDAlHdWFuZ0RvbmcxDzANBgNVBAcMBlpodUhhaTEPMA0G | ||
A1UECgwGaXJlc3R5MREwDwYDVQQDDAh0ZXN0LmNvbTAgFw0xOTA2MjQyMjE4MDVa | ||
GA8yMTE5MDUzMTIyMTgwNVowVjELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5n | ||
RG9uZzEPMA0GA1UEBwwGWmh1SGFpMQ8wDQYDVQQKDAZpcmVzdHkxETAPBgNVBAMM | ||
CHRlc3QuY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAyCM0rqJe | ||
cvgnCfOw4fATotPwk5Ba0gC2YvIrO+gSbQkyxXF5jhZB3W6BkWUWR4oNFLLSqcVb | ||
VDPitz/Mt46Mo8amuS6zTbQetGnBARzPLtmVhJf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Ej42hA79MuX64lMSCVQSjX+ipR289GQZqFrIhiJxLyA+Ve | ||
U/OOcSRr39Kuis/JJ+DkgHYa/PWHZhnJQBxcqXXk1bJGw9BNbhM= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIG5AIBAAKCAYEAyCM0rqJecvgnCfOw4fATotPwk5Ba0gC2YvIrO+gSbQkyxXF5 | ||
jhZB3W6BkWUWR4oNFLLSqcVbVDPitz/Mt46Mo8amuS6zTbQetGnBARzPLtmVhJfo | ||
eLj0efMiOepOSZflj9Ob4yKR2bGdEFOdHPjm+4ggXU9jMKeLqdVvxll/JiVFBW5s | ||
mPtW1Oc/BV5terhscJdOgmRrabf9xiIis9/qVYfyGn52u9452V0owUuwP7nZ01jt | ||
6iMWEGeQU6mwPENgvj1olji2WjdG2UwpUVp3jp3l7j1ekQ6mI0F7yI+LeHzfUwiy | ||
Vt1TmtMWn1ztk6FfLRqwJWR/Evm95vnfS3Le4S2ky3XAgn2UnCMyej3wDN6qHR1o | ||
npRVeXhrBajbCRDRBMwaNw/1/3Uvza8QKK10PzQR6OcQ0xo9psMkd9j9ts/dTuo2 | ||
fzaqpIfyUbPST4GdqNG9NyIh/B9g26/0EWcjyO7mYVkaycrtLMaXm1u9jyRmcQQI | ||
1cGrGwyXbrieNp63AgMBAAECggGBAJM8g0duoHmIYoAJzbmKe4ew0C5fZtFUQNmu | ||
O2xJITUiLT3ga4LCkRYsdBnY+nkK8PCnViAb10KtIT+bKipoLsNWI9Xcq4Cg4G3t | ||
11XQMgPPgxYXA6m8t+73ldhxrcKqgvI6xVZmWlKDPn+CY/Wqj5PA476B5wEmYbNC | ||
GIcd1FLl3E9Qm4g4b/sVXOHARF6iSvTR+6ol4nfWKlaXSl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jDuwV0sPXjzJxL7NpR/fHwgndgyPcI14y2cGz | ||
zMC44EyQdTw+B/YfMnoZx83xaaMNMqV6GYNnTHi0TO2TAoHBAKmdrh9WkE2qsr59 | ||
IoHHygh7Wzez+Ewr6hfgoEK4+QzlBlX+XV/9rxIaE0jS3Sk1txadk5oFDebimuSk | ||
lQkv1pXUOqh+xSAwk5v88dBAfh2dnnSa8HFN3oz+ZfQYtnBcc4DR1y2X+fVNgr3i | ||
nxruU2gsAIPFRnmvwKPc1YIH9A6kIzqaoNt1f9VM243D6fNzkO4uztWEApBkkJgR | ||
4s/yOjp6ovS9JG1NMXWjXQPcwTq3sQVLnAHxZRJmOvx69UmK4QKBwFYXXjeXiU3d | ||
bcrPfe6qNGjfzK+BkhWznuFUMbuxyZWDYQD5yb6ukUosrj7pmZv3BxKcKCvmONU+ | ||
CHgIXB+hG+R9S2mCcH1qBQoP/RSm+TUzS/Bl2UeuhnFZh2jSZQy3OwryUi6nhF0u | ||
LDzMI/6aO1ggsI23Ri0Y9ZtqVKczTkxzdQKR9xvoNBUufjimRlS80sJCEB3Qm20S | ||
wzarryret/7GFW1/3cz+hTj9/d45i25zArr3Pocfpur5mfz3fJO8jg== | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[req] | ||
distinguished_name = req_distinguished_name | ||
x509_extensions = v3_req | ||
prompt = no | ||
|
||
[req_distinguished_name] | ||
C = CN | ||
ST = GuangDong | ||
L = ZhuHai | ||
O = iresty | ||
CN = test.com | ||
|
||
[v3_req] | ||
subjectKeyIdentifier = hash | ||
authorityKeyIdentifier = keyid,issuer | ||
basicConstraints = CA:TRUE | ||
subjectAltName = @alt_names | ||
|
||
[alt_names] | ||
DNS.1 = test.com | ||
DNS.2 = *.test.com | ||
|
||
## openssl genrsa -out apisix.key 3072 -nodes | ||
## openssl req -new -x509 -key apisix.key -sha256 -config openssl.conf -out apisix.crt -days 36500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
master_process on; | ||
|
||
worker_processes 1; | ||
|
||
error_log logs/error.log warn; | ||
pid logs/nginx.pid; | ||
|
||
worker_rlimit_nofile 20480; | ||
|
||
events { | ||
accept_mutex off; | ||
worker_connections 10620; | ||
} | ||
|
||
worker_shutdown_timeout 3; | ||
|
||
http { | ||
lua_package_path "$prefix/lua/?.lua;;"; | ||
|
||
init_by_lua_block { | ||
require "resty.core" | ||
apisix = require("apisix") | ||
apisix.http_init() | ||
} | ||
|
||
init_worker_by_lua_block { | ||
apisix.http_init_worker() | ||
} | ||
|
||
upstream apisix_backend { | ||
server 0.0.0.1; | ||
balancer_by_lua_block { | ||
apisix.http_balancer_phase() | ||
} | ||
|
||
keepalive 32; | ||
} | ||
|
||
server { | ||
listen 9443 ssl; | ||
ssl_certificate cert/apisix.crt; | ||
ssl_certificate_key cert/apisix.key; | ||
ssl_session_cache shared:SSL:1m; | ||
|
||
listen 9080; | ||
|
||
access_log off; | ||
|
||
server_tokens off; | ||
more_set_headers 'Server: APISIX web server'; | ||
|
||
location = /apisix/nginx_status { | ||
allow 127.0.0.0/24; | ||
access_log off; | ||
stub_status; | ||
} | ||
|
||
location /apisix/admin { | ||
allow 127.0.0.0/24; | ||
content_by_lua_block { | ||
apisix.http_admin() | ||
} | ||
} | ||
|
||
ssl_certificate_by_lua_block { | ||
apisix.http_ssl_phase() | ||
} | ||
|
||
location / { | ||
set $upstream_scheme 'http'; | ||
set $upstream_host $host; | ||
set $upstream_upgrade ''; | ||
set $upstream_connection ''; | ||
set $upstream_uri ''; | ||
|
||
access_by_lua_block { | ||
apisix.http_access_phase() | ||
} | ||
|
||
proxy_http_version 1.1; | ||
proxy_set_header Host $upstream_host; | ||
proxy_set_header Upgrade $upstream_upgrade; | ||
proxy_set_header Connection $upstream_connection; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_pass_header Server; | ||
proxy_pass_header Date; | ||
proxy_pass $upstream_scheme://apisix_backend$upstream_uri; | ||
|
||
header_filter_by_lua_block { | ||
apisix.http_header_filter_phase() | ||
} | ||
|
||
log_by_lua_block { | ||
apisix.http_log_phase() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
local balancer = require "ngx.balancer" | ||
local _M = {version = 0.1} | ||
|
||
function _M.http_init() | ||
end | ||
|
||
function _M.http_init_worker() | ||
end | ||
|
||
local function fake_fetch() | ||
ngx.ctx.ip = "127.0.0.1" | ||
ngx.ctx.port = 80 | ||
end | ||
|
||
function _M.http_access_phase() | ||
local uri = ngx.var.uri | ||
local host = ngx.var.host | ||
local method = ngx.req.get_method() | ||
local remote_addr = ngx.var.remote_addr | ||
fake_fetch(uri, host, method, remote_addr) | ||
end | ||
|
||
function _M.http_header_filter_phase() | ||
if ngx.ctx then | ||
-- do something | ||
end | ||
end | ||
|
||
function _M.http_log_phase() | ||
if ngx.ctx then | ||
-- do something | ||
end | ||
end | ||
|
||
function _M.http_admin() | ||
end | ||
|
||
function _M.http_ssl_phase() | ||
if ngx.ctx then | ||
-- do something | ||
end | ||
end | ||
|
||
function _M.http_balancer_phase() | ||
local ok, err = balancer.set_current_peer(ngx.ctx.ip, ngx.ctx.port) | ||
if not ok then | ||
ngx.log(ngx.ERR, "failed to set the current peer: ", err) | ||
return ngx.exit(500) | ||
end | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#! /bin/bash -x | ||
|
||
if [ -n "$1" ]; then | ||
worker_cnt=$1 | ||
else | ||
worker_cnt=1 | ||
fi | ||
|
||
mkdir -p benchmark/server/logs | ||
mkdir -p benchmark/fake-apisix/logs | ||
|
||
sudo openresty -p $PWD/benchmark/server || exit 1 | ||
|
||
trap 'onCtrlC' INT | ||
function onCtrlC () { | ||
sudo killall wrk | ||
sudo killall openresty | ||
sudo openresty -p $PWD/benchmark/fake-apisix -s stop || exit 1 | ||
sudo openresty -p $PWD/benchmark/server -s stop || exit 1 | ||
} | ||
|
||
sed -i "s/worker_processes [0-9]*/worker_processes $worker_cnt/g" conf/nginx.conf | ||
make run | ||
|
||
sleep 3 | ||
|
||
############################################# | ||
echo -e "\n\napisix: $worker_cnt worker + 1 upstream + no plugin" | ||
|
||
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' | ||
{ | ||
"uri": "/hello", | ||
"plugins": { | ||
}, | ||
"upstream": { | ||
"type": "roundrobin", | ||
"nodes": { | ||
"127.0.0.1:80": 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 | ||
|
||
sleep 1 | ||
|
||
############################################# | ||
echo -e "\n\napisix: $worker_cnt worker + 1 upstream + 2 plugins (limit-count + prometheus)" | ||
|
||
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' | ||
{ | ||
"uri": "/hello", | ||
"plugins": { | ||
"limit-count": { | ||
"count": 2000000000000, | ||
"time_window": 60, | ||
"rejected_code": 503, | ||
"key": "remote_addr" | ||
}, | ||
"prometheus": {} | ||
}, | ||
"upstream": { | ||
"type": "roundrobin", | ||
"nodes": { | ||
"127.0.0.1:80": 1 | ||
} | ||
} | ||
}' | ||
|
||
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 openresty -p $PWD/benchmark/fake-apisix || 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 openresty -p $PWD/benchmark/fake-apisix -s stop || exit 1 | ||
|
||
sudo openresty -p $PWD/benchmark/server -s stop || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
master_process on; | ||
|
||
worker_processes 2; | ||
|
||
error_log logs/error.log warn; | ||
pid logs/nginx.pid; | ||
|
||
worker_rlimit_nofile 20480; | ||
|
||
events { | ||
accept_mutex off; | ||
worker_connections 10620; | ||
} | ||
|
||
worker_shutdown_timeout 3; | ||
|
||
http { | ||
server { | ||
listen 80; | ||
|
||
access_log off; | ||
location = /hello { | ||
echo_duplicate 400 "1234567890"; | ||
} | ||
} | ||
} |