Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We're running web servers behind an EC2 load balancer, and in turn these servers run HAProxy and spread load between work servers.

Assuming equal server weights, it seems like the following scenario would play out if EC2 effectively uses a roundrobin load balancing algorithm:

Server 1 handles request, sends to backend 1
Server 2 handles request, sends to backend 1
Server 3 handles request, sends to backend 1

Server 1 handles request, sends to backend 2
Server 2 handles request, sends to backend 2
Server 3 handles request, sends to backend 2

Server 1 handles request, sends to backend 3
Server 2 handles request, sends to backend 3
Server 3 handles request, sends to backend 3
...

If session lengths are roughly the same, load is not balanced correctly. Assuming equal weights, does HAProxy choose a random first server in its roundrobin algorithm?

share|improve this question
    
Round-robin isn't the best algorithm to use, as it effectively means that all of your web servers are serving up all of your content. –  rmalayter Dec 27 '11 at 20:09
1  
To follow up, for static files, you will likely want to use a consistent hashing algorithm based on URL, so that a request for /images/foo.jpg always hits server 1, but /images/bar.jps always hits server 2 so long as they are online. This enables a much higher hit ratio in the filesystem cache. So instead of 3 copies of your hot files in RAM on each of 3 servers, you have 3x as much effective RAM cache. –  rmalayter Dec 27 '11 at 20:15

1 Answer 1

up vote 1 down vote accepted

In my experience, haproxy always starts from first server (not random one). If what you're describing does indeed happen, just rotate the server list by 1 entry on each balancer.

share|improve this answer

Your Answer

 
discard

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.