# Load balancing server retry interval

**URL:** <https://www.ruby-forum.com/t/load-balancing-server-retry-interval/201291>\
**Category:** NGINX\
**Created:** [January 4, 2011, 4:42pm UTC](https://www.ruby-forum.com/t/load-balancing-server-retry-interval/201291 "2011-01-04T16:42:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 4, 2011, 4:42pm UTC](https://www.ruby-forum.com/t/load-balancing-server-retry-interval/201291/1 "2011-01-04T16:42:20Z")

</div>

Hi everyone,  
I’m setting up a load balancer with 2 backend servers using the  
following configuration:

```auto
upstream backend{
        ip_hash;
        server 10.0.0.1:3000 max_fails=3 fail_timeout=20s;
        server 10.0.0.2:3000 max_fails=3 fail_timeout=20s;
}

location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://backend;
        proxy_read_timeout 20;
        proxy_connect_timeout 10;
        proxy_pass_header Set-Cookie;
}
```

When I bring one of the servers down for testing, I get a behavior that  
is a bit odd. The first 3 requests timeout, and transfer to the second  
server.  
After that, for 20 seconds, all requests automatically transfer to the  
second server (as the first one is flagged as down).  
However, after these 20 seconds pass, the server status is reset and all  
requests are directed to it until it fails again.

The documentation says fail\_timeout is also used as the interval before  
another check is made, and that leads me to believe this behavior is by  
design. The problem is, when 20 seconds have passed (and ip\_hash is  
activated) all users who were assigned to the failed server are directed  
to it again, having their requests hang until they timeout again.

Am I supposed to use a larger fail\_timeout to imply a longer failed  
status? It seems odd that nginx assumes a server is back up and waits  
until it fails again (instead of checking in the background if it’s back  
online and only then set it to healthy).

Posted at Nginx Forum:

> **[Load balancing server retry interval](https://forum.nginx.org/read.php?2,163404,163404#msg-163404)**
>
> Hi everyone, I'm setting up a load balancer with 2 backend servers using the following configuration: \[code\] upstream backend{ ip\_hash; server 10.0.0.1:3000 max\_fails=3 fail\_timeout=20s; server 10.0.0.2:3000 max\_fails=3 fail\_timeout

---

<div class="post-metadata">

**Author:** ![ehudros2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/76d3ee/32.png) [@ehudros2](https://www.ruby-forum.com/u/ehudros2)\
**Post date:** [January 5, 2011, 6:00am UTC](https://www.ruby-forum.com/t/load-balancing-server-retry-interval/201291/2 "2011-01-05T06:00:04Z")

</div>

Hello!

On Tue, Jan 04, 2011 at 10:41:13AM -0500, ehudros2 wrote:

> location / {  
> When I bring one of the servers down for testing, I get a behavior that  
> activated) all users who were assigned to the failed server are directed  
> to it again, having their requests hang until they timeout again.
> 
> Am I supposed to use a larger fail\_timeout to imply a longer failed  
> status? It seems odd that nginx assumes a server is back up and waits  
> until it fails again (instead of checking in the background if it’s back  
> online and only then set it to healthy).

Yes, this is how it currently works. Not very good algorithm  
(awfull one, actually) and this should be changed somehow.  
Providing good patch may be beneficial.

Maxim D.
