stream{
server {
listen 1111;
lua_socket_keepalive_timeout 10s;
content_by_lua_block {
local sock = assert(ngx.req.socket(true))
local data = sock:receive() -- read a line from downstream
ngx.say("HTTP/1.1 200 OK\r\nServer: ngx-lua-stream\r\nContent-Type: text/html\r\nContent-Length: 4\r\nConnection: keep-alive\r\n\r\n123")
sock:set_timeout(10*1000)
}
}
}
http {
listen 80 ;
server_name test;
location /lua{
content_by_lua_block {
ngx.say("123")
}
}
}ab -n 10000 -c 100 -k http://localhost:1111/ ---> QPS: 3k
ab -n 10000 -c 100 -k http://localhost:80/ ---> QPS: 2w+
stream-lua的 qps只有 3.5~4k,面lua-http的有2万多的qps。
mysqlslap -a --concurrency=20 --number-of-queries=1000 -P 1234
- 直接裸测 MySQL,大概在0.2~0.3秒完成
- 使用ngx-stream (不带lua)的tcp直接代理mysql的3306端口,大概在0.3~0.4+完成
- 使用stream-lua-nginx-module,+resty/mysql.lua 作mysql-proxy后,大概要1.4~2.0s才能完成。
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
Hello!
2016-08-29 23:24 GMT-07:00 Huang ChuanTong:
> content_by_lua_block {
> local sock = assert(ngx.req.socket(true))
> local data = sock:receive() -- read a line from downstream
> ngx.say("HTTP/1.1 200 OK\r\nServer: ngx-lua-stream\r\nContent-Type:
> text/html\r\nContent-Length: 4\r\nConnection: keep-alive\r\n\r\n123")
> sock:set_timeout(10*1000)
你这里的最后一行 Lua 代码会抛下面的 Lua 异常:
2016/08/30 16:17:32 [error] 28404#0: *9 stream lua entry thread
1. 检查你的 nginx 错误日志文件,
2. 使用火焰图工具分析满载时的 nginx worker 进程。
否则太容易得出完全错误的性能结果了。
把你那个最后一行 Lua 去掉之后,你的例子在我的 macbook pro 上的 linux 虚机里面,使用一个 nginx worker
(即最多用上一个 CPU 核),ab -n10000 -c10 可以压出近 2 万 3 千 qps:
> ab -n 10000 -c 20 -k http://127.0.0.1:1111/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: ngx-lua-stream
Server Hostname: 127.0.0.1
Server Port: 1111
Document Path: /
Document Length: 4 bytes
Concurrency Level: 20
Time taken for tests: 1.347 seconds
Complete requests: 10000
Failed requests: 5002
(Connect: 0, Receive: 0, Length: 5002, Exceptions: 0)
Write errors: 0
Keep-Alive requests: 5002
Total transferred: 575920 bytes
HTML transferred: 20032 bytes
Requests per second: 7423.97 [#/sec] (mean)
Time per request: 2.694 [ms] (mean)
Time per request: 0.135 [ms] (mean, across all concurrent requests)
Transfer rate: 417.54 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.2 1 3
Processing: 0 1 0.9 1 4
Waiting: 0 1 1.2 1 4
Total: 0 3 2.0 3 6
Percentage of the requests served within a certain time (ms)
50% 3
66% 4
75% 5
80% 5
90% 5
95% 5
98% 5
99% 5
100% 6 (longest request)标题上,我定义的就是“简单” 测试,所有并没准备图。 而最关键的是,我引出章老师来回答此问题---目的达成。
否则太容易得出完全错误的性能结果了。
把你那个最后一行 Lua 去掉之后,你的例子在我的 macbook pro 上的 linux 虚机里面,使用一个 nginx worker
(即最多用上一个 CPU 核),ab -n10000 -c10 可以压出近 2 万 3 千 qps:在不使用-k参数,跑ab也能达到2w3? 我24核的服务器上也做不到;即使单用一个U也不成~
--