Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx#ngx_http_limit_req_module: For how long is 503 returned once exceeding the rate?

Tags:

nginx

Say I set

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

server {
    location / {
        limit_req zone=one burst=5 nodelay;
    }

Then for 5 seconds, I send 10 requests per second.

Which request should see a 200 and which should see a 503?
Would it be the first of each 10 requests?

Or does nginx keep track of bad users continuously sending requests, and in this case only the first of the 50 requets would get a 200?

like image 850
oldergod Avatar asked Feb 14 '13 06:02

oldergod


1 Answers

As it stated in the documentation: http://nginx.org/en/docs/http/ngx_http_limit_req_module.html nginx uses "leaky bucket" algorithm which is simple and pretty common in network area. You can read about it on wikipedia: http://en.wikipedia.org/wiki/Leaky_bucket

As for your question (rate=1r/s burst=5 nodelay), in practice it would be something like this:

 Req.# | Time (sec) | Response
   1         0         200 OK
   2       0.1         200 OK
   3       0.2         200 OK
   4       0.3         200 OK
   5       0.4         200 OK
   6       0.5         200 OK
   7       0.6         503
   8       0.7         503
   9       0.8         503
  10       0.9         503
  11       1.0         200 OK
  12       1.1         503
  13       1.2         503
  14       1.3         503
  15       1.4         503
  16       1.5         503
  17       1.6         503
  18       1.7         503
  19       1.8         503
  20       1.9         503
  21       2.0         200 OK
  22       2.1         503
  23       2.2         503
  24       2.3         503
  25       2.4         503
  26       2.5         503
  27       2.6         503
  28       2.7         503
  29       2.8         503
  30       2.9         503
  31       3.0         200 OK
  32       3.1         503
  33       3.2         503
  34       3.3         503
  35       3.4         503
  36       3.5         503
  37       3.6         503
  38       3.7         503
  39       3.8         503
  40       3.9         503
  41       4.0         200 OK
  42       4.1         503
  43       4.2         503
  44       4.3         503
  45       4.4         503
  46       4.5         503
  47       4.6         503
  48       4.7         503
  49       4.8         503
  50       4.9         503
like image 85
VBart Avatar answered Nov 15 '22 05:11

VBart