1

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?

2
  • 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. Commented Dec 27, 2011 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. Commented Dec 27, 2011 at 20:15

1 Answer 1

1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.