# Request limit calculation

**URL:** <https://www.ruby-forum.com/t/request-limit-calculation/242388>\
**Category:** NGINX\
**Created:** [June 20, 2015, 8:48am UTC](https://www.ruby-forum.com/t/request-limit-calculation/242388 "2015-06-20T08:48:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [June 20, 2015, 8:48am UTC](https://www.ruby-forum.com/t/request-limit-calculation/242388/1 "2015-06-20T08:48:15Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [June 21, 2015, 2:59pm UTC](https://www.ruby-forum.com/t/request-limit-calculation/242388/2 "2015-06-21T14:59:16Z")

</div>

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:

> **[Module ngx\_http\_limit\_req\_module](http://nginx.org/en/docs/http/ngx_http_limit_req_module.html)**

> **[Leaky bucket](https://en.wikipedia.org/wiki/Leaky_bucket)**
>
> The leaky bucket is an algorithm based on an analogy of how a bucket with a constant leak will overflow if either the average rate at which water is poured in exceeds the rate at which the bucket leaks or if more water than the capacity of the bucket is poured in all at once. It can be used to determine whether some sequence of discrete events conforms to defined limits on their average and peak rates or frequencies, e.g. to limit the actions associated with these events to these rates or delay ...

–  
Maxim D.

> **[nginx](http://nginx.org/)**
