Re: backup servers as overflow servers

From: Willy Tarreau <w#1wt.eu>
Date: Tue, 22 Jan 2008 19:02:39 +0100


Hi Dale,

On Tue, Jan 22, 2008 at 03:41:47PM +0000, Dale Roberts wrote:
>
> Hi all
>
> I just wanted to know if, with HAProxy, you can have a client request sent to a backup server if all the non backup server are still alive, but overloaded (as defined by maximum connection count, maximum queue size and connecion timeouts).

I would be tempted to say "yes", because on a server, you can define :

The queue applies only when servers have reached their maxconn. So if you set a maxqueue parameter to all your servers, excessive requests will be rejected with a 503 error. If you add "option redispatch", they should be redispatched to other servers. In this case, the load balancing algorith applies and if no usable server is found, the backup ones should be used. I just have a doubt about the fact that the queue size would be checked when selecting a server.

> I ask, as I'd like to be able to send "current" users of web site (i.e. those with a cookie) as well as excessive new users (i.e. those without a cookie) to a backup server so that they get a nice "we are busy, please try again later" message. I'm happy for users to get a cookie that "binds" them to that backup server till they close their browser as they will alleviate problem of impatient page refreshes.

If you just want to send them a sorry page, maybe you should just define your limits and redirect the 503 message to another URI which will be declared in another backend ?

> Obviously other suggestions on how to nicely do this are welcomed.

You may also want to check the "dst_conn" and "nbsrv" ACL criteria. They will allow you to make a decision based on the number of alive servers and the number of connections on the frontend. While admittedly tricky, you could then decide how many servers can accept how many conns (including queues) and decide in the frontend to switch new ones to another backend. For instance, consider the case below, allowing up to 250 connections per online server, switching to another backend when the limit is reached :

frontend www

     acl 0_srv  nbsrv(backend) 0
     acl 1_srv  nbsrv(backend) 1
     acl 2_srv  nbsrv(backend) 2
     acl 3_srv  nbsrv(backend) 3
     acl 4_srv  nbsrv(backend) 4

     acl 1_full dst_conn ge 250
     acl 2_full dst_conn ge 500
     acl 3_full dst_conn ge 750
     acl 4_full dst_conn ge 1000

     use_backend backup if 4_srv 4_full OR 3_srv 3_full OR 2_srv 2_full OR 1_srv 1_full OR 0_srv 
     default_backend normal

# used when everything works as expected. backend normal

    balance roundrobin
    cookie SERVERID insert
    server ...

# used only when users get into trouble. Do not set a cookie
# so that users can get their session back when the load goes
# away

backend backup

    server ...

You may even improve on this in order not to perturbate POST requests. That way, you do what you can to serve those users with forms just fulled :

     use_backend backup if 0_srv 
     use_backend normal if METH_POST 
     use_backend backup if 4_srv 4_full OR 3_srv 3_full OR 2_srv 2_full OR 1_srv 1_full
     default_backend normal


> >From my reading of the manual for HAProxy (not quite exhaustive yet) and some brief fiddling I can see that once connected to a backup server (and armed with it's cookie) you get returned to that backup server even when the main server are back on-line. But it appears that if the normal server are on-line and you're connection can't be served you get a 503 error, with no way to tell HAProxy to instead re-dispatch the request to a backup server.
>
> I hope this makes sense and many thanks in advance for any feedback.

It somewhat makes sense. You have to think what level of service you want to offer to your users though, as you're clearly saying that you'll cause some perturbations.

I hope this helps,
Willy Received on 2008/01/22 19:02

This archive was generated by hypermail 2.2.0 : 2008/01/22 19:45 CET