简单测试了一下, 【stream-lua-nginx-module 】性能好像并不高?

1,922 views
Skip to first unread message

Huang ChuanTong

unread,
Aug 30, 2016, 2:24:27 AM8/30/16
to openresty
使用 github最新的版本https://github.com/openresty/stream-lua-nginx-module
配置大致如下:

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")
 
}
   
}
}

然后使用工具对以上两个端口(同一个ngx内)进行压测
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。
而发现stream-lua的没法keekplive ? 请教如何配置?

keepalive不是关键,另一个案例是使用 stream-lua实现一个mysql-proxy,mysql协议是长链的。

然后使用 mysqlslap 简单20个并发,1000次查询。
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才能完成。
结论还是 stream-lua-nginx-module性能暂时不太高?
请问,性能这块,在未来开发中,处什么优先级?
 
 
 



Terry An

unread,
Aug 30, 2016, 3:08:58 AM8/30/16
to openresty
同关注这个话题~

--
--
邮件来自列表“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

Yichun Zhang (agentzh)

unread,
Aug 30, 2016, 7:24:18 PM8/30/16
to openresty
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

Huang ChuanTong

unread,
Aug 30, 2016, 8:11:28 PM8/30/16
to openresty


在 2016年8月31日星期三 UTC+8上午7:24:18,agentzh写道:
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:
在不使用-k参数,跑ab也能达到2w3? 我24核的服务器上也做不到;即使单用一个U也不成~

同样,在改成settimeout,没错误日志下, http的能达到3w下,而, lua-stream依然只有 7k
> 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-stream与lua-http的性能对比。

DeJiang Zhu

unread,
Sep 1, 2016, 9:59:58 AM9/1/16
to open...@googlegroups.com
Hello

在 2016年8月31日 上午8:11,Huang ChuanTong <chuanto...@gmail.com>写道:
标题上,我定义的就是“简单” 测试,所有并没准备图。 而最关键的是,我引出章老师来回答此问题---目的达成。

汗哪,你是猴子派来的逗逼么
 

否则太容易得出完全错误的性能结果了。

把你那个最后一行 Lua 去掉之后,你的例子在我的 macbook pro 上的 linux 虚机里面,使用一个 nginx worker
(即最多用上一个 CPU 核),ab -n10000 -c10 可以压出近 2 万 3 千 qps:
在不使用-k参数,跑ab也能达到2w3? 我24核的服务器上也做不到;即使单用一个U也不成~

这,应该是用了 -k 吧,你不加 -k 测的就主要是建立连接效率了

测试不是简单跑个分,重点是要深入学习,仔细分析
 

--

Wang Liu

unread,
Dec 21, 2017, 4:06:52 AM12/21/17
to openresty
这是没打满CPU吧


在 2016年8月31日星期三 UTC+8上午8:11:28,Huang ChuanTong写道:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages