Baoyuantop commented on issue #12577:
URL: https://github.com/apache/apisix/issues/12577#issuecomment-3244123921

   Hi @avaldor-dw, I followed the steps you provided to reproduce the problem 
locally, and the results were the same as yours. However, this is not a bug in 
APISIX, but the expected behavior.
   
   The limit-req plugin uses the [leaky 
bucket](https://en.wikipedia.org/wiki/Leaky_bucket) algorithm to rate limit the 
number of the requests and allow for throttling. 
   
   You can think of network requests or data packets as filling a bucket with 
water. There is a small hole at the bottom of the bucket, and the water flows 
out at a fixed rate. The bucket can only hold a limited amount of water 
(requests). If the capacity is exceeded, it overflows (requests are discarded). 
Regardless of how quickly water is added to the top layer, the rate of water 
leakage from the bottom of the bucket remains constant (the system processing 
rate is fixed). When the inflow of requests exceeds the bucket capacity plus 
the outflow rate, the excess requests are discarded.
   
   Based on your configuration, the rate is set to 5 and the burst is set to 0. 
This means that you expect a leak rate of 5 requests per second, or one request 
every 0.2 seconds. However, the bucket size is 0, so any request that exceeds 
the 0.2-second interval will be dropped. The first request took only 0.085 
seconds to process (you can see this by printing the timestamp). This is before 
the 0.2 second limit, and your bucket size is set to 0, so all other requests 
are discarded. The requests that apisix returns a 429 error take an average of 
0.015 seconds each.
   
   If your expected behavior is to pass 5 requests per second, I think the 
[limit-count](https://docs.api7.ai/hub/limit-count/) plugin is more suitable 
for your needs. You can refer to the configuration:
   ```
   "plugins": {
         "limit-count": {
           "count": 5,
           "time_window": 1,
           "rejected_code": 429,
           "rejected_msg": "Later!!!",
           "key": "consumer_name"
         }
       },
   
   ```


-- 
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