just recently I got responsible for an existing project that uses Apache webservers and MySQL databases.

The webserver are behind a HAProxy loadbalancer and the application connects to the MySQL slaves via another HAProxy.

2 of the 10 webserver were added just recently and are more powerful than the old ones. The same for the MySQL slaves: 2 of these 5 slaves have more RAM and CPUs.

The balancing algorithm for the Apache servers is leastconn and for the slaves is source. At least the settings for the MySQL servers I find odd because in the worst case the "best" apache (with the most weight) can always pick the worst MySQL server if I understand the HAProxy Docs right. I'd pick roundrobin with adjusted weights:

  • 10 for the three normal MySQL server
  • 20 for the two stronger MySQL server

And because the apaches are behind the HAProxy with a 20s timeout, I'd rather apply roundrobin, too.

  • 10 for the eight normal apache server
  • 20 for the more powerfull apache server

(I would use the 20 just for a start. I'm going to watch the monitoring and will have it adjusted later.)

Because the the servers are in colocation (as in: I have not root access, change requests take some time) I'd just like to have a second (or more) opinion on this topic: is it a good idea to change the balancing algorithm for both to roundrobin ? I wouldn't consider this if there weren't any performance problems just recently and this is just one place that I find worth tweaking.

Thanks for any/ your advice!

Regards dennis


source is indeed an odd choice, unless your appservers are supposed to have session persistence with DB slaves. That's for you to figure out, though.

leastconn is usually a very good choice if performance of each server (both appserver and database) is not absolutely steady. This depends on the details of your application and platform. (E.g., a Java based appserver can have periods of slow-down due to garbage collection, during which it is sensible to decrease its balancing load.)

Finally, yes, with roundrobin you will usually achieve very predictable and stable balancing that adheres tightly to the weightings.

  • 1
    Thanks for your feedback. Especially the hint at the session persistence. – dennis May 11 '15 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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