High availability - MySQL cluster v's replication

High availability - MySQL cluster v's replication

by Hugh Morrow -
Number of replies: 11
For some time now I've been trying to determine a simple robust architecture that will enable high availability (that is, I'm after availability first, performance second). After some research (thanks to all of you that have contributed to these discussions) I think I'm close to a solution and thought I'd share my findings here for community. If consensus can be reached we might add the detail to the Performance documentation (as requested some time back).

Before going too far, it is clear from the discussion that one of the linux variants is strongly recommended for the OS. For the applications I'm assuming Apache and MySQL.

The high availability web server setup seems pretty straightforward - put a load balancer in front of 2+ web servers. There has been some discussion of the use of a reverse proxies, hardware and software load balancers ... but all in all this looks relatively easy. (References: Linux Virtual Server and a LVS how-to; Squid used at SFSU, and here, and disputed here(!); other options mentioned include Perlbal, Balance, Varnish and a request for varnish experience reports?)

The big issue, as far as I can tell is the database. And here is what I've gleaned (check out the MySQL docs on HA for a good overview of replication and clustering):
Leading to architectures like:
MySQL replication:
moodle.PNG
DRBD like in this setup:
moodle_my.JPG
Reverse proxy and replication like this:
clustering.gif


In either scenario, there needs to be some automated process to manage the failover. If the primary database goes down, then the application (moodle) needs to redirect queries to the slave.

Which leads me to my three remaining questions:
  1. How is automated failover best achieved?
  • I am guessing that people are using something like heartbeat to detect a failure of the primary MySQL server and trigger a script that changes the moodle/config.php files on each of the web servers to look a the slave database. Is this correct?
Is DRBD more reliable / safer than replication?
  • I am concerned that if the main table gets corrupted, then so too will the slave. Also, I like the idea of having a slave available for the creation of backups (due to the ability to stop the slave db server, create backup, restart and let the slave catch up) ... maybe the answer is to do both?
What are the options for scaling up performance?
  • Other than throwing more RAM and CPU at the primary server (and using memcached , db tuning). I can't see that moodle will support a master for writes and slaves for reads due to the nature of the application. with many slave - vertical scaling)?

Any help and comments appreciated.



Average of ratings: -
In reply to Hugh Morrow

Re: High availability - MySQL cluster v's replication

by Gary Benner -

HI Hugh,

Great to see your work in this area.

At the 2005 moodle Moot in Adelaide I ran a workshop on Enterprise Moodle, where I showed how to build a Moodle Cluster. We created a eight server configuration which we later demonstrated to the main conference, showing the system continue to work as we "removed" each computer from the cluster - in this case by removing the network cables.

I had based this on a research project I undertook at the Waiariki Institute of Technology ( Rotorua NZ ) where I work part time.

The load balancing and web server management is not too difficult, as you have found.

The area that I came to struggle with was the persistent storage - ie database, and in the end I felt that the answer was in a practical compromise. Elsewhere on this site I have discussed the issues and fallacies of trying to achieve a high level of availability - or "nines" as they call them.

For the database, my recommendation is now that you provide the best hardware platform that you can - dual psu's, fans ( the things that move and wear out ), quality gear, and raid to give better performance and to handle HDD failures ( at last one at a time ) without having to take the server down.

Then provide a smaller ( or same if you have the budget <g> ) backup Db server that runs a simple master - slave replication. If you need instant failover then you can place another couple of load balancers between the web servers and the db servers. ( you need two else you introduce another single point of failure ) I've tried to implement an effective bi-directional replication mechanism that is easy to setup AND maintain, but have found it to be elusive so far.

When you put this all together you end up with a lot of boxes to support. My effort now is creating a two and/or three (physical) server configuration using virtual machines - effectively allowing everything to run on just one box, but ideally on the 2 / 3. This I hope will provide an effective solution that the average IT guy can get his head around. Being Linux based the configured images can then be distributed ready to go.

In a practical sense, trying to achieve 100% uptime is a fruitless task, as there are so many other issues that can affect the perceived QOS of your system.

The basics of good hardware, good network connectivity, good ISP, experienced and motivated support staff ... always apply, and can achieve almost all the desired results for the most. What we are trying to achieve here is perhaps get to that extra level we call excellence!

I'll follow your work with interest.

regards

gary 

 

 

 

 

In reply to Gary Benner

Re: High availability - MySQL cluster v's replication

