Request limit calculation

Hello, I’m John and I’m a nginx noob.
I was wondering how the request limit reach is calculated when
using limit_req_zone and limit_req.My problem is that, in development,
I’m not concatenating static files such as .js and .css files. And so
the browser does about 27 requests when the first page is loaded. I’ve
set up a rate of 50r/s, but out of 27, about 18 requests receive a 503
response and I don’t understand why, since the rate isn’t exceeded.
My config looks something like this. I have a link to this from the
sites-enabled folder.
limit_req_zone $binary_remote_addr zone=one:10m rate=50r/s;
server { listen 443 ssl; ssl_certificate …;
ssl_certificate_key …; server_name localhost; server_tokens
off; gzip_types *; root …;
limit_req zone=one;
location = / { index index.html; }
location = /index.html { … }
location / { … }}
If I use limit_req_zone $binary_remote_addr zone=one:10m
rate=10r/s;with limit_req zone=one burst=50 nodelay;
it works OK.
I was wondering why I would have to specify a burst in order for this to
work.
Thank you!

Hello!

On Sat, Jun 20, 2015 at 06:43:57AM +0000, John S. wrote:

it works OK.
I was wondering why I would have to specify a burst in order for this to work.

The 50r/s rate means no more than one request per 20 milliseconds.
If a client will try to do 2 requests at the same time (with less
than 20 milliseconds difference from nginx point of view), the 503
error will be returned to the second request.

To handle such cases there is the burst parameter, and that’s why
you should use it instead of trying to set enormous rate to
accomodate bursts.

Some additional details may be found in docs and in the Wikipedia
article about the algorithm used:

http://nginx.org/en/docs/http/ngx_http_limit_req_module.html
https://en.wikipedia.org/wiki/Leaky_bucket


Maxim D.
http://nginx.org/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs