# Delayed 503 limit\_req response - feature request

**URL:** <https://www.ruby-forum.com/t/delayed-503-limit-req-response-feature-request/229617>\
**Category:** NGINX\
**Created:** [January 25, 2013, 8:09pm UTC](https://www.ruby-forum.com/t/delayed-503-limit-req-response-feature-request/229617 "2013-01-25T20:09:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CM\_Fields](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@CM\_Fields](https://www.ruby-forum.com/u/CM_Fields)\
**Post date:** [January 25, 2013, 8:09pm UTC](https://www.ruby-forum.com/t/delayed-503-limit-req-response-feature-request/229617/1 "2013-01-25T20:09:45Z")

</div>

Nginx Feature Request: Delay 503 limit\_req responses

We would like to delay the 503 response to clients which exceed the  
limit\_req value rather then send an immediate 503. The delay would be  
in milliseconds or in tenths of a second increments for example.

We are not trying to slow down those clients who are obviously abusive  
or malicious. Those ips are blocked at the firewall with custom  
scripts. We are trying to slow down valid clients who use overly  
aggressive programs, but have legitimate access our servers.

The nginx server in question is used to serve large data downloads. We  
want to serve as many people as we can without using excessive CPU  
time or sending billions of 503 error network packets. According to  
our logs we spend approximately 1.3% of our outgoing bandwidth on 503  
responses to valid clients. I believe simply by adding in a 200ms  
delay we could reduce outgoing 503 bandwidth from 1.3% to less then  
0.2% saving us time and money.

Our current setup:

The following directives allow a client to make 100 requests with no  
delay. After 100 requests the client is limited to 61 requests per  
minute. Client requests over 61/60 seconds are returned an error 503  
immediately for every subsequent request.

http {  
limit\_req\_zone $binary\_remote\_addr zone=one:10m rate=61r/m;  
server {  
limit\_req zone=one burst=100 nodelay;  
}  
}

What does everyone think of slightly delaying the 503 response?

Using the same limit\_req code above the client could exceed our limit  
of 61 req per 60 sec and we would still send back a 503, but now we  
delay the response by 200ms. Notice the delay at the end of the  
following directive. The delay would slow the next request by the  
client by slowing our response.

limit\_req\_zone $binary\_remote\_addr zone=one:10m rate=61r/m delay=200ms;

What does delaying the response solve?

The problem we see is over aggressive download accelerators, http  
scanners or broken scripts. A client application which gets an  
immediate 503 will just send another request right away and we will  
send them another 503 right away. This looping behavior uses CPU  
resources, network time and can be a significant drain on resources.

If nginx could delay the 503 by a user specified time the excessive  
client requests and 503 error loops will be reduced. The client would  
wait till it gets a response from the server before sending another  
request believing the packet is still in the network. The side effect  
of the delay is the client would be slowed and perhaps lower its  
request rate below our limit\_req value.

Problems with delaying the 503 response?

One issue we see with delaying the response to the client is holding  
open the connection. Not sure if this is a real problem because the  
client will probably use the same connection for their next immediate  
request anyways. There may be other problems with the delay we have  
not thought of yet.

Thanks for everyone’s time. We just wanted to post this request in  
case anyone else also thought the idea was valid and a delayed 503 was  
a decent solution.

---

<div class="post-metadata">

**Author:** ![CM\_Fields](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@CM\_Fields](https://www.ruby-forum.com/u/CM_Fields)\
**Post date:** [January 26, 2013, 2:40pm UTC](https://www.ruby-forum.com/t/delayed-503-limit-req-response-feature-request/229617/2 "2013-01-26T14:40:48Z")

</div>

Hello!

On Fri, Jan 25, 2013 at 02:09:21PM -0500, CM Fields wrote:

> Nginx Feature Request: Delay 503 limit\_req responses
> 
> We would like to delay the 503 response to clients which exceed the  
> limit\_req value rather then send an immediate 503. The delay would be  
> in milliseconds or in tenths of a second increments for example.

Try the following trivial module:

> **[ngx\_http\_delay\_module: log](http://mdounin.ru/hg/ngx_http_delay_module/)**

With the config like

```
error_page 503 /errors/503.html;

location = /errors/503.html {
    delay 200ms;
}

```

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![CM\_Fields](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@CM\_Fields](https://www.ruby-forum.com/u/CM_Fields)\
**Post date:** [January 28, 2013, 9:09pm UTC](https://www.ruby-forum.com/t/delayed-503-limit-req-response-feature-request/229617/3 "2013-01-28T21:09:12Z")

</div>

On Sat, Jan 26, 2013 at 8:40 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Try the following trivial module:
> 
> –  
> Maxim D.  
> [NGINX | F5](http://nginx.com/support.html)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Maxim,

Thank you! The ngx\_http\_delay\_module works perfectly.
