bug: limit-req cannot limit access
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 https://github.com/bingoohuang/blog/issues/209%EF%BC%89
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 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux - OpenResty / Nginx version (run
openresty -Vornginx -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):
Is this issue the same as https://github.com/apache/apisix/issues/11288? If so, could you keep one open with the summarized info? Thanks.