by Vipen Mahajan -
Gary,
Excellent approach. Could I suggest that in addition you could add a iSCSI box which can also be virtualized, to give redundancy/reliability to the database etc., besides allowing to separate the disk-storage into a modular component, which can be accessed by different boxes/virtual machines.

I have played around with VMware virtual machines, Xen etc must also be good. I feel that virtualization and grid/utility/cloud computing is the way of the future.

Pl. keep up the good work.

Vipen

Very well
In reply to Vipen Mahajan

Re: High availability - MySQL cluster v's replication

by Gary Benner -

Hi all,

Further to my last post, in some ways the search here is for the "holy grail" of performance and (high) availability.

In other areas of my work I'm monitoring a dialogue with the development of 'cloud database' architecture for an open source DB. I must say it is pretty heavy duty stuff and at times goes a little above my personal cpu resources.

However I believe that in time - perhaps over the next 3-4 years - we will see a solution, hopefully open source - that will allow us to not have to worry to much with some of the 'work arounds' to get what we want in this regard.

I presume that most on this list (by the nature of the discussion) are application oriented, rather than DB system designers. And our solutions are engineered on this level. It would be nice that an easy to use solution to the back end scaling and replication was available out of the box. But in reality it is not quite there yet.

In our own systems we have developed a system design for high end applications where we do all DB access through a SOAP interface, where the application code ( running on the web server ) provides the facility to access multiple soap servers ( a middle tier ) using round robin access like Ldirectord in the Linux LVS HA . This gives us performance and reliability. The soap servers "know" what requires a write to the database, and direct those queries to the current Master in a set of DB servers. DB reads are shared amongst all DB servers ( slaves and master ). The DB servers replicate instantly at a query level ( NOT at the underlying filesystem level as with DRDB ) and respect DB transactions. In a situation where the master DB server fails, the soap servers detect this ( at the first failed write ) and instigate a message to change the replication configuration - using a sort of STONITH technique ( "shoot the other node in the head" ) to make sure the failed master does not participate further until checked and reinserted manually into the DB server set.

BTW we use the Firebird DB server - it is FULLY open source, and the feature set close to Oracle. In fact it has a version known as Fyracle that is 95% compatible with Oracle. It's replication capability is enhanced by it's "Events" messaging system, allowing the replication process to be triggered instantly as changes occur. Firebird also has a "multi-generational versioning" architecure which means it does not use log files, so recovery from outages is very fast.

Now this architecture described above can only work where the application is structured as I have described. And it may take quite a lot of work to change the Moodle code base to take advantage of this. But maybe as a long term plan it could be considered. 

HTH

Gary

In reply to Hugh Morrow

Re: High availability - MySQL cluster v's replication

by Taylor Judd -

Hi Hugh,

Nice job with the research. You've compiled a lot of separate threads and discussions into a really great summary.

Let me clarify a few things from our perspective at SFSU and my experience.

1) Performance. This is why we use replication. Our major concern is making sure our 30,000 some odd users can all use the system during finals week. This is why we switched to INNODB and threw a whole bunch of RAM at the system. This got us the best performance. We use replication as our backup and statistics system. It is fail over but it primarily is used for us to run statistics on without impacting the live site. It can be used as failover but the few times we've had problems with the main database it has been just minutes to fix the live database which is less time than it would take to implement the failover. I'll also say if you implement INNODB correctly you should be ACID compliant meaning you have little to no risk of loss of data and extremely high reliability/upditme.
http://proquest.safaribooksonline.com/0596102461/I_0596102461_CHP_15_SECT_7

2) DRDB. I don't have a lot of experience, mostly just my own tinkering and reading, but from everyone I've talked to and heard from this is the best for High Availability. If automatic failover and high availability are your concern I'd go here. Do make sure you have enough hardware to run it as my understanding leads me to believe that there can be major performance bottle necks in moodle especially in high SQL write times such as high concurrent use of the moodle quiz.

3) Crashing/table corruption. Corruption is not a problem if your ACID compliant. Under myisam, I had tables crashing left and right about 2 years ago. Now with INNODB, I've never had a table crash. Even if you do crash under query replication, standard in 5.0 but to change in 5.1, the query would not replicate to the slave until it is finished on the live leaving your replicated database in tack. (I haven't tested that last part). A safer bet will be in 5.1 when row based replication gets implemented.

In terms of tuning there is a lot you can do in the my.cnf file. I don't use the out of the box my.cnf but it is always a good starting. Assuming you are using dedicated hardware for the database some basic items:

