Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently testing haproxy to load balance our newsletter generation. We build personalized newsletter for our customers.

To do this we use two webservers (identical machines), and one "mail engine". The mail engine makes calls to the webservers, which then returns a personalized html newsletter.

Now the problem, is that one webserver has a cpu load about 75% but the other is only running 15%. Looking at "Session rate" when testing, both server has "Session rate -> Cur" between 3 and 4 the whole time.

But when looking at "Sessions", here the "Sessions -> Cur" has a total of 10, web server 1 has a "Cur" of 8 and the other web server has between 0 and 2.

Why would there be 8 session on the first web server and 0-2 on the other?

Here is my config:

        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        timeout connect 5000
        timeout client  50000
        timeout server  50000

listen mailgenerator
        mode http
        stats enable
        balance roundrobin
        option httpclose
        option forwardfor
        option httpchk HEAD /robots.txt
        server mail1 check weight 100
        server mail2 check weight 100
share|improve this question

If you use round robin then connections will be distributed evenly as they arrive regardless of load. So if you have a slower server or a slow process it can build up a queue on one while the other is free.

You can get much more even distribution if you use the leastconn balancing and set a low maxconn per server to cause connections to queue in haproxy rather than on each server.

share|improve this answer
For short, stateless connections, using roundrobin and varying the server weights is still better than leastconn when you need to balance asymmetrically. Leastconn works better for long lived tcp connections, where the number of corrent sessions is more relevant. – JimB Jun 17 '11 at 15:05
No because when you get one stalled or slow connection it causes problems as demonstrated in the Q. And with fast or few connections leastconn ends up alternating in the same was as roundrobin anyway. – JamesRyan Jun 17 '11 at 15:26
@JamesRyan - hmm, I was just restating a recommendation from the author of haproxy, but I do agree (and usually use leastconn myself when there's any variability in session time). I wonder if there really is a drawback to leastconn with a high session rate... – JimB Jun 17 '11 at 16:02
Another point to ponder, depending on the application the number of connections does not necessarily correlate to load. In situations where session setup is expensive, you want to distribute new connections evenly, not based on session that haven't closed. – JimB Jun 17 '11 at 16:10
I think this would sort itself out though because on servers where session setup took longer the queue would grow quicker. – JamesRyan Jun 17 '11 at 16:24

For http, the current sessions doesn't mean much. The sessions Total and LbTot better represent how the servers are being balanced. If those numbers are fairly even, it may be something on one server causing it to process its requests more slowly, therefor pushing up the load.

share|improve this answer
The point of balancing is not to ensure that your servers get an even amount of the work. Even distribution is only important under load and then is secondary to making sure requests are fulfilled. If one server is slow or stalled you WANT more requests to go to the other one. – JamesRyan Jun 17 '11 at 15:29
@JamesRyan - Agreed. The OP though said he has identical machines fielding identical requests. I was trying to show that the load balancing may still be even, and skewed load cause by another problem (Maybe my answer should have been comment). You're trying to solve the problem (which is good), where as I'm trying to diagnose the symptoms. – JimB Jun 17 '11 at 15:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.