Search code examples
phpmysqlreplicationload-balancing

MySQL replication - Should I handle load balancing from my client code (PHP)?


In a MySQL master-slave replication enviroment if I have 4 slave servers how can I execute load balanced select queries?

Should I write a PHP class to dealing with the 4 slaves or it is possible to address queries to MySQL's own load balancer solution? Is there any MySQL load balancing solution?

Can I use some other tool to distribute my queries? What is the typical set up in situations like this?

Thanks for all answers!


Solution

  • Common practice would be to set up something like ldirectord in front of your mysql cluster to provide a virtual ip as a load balanced address for the cluster, this could then distribute your queries to the various mysql servers.

    This would require ipvs routing which may/may not be overkill for your specific situation, it may be that php control of the load balancing would be appropriate for what you are trying to achieve.