dimon-v commented on issue #11288:
URL: https://github.com/apache/apisix/issues/11288#issuecomment-2133129270

   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)
   
   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"
   
               -- 限制每秒 200 个请求 (rate),以及 100 的等待队列 (burst), 超过每次 300,直接拒绝
               local rate = tonumber(ngx.var.arg_rate or 200)
               local burst = tonumber(ngx.var.arg_burst or 100)
               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.log(ngx.ERR, "rejected")
                   -- ngx.say, ngx.print 发送消息包,必然要先发送消息头,所以需要提前设置 response 
status (默认为200)
                   ngx.status = 503
                   ngx.say("XX delay:", delay, ", rate: ", rate, ", burst: ", 
burst)
                   return ngx.exit(503)
               end
   
               ngx.say("OK delay: ", delay, ", rate: ", rate, ", burst: ", 
burst, ", excess: ", excess)
               return ngx.exit(200)
           }
       }
   }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to