HI,ALL:
最近尝试使用openresty自己编写一个简单网关进行openresty的学习,主要想实现动态的upsream和server,参考openresty给的demo编写,逻辑类似下面这样
http{
send_timeout 60s; keepalive_timeout 75s;
keepalive_requests 10000;
client_body_timeout 60s;
client_header_timeout 60s;
charset UTF-8;
lua_code_cache on;
server {
listen 80;
location / {
set $backend '';
rewrite_by_lua_block { rewrite()
}
proxy_pass http://$backend;
}
}
server { listen 8111;
location / {
proxy_pass http://stable_ups;
}
}
upstream dynamic_ups {
server 0.0.0.1; balancer_by_lua_block {
balancer()
}
keepalive 20;
}
upstream stable_ups { server 127.0.0.1:1111; keepalive 20;
}
}
在ubuntu16.04下,开启单个worker,跑满cpu,访问1Kb的静态文件做测试
I7 6700HQ 4C8T 16GB内存
分别测试以下的几种情况
1、直接使用nginx -> proxy_pass -> stable_ups,tps大概在1.5W
2、开启lua代码rewrite -> proxy_pass -> stable_ups,tps大概在1.9W 这里非常奇怪?为何tps会更高了呢?
3、开启lua代码rewrite -> proxy_pass -> dynamic_ups -> balancer,tps大概在1.5w 开启balancer之后下降了很多,我的代码应该有问题
以上lua中的upstream+sever数据都预先加载在lrucache
请问在2的情况下,resty的性能似乎高过了nginx,是因为我的测试方式有问题还是resty的性能十分优秀?
我在性能测试上没有什么经验,希望各位能帮我解惑。THX !