跳转到内容
彼岸论坛
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 关于 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 个请求,希望大佬们为我指点下,谢谢~

意见的链接
分享到其他网站

加入讨论

您现在可以发表并稍后注册. 如果您是会员,请现在登录来参与讨论.

游客
回复主题...

×   粘贴为富文本.   粘贴为纯文本来代替

  只允许使用75个表情符号.

×   您的链接已自动嵌入.   显示为链接来代替

×   您之前的内容已恢复.   清除编辑器

×   您无法直接粘贴图片.要从网址上传或插入图片.

  • 游客注册

    游客注册

  • 会员

    没有会员可显示

  • 最新的状态更新

    没有最新的状态更新
  • 最近查看

    • 没有会员查看此页面.
×
×
  • 创建新的...