|
|||
|
Hello everyone! This is a first time post.
We've got a database with replication set up. In this case, we want the website to be doing all its queries from the slave databases but all its additions and alterations to the master database. It seems to me that the easiest PHP solution is to set up a twin adapter (extension of Zend_Db_Adapter_Abstract) that takes two other adapters as arguments. All the fetch and describes get passed to the 'slave' adapter and all the insert, updates and delete methods get passed to the 'master' adapter. In fact, this seems so simple that I'm pretty sure someone's done it. Has someone created the adapter I describe? Can anyone think of a reason why this wouldn't work or a better way of doing it? |
|
||||
|
You should reconsider this approach. If you wanted two seperate database servers, then do seperate servers. But if you have a master/slave, then you should utlize MySQLs replication tools and techniques to get the most out of it. The DB is going to be better at this than anything you can do on the client side (php being the client of mysql).
Replication as a scale out method is meant for apps that rarely insert/update, but do lots of reads. More info here: MySQL :: MySQL 5.0 Reference Manual :: 15.2.3 Using Replication for Scale-Out If you do more writes than reads, or have a mixed result, consider a mysql cluster as a scale out solution: MySQL :: MySQL Cluster |
|
|||
|
I don't see that the documentation you've helpfully posted is inconsistent with my approach. We're going to do replication exactly as you describe, but it won't do us any good if we're always reading and writing from the master. The documentation itself says I need to change my website code (in this case, Zend Framework):
If the part of your code that is responsible for database access has been properly abstracted/modularized, converting it to run with a replicated setup should be very smooth and easy. I'm not planning on using PHP to replicate. MySQL will replicated. I want to take the PHP code and "convert it to run with a replicated setup", which, as best I can tell, means setting it to read from slaves and write to the master, as my twin adapter idea does. Now, if MySQL has its own load balancer that will redirect read requests to slaves and write requests to masters, then, great, I don't have to worry about PHP at all, and I'd need to rethink my approach. This documentation you've posted seems to suggest MySQL doesn't do it, since they're giving us advice on how to rewrite our website code. Since replication is the way to go, and since replication seems to require something like my twin adapter, the question remains. Has someone already done it, or should I write it? |
![]() |
| Thread Tools | |
| Display Modes | |
|
|