1. make sure you have the right RAID with a battery backup write cache.
2. All RAM should be allcollated to mysql with maybe half a gig reserved for the system.
3. Disable any engines you are not using: innodb ect. (Can't disable myisam as it is required for the mysql table)
4. Memcached is great for mysql performance. (actually all caching is)
5. Innodb is easy to configure for memory... throw it all at the innodb_buffer_pool
6. Myisam is a little more tricky but lots of good information on it online.
7. Use jmeter or some other similar load testing software. Have it throw everything it can at your install and see how you do. Tweek as necessary based on this info preferably before you go live.
8. MONITOR MONITOR MONITOR. Use MRTG or Cacti or Mysql Enterprise or something to actively monitor your database for performance changes. Much easier to do this from the start than to try and go back and look at 'show extended status' and try to figure it out after the fact.

Hope some of this helps if anything is unclear or I'm wrong about please let me know.

Cheers.


In reply to Taylor Judd

Re: High availability - MySQL cluster v's replication

by Dan Poltawski -
3) Crashing/table corruption. Corruption is not a problem if your ACID compliant. Under myisam, I had tables crashing left and right about 2 years ago. Now with INNODB, I've never had a table crash. Even if you do crash under query replication, standard in 5.0 but to change in 5.1, the query would not replicate to the slave until it is finished on the live leaving your replicated database in tack. (I haven't tested that last part). A safer bet will be in 5.1 when row based replication gets implemented.


My worry with mysql replication is actually that slave updates could can get lost without any problem (until a delete statement has been silently dropped and someone tries to insert a duplicate clashing constraint).

The mechanics of mysql replication are actually pretty damn scary when you think about it.. log all your updates and keep sending them over there.. without knowing if they were recieved or anything (I stlll use it :/ )
In reply to Dan Poltawski

Re: High availability - MySQL cluster v's replication

by Martín Langhoff -

lost without any problem

Except for that niggly concept of data integrity. mixed As you say, the mechanics of replication on MySQL are not pretty. So we are between easy-to-setup-but-might-lose-data MySQL replication and bulletproof-but-hard-to-configure Pg replication.

Magic 8-ball says "wait a few releases and retry" wide eyes

In reply to Hugh Morrow

Re: High availability - MySQL cluster v's replication

by Jonathan Moore -
You seem to have covered most/all the points of debate. if your performance needs are one server or less, ie one server total for apache and database combined. I like DRBD in combination with a virtualization technology (I'm fond of openvz) to contain all the complexity of the setup, IE if one server is fast enough to keep up with your load, then there is a lot to be said for doing the HA via DRBD and Heartbeat. No special parts and pretty good fail over for hardware based issues and you only need two off the shelf even low end servers to pull it off. Combine this with some form of backup software that supports snapshots on a decent interval and you have some backup for sql problems that replicate between the two hosts.

As you point out there are certain classes of problems that this doesn't protect againts and I think things get much murkier when/if you need to scale up to multiple numbers of servers. There are some pretty good articles out in the mysql community discussion the relative merits of DRBD vs binary log replication. For example if I remember right with innobd based tables you can have a long startup time after a fail over for DRBD solutions while certain database checks are performed. On the flip side binary replication doesn't have a gaurenteed convergence time for when the two units will be in sync. Additionally, the syncing method is not multi-entrant so I have read reports of the database slave having to be much bigger hardware wise so it can keep up with the master with only one cpu core.


In reply to Hugh Morrow

Re: High availability - MySQL cluster v's replication

by Dan Poltawski -
There is actually a third posibility with mysql replication 'tricked' into doing dual-master replication (using different auto-increment values). This is useful for a rapid switch to a 'slave' server.
In reply to Dan Poltawski

Re: High availability - MySQL cluster v's replication

by HJWUCGA INC. -
Hi Dan,

Could you please elaborate in detail on how to best try/test/use this approach?

thanks
In reply to Dan Poltawski

Re: High availability - MySQL cluster v's replication

by Marc Grober -
Can anyone comment on:
http://dev.mysql.com/tech-resources/articles/advanced-mysql-replication.html
vis-a-vis Moodle and fail over?
In reply to Marc Grober

Re: High availability - MySQL cluster v's replication

by Martín Langhoff -
Marc - the original poster isdoing exactly that. Commenting on those options. Do read the whole thread. Also I have posted in the past about mysql cluster at least.

Make sure you also review PostgreSQL PITR, which I've also discussed here in connection to a very nice set of scripts that give you a Magic Power over your moodle install.

Such is the power of Potent Magic, GIT and Pg. Search and ye shall find.