Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: limit-req cannot limit access #11299

Open
dimon-v opened this issue May 28, 2024 · 1 comment
Open

bug: limit-req cannot limit access #11299

dimon-v opened this issue May 28, 2024 · 1 comment

Comments

@dimon-v
Copy link

dimon-v commented May 28, 2024

Current Behavior

When using OpenResty Limit Req, Set the rate to 200 Burst setting 1, after using WRK stress testing, I calculated that the number of 200 status entries in the access log is less than the rate ( see bingoohuang/blog#209

lua_shared_dict my_limit_req_store 100m;

server {
listen 8700;
default_type text/html;

location / {
    return 200 OK;
}

location /limit {
    access_by_lua_block {
        local limit_req = require "resty.limit.req"

    -- 限制每秒 100 个请求 (rate),以及 1 的等待队列 (burst), 超过每次 300,直接拒绝
    local rate = tonumber(ngx.var.arg_rate or 100)
    local burst = tonumber(ngx.var.arg_burst or 1)
    local lim, err = limit_req.new("my_limit_req_store", rate, burst)
    if not lim then
        ngx.log(ngx.ERR, "failed to instantiate a resty.limit.req object: ", err)
        return ngx.exit(500)
    end

    -- 以远端IP为限制 key
    local delay, excess = lim:incoming(ngx.var.binary_remote_addr, true)
    if excess == "rejected" then
        ngx.status = 503
        return ngx.exit(503)
    end

    ngx.say("OK delay: ", delay, ", rate: ", rate, ", burst: ", burst, ", excess: ", excess)
    return ngx.exit(200)
}

Expected Behavior

According to the limit req document, requests with a request rate exceeding (rate+burst) will be directly rejected, such as setting rate=100, Burst=1 expects requests with QPS greater than 101 per second to return 503

Error Logs

No response

Steps to Reproduce

1、run apisix and set route with limit-req
2、use wrk testing
3、grep access log count

Environment

  • APISIX version (run apisix version): 3.8.1
  • Operating system (run uname -a): 3.10.0-1160.31.1.el7.x86_64 change: added doc of how to load plugin. #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.21.4.2
    built by gcc 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)
    built with OpenSSL 3.2.0 23 Nov 2023
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): {"id":"66356a45-bcc5-4a5a-9318-210342728ebd","hostname":"nginx-gray02","version":"3.8.1","boot_time":1716876699,"etcd_version":"unknown"}
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@kayx23
Copy link
Member

kayx23 commented Jun 5, 2024

Is this issue the same as #11288? If so, could you keep one open with the summarized info? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants