I am the back-end engineer/architect working on consolidating a number of production web sites using Drupal 5.11 with the Drupal Memcache API as a base along with the multi-site configuration.
Here's the architecture so far...
- 2-node load balancer front-end (2 Cisco ASA 5510s)
- 4-node web/app servers: RHEL 5 + GFS + Drupal Memcache API + Memcached (Quad Xeon, 8GB Ram each)
- 1-node MySQL 5.x database server with two other MySQL servers in hot stand-by mode (Quad Xeon, 16GB Ram each)
- EMC SAN Storage (1.5TB allocated)
I have attached a PDF of the production infrastructure for visual representation needs.
The current layout works like a charm, however it does present a single point of failure -- the single MySQL database server. We would like to add in the capability to Drupal to allow for split read/writes to a couple of MySQL database servers (which can be configured as Master/Slave) to help reduce the load on the one master database server.
Before you ask: Upgrading to D6 or D7 is not an option at this time due to several 'customized' module issues.
Anyone have an idea of what it would take to modify/patch the Drupal 5.x environment to allow for this?
-- Michael
| Attachment | Size |
|---|---|
| SMS_Production_Layout.pdf | 376.05 KB |

Comments
Patches
There are patches to do master slave and reduce the load. We use them on drupal.org itself.
http://drupal.org/node/147160
http://drupal.org/node/225450
You have to be aware of the possible caveats
See this http://buytaert.net/scaling-with-mysql-replication
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
D6, D5, D7
kbahey wrote:
>There are patches to do master slave and reduce the load. We use them on drupal.org itself.
Yes, from those issues, it seems that at least the first patch (for database replication) -delayed a year ago from D6 to D7 development- was backported to D5, given that drupal.org ran and still runs on Drupal 5.
Both of those links focus of
Both of those links focus of D7, not D5.
I read through the article and found two possible patches, but there is like no info on how to use them...
http://drupal.org/node/147160#comment-561428
http://drupal.org/node/147160#comment-561431
I also found this drupal.org related patch as well...
http://drupal.org/node/147160#comment-561444
Is there a MySQL replication patch list just for D5?
-- M
use new database 'driver'
as you know in settings.php you define driver like this
'mysql://....'
so, you need to write new driver which divide 'select' queries from 'write'
as one of ways to do this:
you can copy database.mysql.inc and rewrite _db_query()
Actually, I am working on
Actually, I am working on using the D5_replication.patch as a base (I found the D5_replication_0.patch to be a bit buggy) and making modifications to our D5.11 environment we have patched with the Memcache API serial module to get both to work concurrently.
However, I do have a couple of questions --
1) Will D7 have the MySQL replication available in the core or as a module?
2) Will the Memcache API be available for D7 as well? (http://drupal.org/project/memcache)
-- M
yes
Yes. No patching needed. It will be in core using the new PDO.
Yes, but it has to wait till the D7 API is frozen and someone to put in the effort required.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Aha!
I see, as per usual, that Khalid is much more informed than me. ;)
http://www.chapterthree.com | http://www.outlandishjosh.com
https://pantheon.io | http://www.chapterthree.com | https://www.outlandishjosh.com
The Future Is Unwritten
There's quite a lot of interest in getting stronger database abstraction tools for Drupal 7, and I'm pretty sure that it will get in there if folks who want it (like you and me) stay active. Now is a good time to be filing issues and patches against the developing builds..
As for memcache, it'll almost certainly get a 7.0 port, as it's becoming a pretty popular piece of the high-performance stack.
http://www.chapterthree.com | http://www.outlandishjosh.com
https://pantheon.io | http://www.chapterthree.com | https://www.outlandishjosh.com
Replication & Performance
Well, finally, I got the D5 MySQL split read and write patches to work. Just took a lot of trial and error tests.
Now my other question...
Since the split reads & writes is more for scaling needs, what kind of performance hits should I encounter under replication? Also, is there anything I can do on either the master and/or slave servers to increase database replication updates and help increase performance?
Contribute it
To save other people from going through the same effort, please post a working patch against the latest Drupal core version (6.6. and 5.12, whichever you are using) to the same issue that you got the initial patch from.
Even if it will never go into core of stable versions, it will save others time.
Thanks in advance.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Modified Files -- MySQL Split Read/Write for D5.11
As requested, I have attached the full modified includes and module files to enable MySQL split read/write under D5.11 and above (I don't know if it will work under D6 or D7). I have already modified the files to have DB_SLAVE enabled and have corrected the code to do automatic fail-back to master (read/write) if the slave database is not available for read-only queries.
NOTE: Rename the 'D5_MySQL_Split_RW_Bundle.doc' file as 'D5_MySQL_Split_RW_Bundle.zip'
CAUTION: These are the full file replacements, not patches!
Read the 'recommended_patch_buildout.txt' for how to create your own patches.
-- Michael
Drupal 6 MySQL Split Read-Write Bundle
After a bit of trial and error, I was able to migrate the code from the original D5 MySQL Split Read-Write bundle over to D6. The real issue was how now D6 uses a database.mysql-common.inc for modularized functionality and focuses on the use of MySQL-I which changes how the MySQL queries are handled as well.
I haven't been able to fully test the code out as of today, but I welcome all of the feedback from your own experiences.
NOTE: Rename the 'D6_MySQL_Split_RW_Bundle.doc' file as 'D6_MySQL_Split_RW_Bundle.zip'
Read the 'recommended_patch_buildout.txt' for how to create your own patches.
-- Michael
Applied patch to D6
I've applied the above bundle in order to get Drupal to split MySQL read/write queries to slave/master databases. However, now when I try to add new content I get an error message: "post could not be saved" and the post is not saved. Also, I can't save any changes made to content.
Any suggestions in order to get this bundle working in D6? Thanks
Unsupported 'hack'
The patch is more of an 'unsupported' hack to the Drupal 6 core. The project/patch on more of a theory and from a proof of concept point of view. If you or someone else can get the patch working in an actual environment, let me and the community know what you did and how it was resolved.
-- Michael
Thanks. Do you know if this
Thanks. Do you know if this is the same patch that Drupal.org has applied to achieve this functionality?
Drupal.org exception
No. Drupal.org site is using a specially designed patch/build that was designed by Four Kitchens (www.fourkitchens.com).
Master/Slave Database replication leads to 'Page not found'
Our database layer has one Master and one Slave, with "synchronous" replication.
We'd like all the "Reads" to go to the Slave, and "Writes" to go to the Master.
We followed the above steps.
Everything works fine for a few minutes, and then we suddenly start getting a "Page not found" (Drupal's page).
That page has the following warnings, and nothing else.
* warning: Invalid argument supplied for foreach() in /xyz/sites/all/modules/views/views.module on line 85.
* warning: Invalid argument supplied for foreach() in /xyz//sites/all/modules/devel/devel.module on line 172.
* warning: array_keys() [function.array-keys]: The first argument should be an array in /xyz/includes/menu.inc on line 1224.
* warning: Wrong parameter count for min() in /xyz/includes/menu.inc on line 1224.
Any idea what could be going on here?
Do sessions/cache need special handling?
Any help is greatly appreciated.
D5 or D6?
Are you doing this under D5 or D6? The reason I ask is that I haven't fully tested the D6 one out as I really don't have a development environment dedicated for this 'unsupported' code hack.
-- M
Thanks for the response. I
Thanks for the response.
I am on Drupal 5.x
"synchronous" replication...
When you are talking "synchronous" replication, do you mean a Master-Master MySQL database configuration?
Also note that is the patch is more of an 'unsupported' hack to the Drupal 5 core. I, for one, haven't utilized this patch in an actual production environment (yet). I have been focusing on this project/patch on more of a theory and proof of concept point of view. I will do the best I can for seeing if there are fixes/updates to be made, but I can't promise anything concrete.
-- M
Master-master replication ?
I'm currently looking at the different options for a high traffic Drupal setup.
I'm wondering whether Drupal is known to work with MySQL in Master Master replication mode ?
That way, no modification of the Drupal code is needed and the Web servers can do their read / writes to any of the db servers....
Len Kranendonk
www.ilance.nl
Smart db reasoning/fail-over?
Are you asking if you point your Drupal build to a single MySQL server running in master-master mode, will it work? Most likely, yes, however there is no available code in Drupal (as of yet) that gives it the 'smart' reasoning to do fail-over to the other working database if more than one master server exists.
However, if you are wanting to double write (i.e. write to both db A and db B), I recommend reading this article first...
How to scale writes with master-master replication in MySQL
http://www.xaprb.com/blog/2008/08/06/how-to-scale-writes-with-master-mas...
Now, if you're looking at doing MySQL with split reads/writes, then you might consider the work I have done so far...
Given that Drupal does not have an option to do MySQL with a master/slave serving, I created my own patch code base for D5 using a combination of a number of older patch releases from a thread geared to D7.x (http://drupal.org/node/147160), but with references to how to do it under D5.x (http://drupal.org/node/147160#comment-561428) as well.
Using the D5.11 code as a base then applying Crell's patches through several trial and error recoding stages, I was able to come up with a MySQL master/slave combination + Drupal patch bundle (http://groups.drupal.org/node/16521#comment-56994). The new settings.php for the $db_url looks like this:
$db_url['default']['master'] = "http://user:password@example.com/master_database";
$db_url['default']['slave'] = "http://user:password@example2.com/slave_database";
So far via my testing, I do know that if you exclude using the 'slave' variable in the settings.php file and have it setup with two 'master' variables, it will only pick up the last 'master' variable entry and not combine the two.
$db_url['default']['master'] = "http://user:password@example.com/master_database";
$db_url['default']['master'] = "http://user:password@example2.com/master2_database"; <-- Only this is seen
I also know that if you try pointing the 'slave' to the other master MySQL server, only 'select' statements will be passed to the 'slave' rather than inserts/updates statements as the pager.inc and database.mysql.inc include files handle the db_query() functions.
-- Michael
Anyone figure this out?
Has anyone gotten this to work with Drupal 6 yet? I'm getting the same "Post could not be saved" message.
Running Drupal 6.10
I'm going to keep trying, if I figure it out I'll let you know.
--
Mathew Winstone
CEO/Co-Founder - Coldfront Labs Inc.
http://coldfrontlabs.ca
@mathewwinstone
patch drupal 6
Hello,
you can find the patch at:
http://www.cestfait.ch/content/drupal-6-patch-masterslave
is the same system master / slave on pressflow.
Enjoi