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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With