<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Performance Blog &#187; High Availability</title>
	<atom:link href="http://www.mysqlperformanceblog.com/category/high-availability/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 03:11:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Finding your MySQL High-Availability solution – Replication</title>
		<link>http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 20:22:36 +0000</pubDate>
		<dc:creator>yves</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1607</guid>
		<description><![CDATA[In the last 2 blog posts about High Availability for MySQL we have introduced definitions and provided a list of ( questions that you need to ask yourself before choosing a HA solution.  In this new post, we will cover what is the most popular HA solution for MySQL, replication.  
High Availability solution [...]]]></description>
			<content:encoded><![CDATA[<p>In the last 2 blog posts about High Availability for MySQL we have introduced <a href="http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/">definitions</a> and provided a list of (<a href="http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%E2%80%93-the-questions/"> questions</a> that you need to ask yourself before choosing a HA solution.  In this new post, we will cover what is the most popular HA solution for MySQL, replication.  </p>
<h3>High Availability solution for MySQL: Replication</h3>
<p>This HA solution is the easiest to implement and to manage.  You basically need to setup MySQL replication between a master and one or more slaves.  Upon failure of the master, one of the slaves is manually promoted to the master role and replication on the other slaves is re-adjusted to point to the new master.  This solution works well with all the MySQL storage engines including MyISAM (NDB is a special discussed later) but it suffers from the limitation of MySQL replication.  The main limitation, in term of HA, is the asynchronous design of MySQL replication which does not allow the master to be sure the slave has been updated before returning after a <em>commit</em> statement.  There is a window in time where it is possible that a fully committed transaction has not been pushed to the slave(s) leading to data loss.  Many large websites that are fine with some data loss rely on replication for HA and for read scaling.  </p>
<p>In addition to hardware failure, the level of availability of this solution is affected by the availability of the MySQL replication link between the servers.  Replication often break for various reasons and while replication is broken, there is no High-Availability.  Also, the availability of this solution is affected by how much the slaves were behind the master when the outage occurred.  So, if you want to have a good level of availability, you need a good monitoring and alerting system to quickly react to replication issue and you need a rather small write load so that the slaves do not lag behind the master too much.  To maximize the level of availability, recovery should be automatic.</p>
<p>Apart of its simplicity, an HA solution based on replication as many interesting properties, no wonder it is so popular.  First, if the application is well designed and has specific database handles for read and write operations,  this HA solution can scales the read operations to a high level.  Using the slaves for reads cause a second interesting side effect, the caches of the slaves are hot so failing over to a slave means no degraded performance associated with caches warm up.  Finally, it is well known that with MySQL,  altering a table means  recreating the whole table and it is a blocking operations.  Altering a large table may takes many hours.  The trick here is to run the alter table on a slave and then, once done, we let the slave catch up with the master using the new table schema, we failover to the slave and repeat the alter table on the other server.  Those online schema change are easier when a master to master topology is used.  </p>
<p>The following figure summarize the simplest HA architecture using MySQL replication.  All writes are going to the master while reads are spread between the master and the slave.  Upon failure of the master, replication is stopped on the slave and all traffic is redirected to the slave which now handles reads and writes.</p>
<p><img src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/11/replication1.png" alt="HA replication" title="HA replication" width="524" height="322" class="alignnone size-full wp-image-1699" /></p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef"><b>Pros</b></td>
<td bgcolor="#efefef"><b>Cons</b></td>
</tr>
<tr>
<td>Simple</td>
<td>Variable level of availability (98-99.9+%)</td>
</tr>
<tr>
<td>Inexpensive</td>
<td>Not suitable for high write loads</td>
</tr>
<tr>
<td>All the servers can be used, no idle standby</td>
<td>read scaling only if application splits reads from writes</td>
</tr>
<tr>
<td>Supports MyISAM</td>
<td>Can lose data</td>
</tr>
<tr>
<td>Caches on failover slave are not cold</td>
<td></td>
</tr>
<tr>
<td>Online schema changes</td>
<td></td>
</tr>
<tr>
<td>Low impact backups</td>
<td></td>
</tr>
</table>
<h3> Automatic failover with replication</h3>
<p>I already mentioned that for best HA levels, failover or recovery should be automatic.  There are tools to manage automatic failover  with replication like MMM, Flipper and Tungsten.  Here, I will quickly describe the most popular one, MMM.</p>
<p>With MMM, you need to add a separate server, the Manager that, like the name imply, manages the availability of the MySQL service.  A high availability solution based on MMM requires at the 2 MySQL servers configured in a Master to Master topology.  Additional slaves can also be added.  A MMM agent runs on all the MySQL servers and it is used to do OS level operations.  The principle of operation of MMM is based on VIPs.  There is one write VIP, where write operations are sent and as many read VIPs as the number of MySQL servers.  For the write VIP, MMM monitors the state of the current master and, upon failure, try to kill all the connections to the failing server and transfer the write VIP to the other master.  For the read VIPs, MMM monitors the state of the slaves and remove the read VIP of a slave if it has failed or is lagging behind the master by more than a defined threshold.  One of the main limitation of MMM is its lack of fencing capability.  It is important to stop all the connections to the failing master and if that server is not responding, maybe because of a network problem, a stonith device must be used to fence it.  I am far from being an expert with MMM, other guys on my team are way better than me, but I heard that the MMM v1 code base had some deficiencies.  MMM v2 is a complete rewrite that addresses some of the shortcomings of v1. Walter Heck from OpenQuery gave an excellent <a href="http://forge.mysql.com/wiki/Dual_Master_Setups_With_MMM">webinar</a> on it recently.</p>
<p>The architecture of a highly available setup using MMM and Master-Master replication is presented on the figure below. Apart from the minimum requirement of two MySQL servers replicating each other, there is a third server, called the manager, that controls both MySQL server through an agent that is running on each server. The manager controls and monitors the state of the replication and assign virtual IPs for specific roles.  There are one VIP where write operations are sent and two or more VIPs where read operations are sent.  If replication on one of the MySQL servers lags behind too much, its read VIP will be moved to another server.</p>
<p><img src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/11/master-master.png" alt="master-master" title="master-master" width="528" height="537" class="alignnone size-full wp-image-1700" /></p>
<p>As a conclusion, replication can be used in many cases to build effective and scalable highly available solutions but it has some limitations.  In my next blog post, I&#8217;ll present another HA solution build around Heartbeat and DRBD.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by yves |
      <a href="http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/#comments">No comment</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/&amp;title=Finding your MySQL High-Availability solution – Replication" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/&amp;title=Finding your MySQL High-Availability solution – Replication" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/&amp;title=Finding your MySQL High-Availability solution – Replication" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/&amp;T=Finding your MySQL High-Availability solution – Replication" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/&amp;title=Finding your MySQL High-Availability solution – Replication" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/11/13/finding-your-mysql-high-availability-solution-%e2%80%93-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>State of the art: Galera &#8211; synchronous replication for InnoDB</title>
		<link>http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 15:08:58 +0000</pubDate>
		<dc:creator>Vadim</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[Innodb]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[xtradb]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1556</guid>
		<description><![CDATA[First time I heard about Galera on Percona Performance Conference 2009, Seppo Jaakola was presenting &#8220;Galera: Multi-Master Synchronous MySQL Replication Clusters&#8221;. It was impressed as I personally always wanted it for InnoDB, but we had it in plans at the bottom of the list, as this is very hard to implement properly.
The idea by itself [...]]]></description>
			<content:encoded><![CDATA[<p>First time I heard about Galera on Percona Performance Conference 2009, Seppo Jaakola was presenting <a href="http://www.percona.com/ppc2009/PPC2009_galera.pdf">&#8220;Galera: Multi-Master Synchronous MySQL Replication Clusters&#8221;</a>. It was impressed as I personally always wanted it for InnoDB, but we had it in plans at the bottom of the list, as this is very hard to implement properly.<br />
The idea by itself is not new, I remember synchronous replication was announced for SolidDB on MySQL UC 2007, but later the product was killed by IBM.</p>
<p>So long time after PPC 2009 there was available version mysql-galera-0.6, which had serious flow, to setup a new node you had to take down whole cluster. And all this time Codership ( company that develops Galera) was working on 0.7 release that introduces node propagation keeping cluster online. You can play with 0.7pre release by yourself <a href="http://www.codership.com/en/downloads/galera">MySQL/Galera Release 0.7pre</a>. </p>
<p>In current version propagation is done by mysqldump from one of nodes (&#8221;donor&#8221;). In next release Codership is going to support LVM snapshot and xtrabackup which will make the setup of new node even easier. The current annoyance I see is that if you shutdown one node for short period of time for quick maintenance, after  start, the node has to load whole mysqldump, like it is new empty node. I hope Codership guys will address this also.<br />
Another thing I miss for now is support of InnoDB-plugin, which as we know performs much better than standard InnoDB &reg;.</p>
<p>So what is so interesting about Galera. Couple things:</p>
<p>- High Availability. Any of N standby nodes are available immediately when main node fails. Galera is serious pretender to be included to the list, Yves put recently, <a href="http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/">http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/</a>. I am not sure how many nines it will provide <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , but efforts on test setup and deployment should be comparable with MMM setup.</p>
<p>- Scale Writes. Galera allows to write to any of N nodes and automatically propagate to other nodes. It sounds too ideal, and there is drawback &#8211; with increasing amount of nodes you write to, your transaction rollback rate may increase, especially if you working on the same dataset. You can find some results on <a href="http://www.codership.com/en/content/benchmarking-write-scalability">Codership&#8217;s page</a>,  and I am going to run my own benchmarks also. Also from benchmark you can see that communication overhead maybe significant for short writes.</p>
<p>- Scale Reads. It can be done with regular replication, but  with synchronous your &#8220;slaves-nodes&#8221; are in the same state, there is no &#8220;slave behind&#8221;. When you read from any slave, you read actual data. Although it also has serious drawback &#8211;  our cluster is fast as fast the &#8220;weakest&#8221; node in the chain. So if one node gets overloaded and performance degrades, the same happens with whole cluster.</p>
<p>- Heterogeneous-database replication. It is not here yet, and I do not know what&#8217;s in Codership roadmap, but group manager protocol in Galera is database independent, and it&#8217;s only matter of database drivers. For InnoDB currently it is set of patches, and I see it is quite possible to make the same for Postgres. So MySQL-Postgres cluster setup is not so far ahead <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On <a href="http://www.codership.com/en/company/about">&#8220;Company page&#8221; Codership says</a> their goal is &#8220;to promote and exploit the latest developments in computer science to produce fast and scalable synchronous replication solution that &#8220;just works&#8221; for databases and similar applications&#8221;, which I think they have success in. Implementing fast, scalable and working group communication and transaction manager is the art.</p>
<p>As for now I would not put 0.7 release into production yet, but you may seriously consider to play with it in test environment, and report bugs to Codership team, they are very responsive.<br />
I am waiting for next releases and looking to make integration with XtraDB.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by Vadim |
      <a href="http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/#comments">6 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/&amp;title=State of the art: Galera &#8211; synchronous replication for InnoDB" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/&amp;title=State of the art: Galera &#8211; synchronous replication for InnoDB" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/&amp;title=State of the art: Galera &#8211; synchronous replication for InnoDB" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/&amp;T=State of the art: Galera &#8211; synchronous replication for InnoDB" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/&amp;title=State of the art: Galera &#8211; synchronous replication for InnoDB" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/10/27/state-of-the-art-galera-synchronous-replication-for-innodb/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Finding your MySQL High-Availability solution – The questions</title>
		<link>http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 21:02:55 +0000</pubDate>
		<dc:creator>yves</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1334</guid>
		<description><![CDATA[After having reviewed the definition my the previous post (The definitions), the next step is to respond to some questions.
Do you need MySQL High-Availability?
That question is quite obvious but some times, it is skipped.  It can also be formulated  &#8220;What is the downtime cost of the service?&#8221;.  In the cost, you need [...]]]></description>
			<content:encoded><![CDATA[<p>After having reviewed the definition my the previous post (<a href="http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/">The definitions</a>), the next step is to respond to some questions.</p>
<h3>Do you need MySQL High-Availability?</h3>
<p>That question is quite obvious but some times, it is skipped.  It can also be formulated  &#8220;What is the downtime cost of the service?&#8221;.  In the cost, you need to include lost revenue from the service and you also need to consider less direct impact like loss of corporate image and other marketing costs.  If your downtime cost is under $10/h, you can stop reading this document, you don&#8217;t need HA.  For the others, let&#8217;s move on!</p>
<h3>How to determine which MySQL High-Availability solution is best?</h3>
<p>What is really tricky with MySQL is the number of possible HA solutions.  From the simplest the most complex let&#8217;s list the most common ones:</p>
<p>- MySQL replication with manual failover<br />
- Master-Master with MMM manager<br />
- Heartbeat/SAN<br />
- Heartbeat/DRBD<br />
- NDB Cluster</p>
<p>These technologies are by far, not a one size fits all and many deployments use combination of solutions.  I will not cover ScaleDB and Continuent because I know almost nothing of these solutions. There are many more questions you need to ask yourself before being able to pick the right one.  Below, I listed the most common questions, I might have missed some.</p>
<h4>1. What level of HA do you need?</h4>
<p>Since all the technologies do not offer the same level of availability, this is a first important sorting factor. Here are estimates of the level of availability offered by the various solutions.</p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef">&nbsp;</td>
<td bgcolor="#efefef"><b>Level of availability</b></td>
</tr>
<tr>
<td>Simple replication</td>
<td>98 to 99.9+%</td>
</tr>
<tr>
<td>Master-Master with MMM manager</td>
<td>99% </td>
</tr>
<tr>
<td>Heartbeat/SAN (depends on SAN)</td>
<td>99.5% to 99.9%</td>
</tr>
<tr>
<td>Heartbeat/DRBD</td>
<td>99.9%</td>
</tr>
<tr>
<td>NDB Cluster</td>
<td>99.999%</td>
</tr>
</table>
<p>From the table, if your requirements are for 99.99%, you are restricted to NDB Cluster while if it is only 99% you have more options.  I recall that the level of availability is hard to estimate and subject to debate.  These are the usually accepted level of availability for these technologies.</p>
<h4>2. Can you afford to lose data?</h4>
<p>Obviously, if you are concerned about loss of data, you are most likely using the InnoDB storage engine, since MyISAM is not transactional and do not sync data to disk.  Similarly, MySQL replication is an asynchronous process and although it is fairly fast at transferring data between the master and the slaves, there is a window of time where data loss is possible.</p>
<p>If you can afford to lose some data, you can consider &#8220;MySQL replication&#8221; and &#8220;Master-Master with MMM manager&#8221; otherwise, you can only consider the other three solutions.</p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef">&nbsp;</td>
<td bgcolor="#efefef"><b>Data 100% safe</b></td>
</tr>
<tr>
<td>MySQL replication</td>
<td>no</td>
</tr>
<tr>
<td>Master-Master with MMM manager</td>
<td>no</td>
</tr>
<tr>
<td>Heartbeat/SAN (depends on SAN)</td>
<td>yes</td>
</tr>
<tr>
<td>Heartbeat/DRBD </td>
<td>yes</td>
</tr>
<tr>
<td>NDB Cluster</td>
<td>yes</td>
</tr>
</table>
<h4>3. Does your application use MyISAM only features?</h4>
<p>There are some features like Full text indexes and GIS indexes that are supported only by MyISAM.  The HA solutions that work well with MyISAM are &#8220;MySQL replication&#8221; and &#8220;Master-Master with MMM manager&#8221;.  Depending on the application, the MyISAM Full text indexes might be replaced by another search engine like Sphinx in order to remove the restriction.  There is no HA solution other than the ones based on replication that handles GIS indexes.</p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef">&nbsp;</td>
<td bgcolor="#efefef"><b>HA solutions</b></td>
</tr>
<tr>
<td>Need MyISAM Full text or GIS indexes </td>
<td>&#8220;MySQL replication&#8221; and &#8220;Master-Master with MMM manager&#8221;</td>
</tr>
<tr>
<td>Don&#8217;t use any special MyISAM feature</td>
<td>All</td>
</tr>
<tr>
<td>Can change MyISAM Full text to Sphinx</td>
<td>All</td>
</tr>
</table>
<h4>4. What is the write load?</h4>
<p>The HA solutions we present are not equal in term of their write capacity.  Due to the way replication is implemented, only one thread on the slave can handle the write operations.  If the replication master is multi-cores servers and is heavily writing using multiple threads, the slaves will likely not be able to keep up.  Replication is not the only technology that put a strain on the write capacity, DRBD, a shared storage emulator for Linux, also reduce by about 30% (very dependent on hardware) the write capacity of a database server.  In term of write capacity here are you choices.</p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef">&nbsp;</td>
<td bgcolor="#efefef"><b>Write capacity</b></td>
</tr>
<tr>
<td>MySQL replication</td>
<td>Fair</td>
</tr>
<tr>
<td>Master-Master with MMM manager</td>
<td>Fair</td>
</tr>
<tr>
<td>Heartbeat/SAN (depends on SAN)</td>
<td>Excellent</td>
</tr>
<tr>
<td>Heartbeat/DRBD</td>
<td>Good</td>
</tr>
<tr>
<td>NDB Cluster</td>
<td>Excellent</td>
</tr>
</table>
<h4>5. For what level of growth are you planning?</h4>
<p>Since NDB Cluster is an integrated sharding environment, if you are planning for a growth that will need sharding (splitting the database over multiple servers), then you might need to take a serious at that solution.  If not, then, apart from the write capacity, all the solutions are approximately equal.</p>
<h4>6. How qualified is your staff or support company?</h4>
<p>There is a quite direct relationship between the level of availability and the complexity of the solution.  In order to reach the promised level of availability, the staff maintaining the HA setup, either internal or external, must have the required level of expertise.  The required expertise level is summarized in the table below.</p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef">&nbsp;</td>
<td bgcolor="#efefef"><b>Expertise level</b></td>
</tr>
<tr>
<td>MySQL replication</td>
<td>Typical, average MySQL DBA + some Sysadmin skills</td>
</tr>
<tr>
<td>Master-Master with MMM manager</td>
<td>Good, average MySQL DBA + good Sysadmin skills</td>
</tr>
<tr>
<td>Heartbeat/SAN (depends on SAN)</td>
<td>High, Good MySQL DBA + strong Sysadmin skills</td>
</tr>
<tr>
<td>Heartbeat/DRBD</td>
<td>High, Good MySQL DBA + strong Sysadmin skills</td>
</tr>
<tr>
<td>NDB Cluster</td>
<td>Very high, Specific NDB knowledge, strom MySQL skills and strong Sysadmin skills</td>
</tr>
</table>
<h4>7. How deep are your pocket?</h4>
<p>The last aspect that needs to be considered is the budget, complexity is expensive.  We will consider two types of setup.  The first one is a basic proof of concept of the technology with the hardware tested, the data imported and basic testing and documentation.  A proof of concept setup is a good way to get used to a technology and experiment with it in a test environment.  The other type of setup we will consider is a full production setup that includes extensive testing, fire drills, full documentation, monitoring, alerting, backups, migration to production and post migration monitoring.  Of course, it is the safest way to migrate an HA solution to production.  All the times here are estimates based on field experience, the values presented here are fairly typical and contains some buffers for unexpected problems. Although an HA solution can be built remotely through a KVM over IP and adequate remote power management, an on site intervention with physical access to the servers is the preferred way, especially for the most complex solutions.</p>
<table cellpadding="1" cellspacing="1" summary="" border="1">
<tr>
<td bgcolor="#efefef">&nbsp;</td>
<td bgcolor="#efefef"><b>Proof of concept</b></td>
<td bgcolor="#efefef"><b>Migration to Production</b></td>
</tr>
<tr>
<td>MySQL replication</td>
<td>4 hours</td>
<td>12 hours</td>
</tr>
<tr>
<td>Master-Master with MMM manager</td>
<td>8 hours</td>
<td>24 hours</td>
</tr>
<tr>
<td>Heartbeat/SAN (depends on SAN)</td>
<td> 32 hours</td>
<td>120 hours</td>
</tr>
<tr>
<td>Heartbeat/DRBD</td>
<td>40 hours</td>
<td>120 hours</td>
</tr>
<tr>
<td>NDB Cluster</td>
<td>40 hours</td>
<td>120 hours+</td>
</tr>
</table>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by yves |
      <a href="http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/#comments">27 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/&amp;title=Finding your MySQL High-Availability solution – The questions" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/&amp;title=Finding your MySQL High-Availability solution – The questions" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/&amp;title=Finding your MySQL High-Availability solution – The questions" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/&amp;T=Finding your MySQL High-Availability solution – The questions" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/&amp;title=Finding your MySQL High-Availability solution – The questions" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/10/16/finding-your-mysql-high-availability-solution-%e2%80%93-the-questions/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Finding your MySQL High-Availability solution &#8211; The definitions</title>
		<link>http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 23:03:14 +0000</pubDate>
		<dc:creator>yves</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1331</guid>
		<description><![CDATA[As my first contribution to the MySQL Performance Blog, I joined Percona at the beginning September, I chose to cover the various high-availability (HA) options available for MySQL.  I have done dozen of MySQL HA related engagements while working for Sun/MySQL over the last couple of years using Heartbeat, DRBD and NDB cluster and I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>As my first contribution to the MySQL Performance Blog, I joined Percona at the beginning September, I chose to cover the various high-availability (HA) options available for MySQL.  I have done dozen of MySQL HA related engagements while working for Sun/MySQL over the last couple of years using Heartbeat, DRBD and NDB cluster and I&#8217;ll probably be doing the same at Percona.  I have built my first DRBD based HA solution nearly 10 years ago.</p>
<p>There is quite a lot of confusion surrounding HA solutions for MySQL, I will try to present them objectively, my goal here been not to sell any specific technology but to help people choose the right one for their needs.  This post is first of a series,  I don&#8217;t yet know how many I will write in the series.</p>
<p>Before we start, it must be stated that high-availability is not only a matter of technical solutions, good management practices covering monitoring, alerting, security and documentation are also needed to insure a successful solution. In other words, no solution is fool proof, if a high-availability solution is running in recovery mode for months without nobody caring about it, the risk of a complete failure is much higher.</p>
<p>In order to all be on the same page, I will first give some definitions of the key terms.  I don&#8217;t pretend those definitions are perfect but let&#8217;s build on them.</p>
<p><strong>High-Availability</strong></p>
<p>Let&#8217;s first define what is meant by high-availability.  The most general definition would be that a high-availability setup is special  computer architecture designed to improve the availability of a computer service, like a MySQL database.  High-availability, HA for short, introduces a wealth of peculiar concepts, we will first review the main ones.</p>
<p><strong>Uptime/Downtime</strong></p>
<p>Uptime means the service is available even if degraded as long as it is above some defined performance threshold. Downtime means the opposite, either the service is completely down or unresponsive according to the defined performance threshold.  In many cases, people don&#8217;t define a performance threshold, it is basically the service monitoring frequency and timeout that fix it.</p>
<p><strong> Level of Availability</strong></p>
<p>The level of availability is basically the guaranteed percentage of uptime you will get over a year.  It has always been a subject of debate and it is something hard to evaluate since, most of the time, the samples are small and all the conditions of the deployments are not easily controlled. See the level of availability as the availability you, as the operator of the service, can promise in case of a worse case scenario. For example, 98% availability means a downtime of a little more than 7 days per year.  The cost is approximately an exponential function of the level of availability and has to be compared with the downtime cost. If an HA setup with a level of availability of 99% is fairly simple and affordable, moving to 99.9% and 99.99% can be much more expensive and complex. Also, you need to consider the environmental factors.  If your ISP cannot guarantee you a level of availability of more then 99.9% for the Internet access, it is useless to go beyond that no matter the importance of the application.</p>
<p><strong> Single point of failure (SPOF)</strong></p>
<p>Single points of failure are the things you are looking to remove when you build an HA solution.  Basically, they are the devices/things that if they are not available, the service is down.  A data center can be considered a SPOF at a high enough level of availability.  Usually the more SPOFs you consider, the higher the availability of your solution and the higher its cost.</p>
<p><strong> Recovery/failover</strong></p>
<p>Recovery (or failover) is the process by how a HA setup recovers from a failure. During the recovery time, the service is down.  With the most simple solutions, it can be a manual process but most of the time, it is automatic.  Also, there is a time associated with the recovery.  If a failure happened during the night and the operator is only available from 8am to 5pm then, you might have a recovery time of more than 12 hours.  The more complex solutions have automatic recovery and do not need human intervention.  Once again, although they are some exceptions, faster and automatic recovery usually means higher costs.</p>
<p><strong>Cluster </strong></p>
<p>A bunch of servers used for the same task.  In our case, dedicated to high availability of the MySQL database service.</p>
<p>With theses common definitions, we will then be able to move to the second step, the questions.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by yves |
      <a href="http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/#comments">9 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/&amp;title=Finding your MySQL High-Availability solution &#8211; The definitions" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/&amp;title=Finding your MySQL High-Availability solution &#8211; The definitions" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/&amp;title=Finding your MySQL High-Availability solution &#8211; The definitions" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/&amp;T=Finding your MySQL High-Availability solution &#8211; The definitions" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/&amp;title=Finding your MySQL High-Availability solution &#8211; The definitions" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/10/09/finding-your-mysql-high-availability-solution-the-definitions/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Is DRBD the right choice for me?</title>
		<link>http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 18:00:32 +0000</pubDate>
		<dc:creator>Morgan Tocker</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[drbd]]></category>
		<category><![CDATA[mmm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=716</guid>
		<description><![CDATA[It seems pretty common to find customers install DRBD for the wrong reasons.  There are many pros/cons to compare DRBD to replication, but I&#8217;ve managed to cut down my spiel I give to customers to these two points:

DRBD&#8217;s aim (assuming replication mode C) is to provide 100% consistency, and then as much uptime as [...]]]></description>
			<content:encoded><![CDATA[<p>It seems pretty common to find customers install DRBD for the wrong reasons.  There are many pros/cons to compare DRBD to replication, but I&#8217;ve managed to cut down my spiel I give to customers to these two points:</p>
<ul>
<li>DRBD&#8217;s aim (assuming replication mode C) is to provide 100% consistency, and then as much uptime as possible.</li>
<li>MySQL Replication (with a manager such as <a href="http://code.google.com/p/mysql-master-master/">MMM</a>) aims to have 100% availability, at the potential loss of some data surrounding a failure.</li>
</ul>
<p>So if you are installing DRBD with the aim of purely &#8220;availability&#8221;, and are not worried about losing that last write on the crash to your master database that (hopefully) happens only once every few years, you may be using the wrong technology.</p>
<p>While the prized &#8220;1 minute failover&#8221; is possible in DRBD, it doesn&#8217;t really explain the full picture. The typical crash recovery process in DRBD is a lot longer:</p>
<ul>
<li>After resource transfer, a filesystem check runs (0-5 seconds).</li>
<li>mysqld is started (1-5 seconds)</li>
<li>InnoDB runs through crash recovery (1 minute &#8211; several hours).  Peter wrote about this <a href="http://www.mysqlperformanceblog.com/2006/07/03/choosing-proper-innodb_log_file_size/">here</a>.</li>
<li>The server is then ready to accept connections.</li>
</ul>
<p>Now, having said that:  If you have an application that requires 100% consistency, then DRBD is one of your best choices on the mysql-market today.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by Morgan Tocker |
      <a href="http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/#comments">16 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/&amp;title=Is DRBD the right choice for me?" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/&amp;title=Is DRBD the right choice for me?" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/&amp;title=Is DRBD the right choice for me?" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/&amp;T=Is DRBD the right choice for me?" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/&amp;title=Is DRBD the right choice for me?" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/07/07/is-drbd-the-right-choice-for-me/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Percona at PHP Quebec 09</title>
		<link>http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 20:29:27 +0000</pubDate>
		<dc:creator>Morgan Tocker</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[High Availability]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[percona]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=641</guid>
		<description><![CDATA[Percona presented two talks at PHP Quebec last week &#8211; one on A Tour of MySQL High Availability, and another on Performance Tuning MySQL.  There was a great reaction to showcasing some of the quick-wins that can be found by using the Percona patches. Unfortunately, the one thing that I forgot to mention in [...]]]></description>
			<content:encoded><![CDATA[<p>Percona presented two talks at PHP Quebec last week &#8211; one on <a href="http://www.percona.com/files/presentations/high-availability-phpquebec09.pdf">A Tour of MySQL High Availability</a>, and another on <a href="http://www.percona.com/files/presentations/performance-tuning-phpquebec09.pdf">Performance Tuning MySQL</a>.  There was a great reaction to showcasing some of the quick-wins that can be found by using the Percona patches. Unfortunately, the one thing that I forgot to mention in the slides is that the patches are Open Source and free to use.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by Morgan Tocker |
      <a href="http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/#comments">4 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/&amp;title=Percona at PHP Quebec 09" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/&amp;title=Percona at PHP Quebec 09" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/&amp;title=Percona at PHP Quebec 09" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/&amp;T=Percona at PHP Quebec 09" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/&amp;title=Percona at PHP Quebec 09" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/03/10/percona-at-php-quebec-09/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Faster MySQL failover with SELECT mirroring</title>
		<link>http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 14:13:27 +0000</pubDate>
		<dc:creator>Baron Schwartz</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=584</guid>
		<description><![CDATA[One of my favorite MySQL configurations for high availability is master-master replication, which is just like normal master-slave replication except that you can fail over in both directions.  Aside from MySQL Cluster, which is more special-purpose, this is probably the best general-purpose way to get fast failover and a bunch of other benefits (non-blocking [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favorite MySQL configurations for high availability is master-master replication, which is just like normal master-slave replication except that you can fail over in both directions.  Aside from MySQL Cluster, which is more special-purpose, this is probably the best general-purpose way to get fast failover and a bunch of other benefits (<a href="http://www.mysqlperformanceblog.com/2007/10/29/hacking-to-make-alter-table-online-for-certain-changes/">non-blocking ALTER TABLE</a>, for example).</p>
<p>The benefit is that you have another server with all the same data, up and running, ready to serve queries.  In theory, it's a truly <em>hot</em> standby (stay with me -- that's not really guaranteed).  You don't get this with shared storage or DRBD, although those provide stronger guarantees against data loss if mysqld crashes.  And you can use the standby (passive) master for serving some SELECT queries, taking backups, etc as usual.  However, if you do this <em>you actually compromise your high-availability plan</em> a little, because you can mask the lack of capacity that will result when one of the servers is down and you have to rely on just one server to keep everything on its feet.</p>
<p>If you need really high availability, you can't load the pair of servers more than a single server can handle.  (You can always use the passive server for non-essential needs -- it doesn't have to be completely dead weight.)  As a result, some people choose to <em>make the passive server truly passive, handling none of the application's queries</em>.  It just sits there replicating and doing nothing else.</p>
<p>The problem is that the passive server's caches start to get skewed to handle the write workload from replication, and not the read workload it will have to handle if there's a planned or unplanned failover.  This isn't a big problem on small systems, but with buffer pools in the dozens of gigabytes (which is arguably "small" these days), it starts to matter a lot.  Warming up a system so it's actually responsive can take hours.  As a result, the passive master isn't truly hot anymore.  It needs to handle the workload it's supposed to be ready to take over.  If you fail over to it, it might perform very badly -- get unresponsive, cause tons of I/O, etc.  In reality, it can be completely unusable for a long time.</p>
<p>To measure how much this really matters, I did some tests for a customer who was having troubles with this type of scenario.  I used <a href="http://www.maatkit.org/doc/mk-query-digest.html">mk-query-digest</a> (with some new features) to watch the traffic on the active master and replay SELECT queries against the passive one.  I timed the results and ran them through the analysis part of mk-query-digest.  A simple key lookup ran in tens of milliseconds on the active master, but executed for up to dozens of seconds on the passive one.</p>
<p>After a couple of hours of handling SELECT traffic, these same queries were responding nicely on the passive master, too.</p>
<p>Is that all?  "Buffer pool warmed up, performance is better, case closed!"  No.  This isn't as simple as it sounds on the surface.  There are two things happening and both are important to understand.</p>
<p>The first, most obvious phenomenon is that the buffer pool gets skewed to handle the write workload. Since we're running <a href="http://www.percona.com/percona-lab.html">Percona's patched server</a>, we can actually <a href="http://www.percona.com/docs/wiki/patches:innodb_show_bp">measure what's in the buffer pool</a>.  I measured the active master's buffer pool with the following query:</p>
<div class="igBar"><span id="lsql-3"><a href="#" onclick="javascript:showPlainTxt('sql-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-3">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> table_schema, table_name, page_type, count<span style="color:#006600; font-weight:bold;">&#40;</span>*<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">FROM</span> information_schema.innodb_buffer_pool_content <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;color:#800000;">1</span>, <span style="color: #cc66cc;color:#800000;">2</span>, <span style="color: #cc66cc;color:#800000;">3</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">OUTFILE</span> <span style="color: #ff0000;">'/tmp/buffer-pool-contents.txt'</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I loaded this file into a table on my laptop with LOAD DATA INFILE and kept it for later.  I did the same on the slave.  Then I used mk-query-digest to watch the traffic on the active master:</p>
<div class="igBar"><span id="lcode-4"><a href="#" onclick="javascript:showPlainTxt('code-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-4">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mk-query-digest --processlist h=active \</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; --filter <span style="color:#CC0000;">'$event-&gt;{arg} =~ m/^SELECT/i'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; --execute h=passive </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>After a bit I CTRL-C'ed it and it printed out the analysis of the time taken to run the queries against the passive master.  I restarted it and after a few hours of this I did the same thing; the query timings were dramatically better now.  Then I just let it keep running without any aggregation options to avoid any overhead of storing and analyzing queries.  (I added --mirror and --daemonize options so it can run in the background and follow along when the passive/active roles switch.)</p>
<p>After a day or so of doing this, I re-sampled the buffer pool contents on the passive server.  With all three samples stored in tables on my laptop, I wrote a query against these three sets of stats to find the top tables on the active server and left-join those against the tables on the passive server, with both a mixed workload from my mirrored SELECT statements and with the "pure" replication workload.  I totaled the pages up into gigabytes.  Here's the result:</p>
<table border="1">
<tr>
<th> db_table               </th>
<th> active </th>
<th> passive + SELECT  </th>
<th> passive </th>
</tr>
<tr>
<td> site.benefits          </td>
<td> 8.30 </td>
<td> 5.73 </td>
<td> 1.32 </td>
</tr>
<tr>
<td> .                      </td>
<td> 3.13 </td>
<td> 0.94 </td>
<td> 0.50 </td>
</tr>
<tr>
<td> site.user_actions      </td>
<td> 2.55 </td>
<td> 4.09 </td>
<td> 6.29 </td>
</tr>
<tr>
<td> site.user_achievements </td>
<td> 1.36 </td>
<td> 1.20 </td>
<td> 0.35 </td>
</tr>
<tr>
<td> site.clicks            </td>
<td> 1.26 </td>
<td> 3.05 </td>
<td> 5.13 </td>
</tr>
<tr>
<td> site.actions_finished  </td>
<td> 1.14 </td>
<td> 0.46 </td>
<td> 0.74 </td>
</tr>
<tr>
<td> site.ratings           </td>
<td> 0.91 </td>
<td> 0.89 </td>
<td> 0.48 </td>
</tr>
</table>
<p>The difference is clear.  The buffer pool contains over 8G of data for the site.benefits table on the active master, but if you just put a replication workload on the server, that falls to 1.32G.  Other tables are similar.  The mixed workload with some SELECT queries mirrored is somewhere between the two.</p>
<p>One thing we don't know is which pages are in the pool. Same table, same size of data doesn't mean same buffer pool contents.  An insert-only workload will probably fill the buffer pool with the most recent data; a mixed workload will usually have some different hot spot or mixture of hot spots, so it'll bring different parts of the table into memory.</p>
<p>So that's the first thing that's happening.  The second is the insert buffer.  Notice the pages with no database or table name -- the second row in the table above.  Those are a mixture of things, but it's overwhelmingly the insert buffer.</p>
<p>As <a href="http://www.mysqlperformanceblog.com/2009/01/13/some-little-known-facts-about-innodb-insert-buffer/">Peter explained in his recent post on the insert buffer</a>, the other thing the SELECTs do is keep the insert buffer in a production steady-state.  The buffered records are forced to be merged by the SELECTs, and a lot more of the pages from the insert buffer are in the buffer pool, not on disk.  So it's not just the buffer pool that gets skewed with a write-only workload!  The insert buffer can also cause terrible performance.  There are some subtleties about exactly what's happening that I'm still investigating and may write more about later, in this particular case.</p>
<p>So what can we conclude from this?  Simply this: if you have a standby server that's not under a realistic workload, you won't be able to get good performance after a failover.  You need to use some technique to mirror the read-only workload to the passive server.  It doesn't have to be the tools I used -- it could be MySQL Proxy or a TCP sniffer or anything else.  But if you need fast failover, you need some way to at least partially emulate a production workload on the standby machine.</p>
<p>PS: I see <a href="http://scale-out-blog.blogspot.com/2009/02/simple-ha-with-postgresql-point-in-time.html">Robert Hodges just published an article on warm standby for PostgreSQL</a>.  Link love for interested readers.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by Baron Schwartz |
      <a href="http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/#comments">9 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/&amp;title=Faster MySQL failover with SELECT mirroring" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/&amp;title=Faster MySQL failover with SELECT mirroring" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/&amp;title=Faster MySQL failover with SELECT mirroring" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/&amp;T=Faster MySQL failover with SELECT mirroring" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/&amp;title=Faster MySQL failover with SELECT mirroring" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/02/01/fast-mysql-master-master-failover-with-select-mirroring/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
