Hi guys,
请问下在极端性能情况下 lua_shared_dict 是不是性能掉得比较严重。
我目前我用lua_shared_dict写一个简单的计数器(主要用于统计请求QPS),压测数据如下:
CPU配置的都是 24 cores
nginx return 200(无lua) 1.5M QPS
echo.lua - 直接 lua say 1.49M QPS
echo.lua - lua_shared_dict+incr 后只能1M了,这掉得比较厉害。
qpscount.lua 代码如下:
local qpscount = ngx.shared.qpscount
local now = os.time()
function show_qpsstatus(max_time)
max_time = max_time or 30
for i = max_time, 1, -1 do
local timestamp = now - i
local qps, err = qpscount:get(timestamp)
ngx.say(string.format("%s,%s", timestamp, qps))
end
end
if ngx.var.uri == "/qps" then
if ngx.var.arg_max and tonumber(ngx.var.arg_max) then
show_qpsstatus(tonumber(ngx.var.arg_max))
else
show_qpsstatus()
end
ngx.exit(ngx.HTTP_OK)
else
local ok, err = qpscount:incr(now, 1, 0, 86400)
if not ok then
ngx.say("0")
ngx.exit(503)
else
ngx.say("1")
ngx.exit(ngx.HTTP_OK)
end
end
echo.lua 代码如下
ngx.say("1")
ngx.exit(ngx.HTTP_OK)