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
aborted: runtime error: content_by_lua_block(nginx.conf:26):5: attempt
to call method 'set_timeout' (a nil value)
stack traceback:
coroutine 0:
content_by_lua_block(nginx.conf:26): in function
<content_by_lua_block(nginx.conf:26):1> while handling client
connection, client: 127.0.0.1, server: 0.0.0.0:1235
显然,应该是 settimeout() 方法,而不是 set_timeout() 方法。
所以你这里测试的性能其实是 nginx 核心以非缓冲方式刷你的 nginx 错误日志文件的性能。性能测试是需要认真些的,至少应该
1. 检查你的 nginx 错误日志文件,
2. 使用火焰图工具分析满载时的 nginx worker 进程。
否则太容易得出完全错误的性能结果了。
把你那个最后一行 Lua 去掉之后,你的例子在我的 macbook pro 上的 linux 虚机里面,使用一个 nginx worker
(即最多用上一个 CPU 核),ab -n10000 -c10 可以压出近 2 万 3 千 qps:
Server Software: ngx-lua-stream
Server Hostname: localhost
Server Port: 1235
Document Path: /
Document Length: 4 bytes
Concurrency Level: 10
Time taken for tests: 0.435 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1150000 bytes
HTML transferred: 40000 bytes
Requests per second: 22984.28 [#/sec] (mean)
Time per request: 0.435 [ms] (mean)
Time per request: 0.044 [ms] (mean, across all concurrent requests)
Transfer rate: 2581.24 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 6
Processing: 0 0 0.2 0 6
Waiting: 0 0 0.2 0 6
Total: 0 0 0.3 0 6
Regards,
-agentzh