openresty lua_shared_dict 性能下降3分之1

112 views
Skip to first unread message

louis....@gmail.com

unread,
Jul 20, 2024, 4:08:24 PM7/20/24
to openresty
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)

kwanhur

unread,
Aug 4, 2024, 3:18:45 AM8/4/24
to open...@googlegroups.com
建议统计 QPS 仅保留统计 `local ok, err = qpscount:incr(now, 1, 0, 86400)` 核心部分,像 `show_qpsstatus()` 部分逻辑剥离开。
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@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
---
您收到此邮件是因为您订阅了Google网上论坛上的“openresty”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到openresty+...@googlegroups.com
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/openresty/c4c43ad1-dbb1-4edd-849d-24b00c20f811n%40googlegroups.com

Junlong li

unread,
Aug 5, 2024, 1:42:43 AM8/5/24
to openresty
你可以在 lua 统计,然后每秒一次刷入 共享内存,看看这样能满足业务需求吗?
Reply all
Reply to author
Forward
0 new messages