跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 关于 nginx 中 limit_req_zone 模块的 burst 的疑惑

发表于

代码如下:

http{

   limit_req_zone $binary_remote_addr zone=mylimit:1m rate=6r/m;
   
   server {
      listen 80;
      ......
      location / {
         limit_req zone=mylimit burst=5;
         proxy_pass http://www.baidu.com;
      }
   }
}

对于 burst ,nginx 给的解释是:

https://blog.nginx.org/blog/rate-limiting-nginx#:~:text=The%20burst%20parameter%20defines,requests%20go%20over%C2%A020.

摘录如下:

The burst parameter defines how many requests a client can make in excess of the rate specified by the zone (with our sample mylimit zone, the rate limit is 10 requests per second, or 1 every 100ms). A request that arrives sooner than 100ms after the previous one is put in a queue, and here we are setting the queue size to 20.

That means if 21 requests arrive from a given IP address simultaneously, NGINX forwards the first one to the upstream server group immediately and puts the remaining 20 in the queue. It then forwards a queued request every 100ms, and returns 503 to the client only if an incoming request makes the number of queued requests go over 20.

结合代码和这段文字,我对 burst 的理解是:

6r/m:以每 1 分钟为一个时间阶段,将这 1 分钟分为 6 段,即每 10s 最多接收 1 个请求,该 10s 内的多余请求将会被返回 503 ;

burst=5:突发队列长度=5 。以每 1 分钟为一个时间阶段,在这 1 分钟内,该队列最多只能接受 5 个请求,即使该队列内的请求已经被处理,也不会往队列里新增新的请求,直到下 1 分钟到来。

测试

测试工具:jmeter
测试线程数:120
测试时间(ramp-up):120s
循环次数:1

预期结果:

在 120s 内,一共发起了 120 个请求,其中请求成功 22 个(6+6+5+5),其余返回 503 ;

实际测试结果:

在 120s 内,一共发起了 120 个请求,其中请求成功 17 个(6+6+5),其余返回 503 ;

为什么少了 5 个请求,希望大佬们为我指点下,谢谢~

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.