MySQL replication. Should I handle load balancing from my client code (PHP)?
In a MySQL master-slave replication environment, if I have 4 slaves, how can I execute load balance selection queries?
Should I write a PHP class to work with four slaves, or can I query MySQL for my own load balancing solution? Is there any MySQL load balancing solution?
Can I use another tool to propagate my requests? What is the typical setup in these situations?
Thanks for all the answers!
a source to share
A common practice would be to create something like ldirectord in front of your mysql cluster to provide the virtual IP as a balanced address for the cluster, so it can propagate your queries to different mysql servers.
This will require IPvs routing, which may / may not be overflowing for your particular situation, it is possible that php load balancing management will be appropriate for what you are trying to achieve.
a source to share
Yes and no.
There are actually two questions:
- Should this query go to slave or master db?
- This logic should probably be in PHP. There are often times when you must have the absolute most recent data that cannot be retrieved from a subordinate. For example, if the user modifies the page, you need to create the refreshed page from the master db - the user changes may not have reached the slave dbs yet. This is very application specific, so third party tools may not do this for you.
- Which business address should this request go to?
- This is probably not something you need to write yourself - it is not very important to your application which particular slave is handling the request. Existing tools should do this well.
a source to share