<?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>Xaprb &#187; Giuseppe Maxia</title>
	<atom:link href="http://www.xaprb.com/blog/tag/giuseppe-maxia/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog</link>
	<description>Stay curious!</description>
	<lastBuildDate>Thu, 09 Feb 2012 03:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>There&#8217;s a European OpenSQL Camp coming up</title>
		<link>http://www.xaprb.com/blog/2010/06/29/theres-a-european-opensql-camp-coming-up/</link>
		<comments>http://www.xaprb.com/blog/2010/06/29/theres-a-european-opensql-camp-coming-up/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 12:32:53 +0000</pubDate>
		<dc:creator>Xaprb</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[OpenSQL Camp]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[cassandra]]></category>
		<category><![CDATA[Giuseppe Maxia]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=1905</guid>
		<description><![CDATA[In addition to the Boston edition, there&#8217;s an OpenSQL Camp at the same time and place as FrOSCon mid-August in Germany. The call for papers is open until July 11th. As always, the conference is about all kinds of open-source databases: MySQL and PostgreSQL are only two of the obvious ones; MongoDB and Cassandra featured [...]


<strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2010/06/25/opensql-camp-boston-2010/' rel='bookmark' title='Permanent Link: OpenSQL Camp Boston 2010'>OpenSQL Camp Boston 2010</a></li>
<li><a href='http://www.xaprb.com/blog/2009/08/29/opensql-camp-events-in-2009/' rel='bookmark' title='Permanent Link: OpenSQL Camp events in 2009'>OpenSQL Camp events in 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2009/11/17/recap-of-portland-opensql-camp-2009/' rel='bookmark' title='Permanent Link: Recap of Portland OpenSQL Camp 2009'>Recap of Portland OpenSQL Camp 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2010/04/18/the-history-of-opensql-camp/' rel='bookmark' title='Permanent Link: The history of OpenSQL Camp'>The history of OpenSQL Camp</a></li>
<li><a href='http://www.xaprb.com/blog/2008/09/17/opensql-camp-develops-further/' rel='bookmark' title='Permanent Link: OpenSQL Camp develops further'>OpenSQL Camp develops further</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>In addition to the Boston edition, there&#8217;s an <a href="http://opensqlcamp.org/Events/FrOSCon2010/">OpenSQL Camp at the same time and place as FrOSCon</a> mid-August in Germany.  The call for papers is open until July 11th.  As always, the conference is about all kinds of open-source databases: MySQL and PostgreSQL are only two of the obvious ones; MongoDB and Cassandra featured prominently at the last one I attended, and SQLite was well represented at the first one.</p>

<p><strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2010/06/25/opensql-camp-boston-2010/' rel='bookmark' title='Permanent Link: OpenSQL Camp Boston 2010'>OpenSQL Camp Boston 2010</a></li>
<li><a href='http://www.xaprb.com/blog/2009/08/29/opensql-camp-events-in-2009/' rel='bookmark' title='Permanent Link: OpenSQL Camp events in 2009'>OpenSQL Camp events in 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2009/11/17/recap-of-portland-opensql-camp-2009/' rel='bookmark' title='Permanent Link: Recap of Portland OpenSQL Camp 2009'>Recap of Portland OpenSQL Camp 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2010/04/18/the-history-of-opensql-camp/' rel='bookmark' title='Permanent Link: The history of OpenSQL Camp'>The history of OpenSQL Camp</a></li>
<li><a href='http://www.xaprb.com/blog/2008/09/17/opensql-camp-develops-further/' rel='bookmark' title='Permanent Link: OpenSQL Camp develops further'>OpenSQL Camp develops further</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.xaprb.com/blog/2010/06/29/theres-a-european-opensql-camp-coming-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSQL Camp 2009 plans announced</title>
		<link>http://www.xaprb.com/blog/2009/06/09/opensql-camp-2009-plans-announced/</link>
		<comments>http://www.xaprb.com/blog/2009/06/09/opensql-camp-2009-plans-announced/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 12:33:50 +0000</pubDate>
		<dc:creator>Xaprb</dc:creator>
				<category><![CDATA[OpenSQL Camp]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Giuseppe Maxia]]></category>
		<category><![CDATA[Lenz Grimmer]]></category>

		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=1130</guid>
		<description><![CDATA[I&#8217;m happy that Lenz Grimmer and Giuseppe Maxia have organized an OpenSQL Camp event in Germany in August. Hooray! Further Reading:OpenSQL Camp events in 2009 Recap of Portland OpenSQL Camp 2009 Going to OpenSQL Camp US 2009 There&#8217;s a European OpenSQL Camp coming up Join OpenSQL Camp on Facebook


<strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2009/08/29/opensql-camp-events-in-2009/' rel='bookmark' title='Permanent Link: OpenSQL Camp events in 2009'>OpenSQL Camp events in 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2009/11/17/recap-of-portland-opensql-camp-2009/' rel='bookmark' title='Permanent Link: Recap of Portland OpenSQL Camp 2009'>Recap of Portland OpenSQL Camp 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2009/10/19/going-to-opensql-camp-us-2009/' rel='bookmark' title='Permanent Link: Going to OpenSQL Camp US 2009'>Going to OpenSQL Camp US 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2010/06/29/theres-a-european-opensql-camp-coming-up/' rel='bookmark' title='Permanent Link: There&#8217;s a European OpenSQL Camp coming up'>There&#8217;s a European OpenSQL Camp coming up</a></li>
<li><a href='http://www.xaprb.com/blog/2008/10/16/join-opensql-camp-on-facebook/' rel='bookmark' title='Permanent Link: Join OpenSQL Camp on Facebook'>Join OpenSQL Camp on Facebook</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy that Lenz Grimmer and Giuseppe Maxia have organized <a href="http://opensqlcamp.org/Events/2009/">an OpenSQL Camp event in Germany in August</a>.  Hooray!</p>

<p><strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2009/08/29/opensql-camp-events-in-2009/' rel='bookmark' title='Permanent Link: OpenSQL Camp events in 2009'>OpenSQL Camp events in 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2009/11/17/recap-of-portland-opensql-camp-2009/' rel='bookmark' title='Permanent Link: Recap of Portland OpenSQL Camp 2009'>Recap of Portland OpenSQL Camp 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2009/10/19/going-to-opensql-camp-us-2009/' rel='bookmark' title='Permanent Link: Going to OpenSQL Camp US 2009'>Going to OpenSQL Camp US 2009</a></li>
<li><a href='http://www.xaprb.com/blog/2010/06/29/theres-a-european-opensql-camp-coming-up/' rel='bookmark' title='Permanent Link: There&#8217;s a European OpenSQL Camp coming up'>There&#8217;s a European OpenSQL Camp coming up</a></li>
<li><a href='http://www.xaprb.com/blog/2008/10/16/join-opensql-camp-on-facebook/' rel='bookmark' title='Permanent Link: Join OpenSQL Camp on Facebook'>Join OpenSQL Camp on Facebook</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.xaprb.com/blog/2009/06/09/opensql-camp-2009-plans-announced/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress on Maatkit bounty, part 3</title>
		<link>http://www.xaprb.com/blog/2007/12/06/progress-on-maatkit-bounty-part-3/</link>
		<comments>http://www.xaprb.com/blog/2007/12/06/progress-on-maatkit-bounty-part-3/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 11:29:44 +0000</pubDate>
		<dc:creator>Xaprb</dc:creator>
				<category><![CDATA[checksum]]></category>
		<category><![CDATA[Giuseppe Maxia]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[synchronization]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/12/06/progress-on-maatkit-bounty-part-3/</guid>
		<description><![CDATA[<p>This is the last day I'm taking off work to hack on mk-table-sync, and I thought it was time for (yet another) progress report.  Here's what I have done so far.  (Click through to the full article to read the details).</p>


<strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2007/12/03/progress-on-maatkit-bounty-part-2/' rel='bookmark' title='Permanent Link: Progress on Maatkit bounty, part 2'>Progress on Maatkit bounty, part 2</a></li>
<li><a href='http://www.xaprb.com/blog/2007/11/30/progress-on-maatkit-bounty/' rel='bookmark' title='Permanent Link: Progress on Maatkit bounty'>Progress on Maatkit bounty</a></li>
<li><a href='http://www.xaprb.com/blog/2007/12/06/progress-on-maatkit-bounty-part-4/' rel='bookmark' title='Permanent Link: Progress on Maatkit bounty, part 4'>Progress on Maatkit bounty, part 4</a></li>
<li><a href='http://www.xaprb.com/blog/2007/11/29/maatkit-bounty-begins-tomorrow/' rel='bookmark' title='Permanent Link: Maatkit bounty begins tomorrow'>Maatkit bounty begins tomorrow</a></li>
<li><a href='http://www.xaprb.com/blog/2008/02/29/how-to-sync-tables-in-master-master-mysql-replication/' rel='bookmark' title='Permanent Link: How to sync tables in master-master MySQL replication'>How to sync tables in master-master MySQL replication</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>This is the last day I&#8217;m taking off work to hack on mk-table-sync, and I thought it was time for (yet another) progress report.  Here&#8217;s what I have done so far:</p>

<ul>
<li>All the code, except for a tiny bit of &#8220;glue&#8221; and &#8220;setup&#8221; code, is in modules.</li>
<li>Lots more tests for the modules.</li>
<li>A new sync algorithm (I still haven&#8217;t rewritten the top-down and bottom-up, which are designed for network efficiency more than MySQL efficiency, and are very complicated).  This algorithm is called &#8220;Chunk&#8221; and is based on the chunking module I&#8217;m re-using from two of the other tools.  This allows syncing the table a bit at a time to avoid locking it so much.</li>
<li>The tool chooses its own parameters, including choosing the sync algorithm automatically by examining indexes.</li>
<li>Proper exit codes, as well as several other smaller issues requested via bug reports.</li>
<li>The tool now syncs entire servers.  That is, you don&#8217;t have to specify a table.  It&#8217;ll find all the tables and just sync them.</li>
<li>The tool can sync many servers.  You give it five servers, it will treat the first as the source, and sync every table in the source to each of the four remaining servers in turn.</li>
<li>It can work via replication.  It can discover a master&#8217;s slaves via SHOW SLAVE HOSTS and sync each slave to the master.  You can also point it at a slave and it&#8217;ll discover the master, connect to it, and sync the slave to the master.</li>
<li>It integrates with mk-table-checksum&#8217;s results.  If you&#8217;ve given the &#8211;replicate option to mk-table-checksum, the slave&#8217;s results are stored in a table.  It can read that table and sync anything marked as different.  This can be combined with sync-to-master and auto-discover-slaves functionality.</li>
<li>Lots of other bugs and problems are gone simply because I&#8217;m using the modules I wrote for other tools.  This includes issues with table parsing, identifier quoting, etc etc.  As an aside, I have to roll my own for almost everything, because I can&#8217;t rely on things like DBI&#8217;s <code>quote_identifier()</code> function &#8212; it does not work in earlier versions, which are amazingly common in the real world.</li>
</ul>

<p>Whew!  So what isn&#8217;t done yet?</p>

<ul>
<li>Bi-directional syncing.</li>
<li>The Nibble sync algorithm.  It will be preferred over Chunk and can be used in more cases.</li>
<li>Documentation.</li>
<li>Full support for wide characters.  (This is non-trivial in Perl.  I need to research it.  A partial solution might not be hard, but I&#8217;m worried about the versions included in, for example, RHEL 3, which is very widely used.)</li>
<li>Updating other tools to work right with the changes to shared code.</li>
<li>Locking and transaction code.  The tool will ultimately use FOR UPDATE/LOCK IN SHARE MODE automatically on InnoDB tables instead of locking them, for example.</li>
</ul>

<p>Here&#8217;s a sample of what it can do, using a replication sandbox I set up with Giuseppe&#8217;s <a href="http://sourceforge.net/projects/mysql-sandbox">MySQL Sandbox</a>.  The sandbox contains a copy of the Sakila sample database.  I&#8217;ll just mangle a few films on the slaves:</p>

<pre>baron@kanga:~$ cd rsandbox_5_0_45/
baron@kanga:~/rsandbox_5_0_45$ ./s1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.45-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

slave1 [localhost] {msandbox} ((none)) &gt; update sakila.film set title='academy dinosaur2' limit 12;
Query OK, 12 rows affected, 12 warnings (0.07 sec)
Rows matched: 12  Changed: 12  Warnings: 0

slave1 [localhost] {msandbox} ((none)) &gt; Bye
baron@kanga:~/rsandbox_5_0_45$ ./s2
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.45-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

slave2 [localhost] {msandbox} ((none)) &gt; update sakila.film set title='academy dinosaur2' limit 1;
Query OK, 1 row affected, 1 warning (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0

slave2 [localhost] {msandbox} ((none)) &gt; Bye</pre>

<p>OK, now I&#8217;ve messed up the first 12 films on one slave, and the first 1 on another.  I could just go ahead and sync them right away, but first I&#8217;ll do a table checksum to demonstrate that functionality:</p>

<pre>baron@kanga:~/rsandbox_5_0_45$ mk-table-checksum --replicate=test.checksum --port=16045 127.0.0.1 -q
</pre>

<p>And now I&#8217;ll tell the sync tool to go fix the differences the checksum revealed:</p>

<pre>
baron@kanga:~/rsandbox_5_0_45$ mk-table-sync  --replicate=test.checksum h=127.0.0.1,P=16045 -vx
# Syncing P=16046,h=127.0.0.1
# DELETE INSERT UPDATE ALGORITHM DATABASE.TABLE
#      0      0     12 Chunk     sakila.film
#      0      0      0 Chunk     sakila.film_text
# Syncing P=16047,h=127.0.0.1
# DELETE INSERT UPDATE ALGORITHM DATABASE.TABLE
#      0      0      0 Chunk     sakila.film
#      0      0      0 Chunk     sakila.film_text
baron@kanga:~/rsandbox_5_0_45$ 
</pre>

<p>Pretty easy, huh?  Take a look at the output: the first thing it did was fix the 12 films I changed.  <code>sakila.film</code> has a trigger that updates <code>sakila.film_text</code>, so that table got changed too.  The checksum tool caught this difference, but the differences were gone by the time the sync tool examined them, again due to the trigger.  On the second slave, no differences were found at all, because the changes to the first slave were made on the master, automatically fixing the second slave.  (This won&#8217;t always be the case, but it worked in this example).</p>

<p>While I&#8217;d love to continue building the perfect beast, I&#8217;m going to have to call it quits around noon today and start cleaning up, writing the documentation, and getting ready to release the code.  I&#8217;m not sure how much I&#8217;ll finish in that time.</p>

<p>By the way, anyone who wants to is welcome to get the code from the <a href="http://code.google.com/p/maatkit/">Maatkit</a> SVN repository!  I never make a big deal out of that because I generally assume people want to run released code, but SVN is there if you want it&#8230;</p>

<p><strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2007/12/03/progress-on-maatkit-bounty-part-2/' rel='bookmark' title='Permanent Link: Progress on Maatkit bounty, part 2'>Progress on Maatkit bounty, part 2</a></li>
<li><a href='http://www.xaprb.com/blog/2007/11/30/progress-on-maatkit-bounty/' rel='bookmark' title='Permanent Link: Progress on Maatkit bounty'>Progress on Maatkit bounty</a></li>
<li><a href='http://www.xaprb.com/blog/2007/12/06/progress-on-maatkit-bounty-part-4/' rel='bookmark' title='Permanent Link: Progress on Maatkit bounty, part 4'>Progress on Maatkit bounty, part 4</a></li>
<li><a href='http://www.xaprb.com/blog/2007/11/29/maatkit-bounty-begins-tomorrow/' rel='bookmark' title='Permanent Link: Maatkit bounty begins tomorrow'>Maatkit bounty begins tomorrow</a></li>
<li><a href='http://www.xaprb.com/blog/2008/02/29/how-to-sync-tables-in-master-master-mysql-replication/' rel='bookmark' title='Permanent Link: How to sync tables in master-master MySQL replication'>How to sync tables in master-master MySQL replication</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.xaprb.com/blog/2007/12/06/progress-on-maatkit-bounty-part-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How fast is MySQL replication?</title>
		<link>http://www.xaprb.com/blog/2007/10/23/how-fast-is-mysql-replication/</link>
		<comments>http://www.xaprb.com/blog/2007/10/23/how-fast-is-mysql-replication/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 02:00:48 +0000</pubDate>
		<dc:creator>Xaprb</dc:creator>
				<category><![CDATA[Federated storage engine]]></category>
		<category><![CDATA[Giuseppe Maxia]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL slave lag]]></category>
		<category><![CDATA[polling]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[User Defined Functions]]></category>

		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/10/23/how-fast-is-mysql-replication/</guid>
		<description><![CDATA[<p>Very fast, as it turns out.  Click through to the full article for details.</p>


<strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2007/11/08/how-mysql-replication-got-out-of-sync/' rel='bookmark' title='Permanent Link: How MySQL replication got out of sync'>How MySQL replication got out of sync</a></li>
<li><a href='http://www.xaprb.com/blog/2008/02/29/how-to-sync-tables-in-master-master-mysql-replication/' rel='bookmark' title='Permanent Link: How to sync tables in master-master MySQL replication'>How to sync tables in master-master MySQL replication</a></li>
<li><a href='http://www.xaprb.com/blog/2007/05/12/how-fast-is-mysql-table-checksum/' rel='bookmark' title='Permanent Link: How fast is MySQL Table Checksum?'>How fast is MySQL Table Checksum?</a></li>
<li><a href='http://www.xaprb.com/blog/2008/03/09/a-very-fast-fnv-hash-function-for-mysql/' rel='bookmark' title='Permanent Link: A very fast FNV hash function for MySQL'>A very fast FNV hash function for MySQL</a></li>
<li><a href='http://www.xaprb.com/blog/2008/01/13/how-pre-fetching-relay-logs-speeds-up-mysql-replication-slaves/' rel='bookmark' title='Permanent Link: How pre-fetching relay logs speeds up MySQL replication slaves'>How pre-fetching relay logs speeds up MySQL replication slaves</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>Very fast, as it turns out.</p>

<p>While writing the chapter on replication for the upcoming second edition of High Performance MySQL, I decided to do a little test and measure replication speed more accurately than I&#8217;ve seen others do before.  The first edition of the book measured replication speed by inserting on the master and polling on the slave.  <a href="http://datacharmer.blogspot.com/2006/04/measuring-replication-speed.html">Giuseppe Maxia later followed up on that by improving the polling process</a>, and found events typically replicated within a half a millisecond.</p>

<p>Polling can only get you so far; the extra overhead caused by polling skews the measurements (even if you <a href="http://www.xaprb.com/blog/2006/05/04/how-to-make-a-program-choose-an-optimal-polling-interval/">poll smartly</a>).  I wanted to see if I could do this without polling the slave for results.  It turned out to be easier than I thought it would be.</p>

<p>All I had to do was write a <a href="http://dev.mysql.com/doc/en/adding-functions.html">MySQL User-Defined Function</a> that returns the system time to microsecond precision.  I&#8217;ll write another post about that later; in this post I want to talk about the results.</p>

<h3>The setup</h3>

<p>After writing and installing the function, I tested it.  Note that it&#8217;s non-deterministic, so you get different results even when you call it twice in the same query:</p>

<pre>SELECT NOW_USEC(), NOW_USEC(); 
+----------------------------+----------------------------+ 
| NOW_USEC()                 | NOW_USEC()                 | 
+----------------------------+----------------------------+ 
| 2007-10-23 10:41:10.743917 | 2007-10-23 10:41:10.743934 | 
+----------------------------+----------------------------+ </pre>

<p>The rest is easy.  I set up two MySQL instances on the same server (because there&#8217;s no way the clocks on two separate machines will be synced to the microsecond), and made one of them the master of the other.  On the master,</p>

<pre>CREATE TABLE test.lag_test( 
   id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
   now_usec VARCHAR(26) NOT NULL 
 ); 

INSERT INTO test.lag_test(now_usec) VALUES( NOW_USEC() ); </pre>

<h3>The results</h3>

<p>Now all that remains is to compare the difference from the slave and the master.  A Federated table is an easy way to do this.  On the slave:</p>

<pre>CREATE TABLE test.master_val ( 
   id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
   now_usec VARCHAR(26) NOT NULL 
) ENGINE=FEDERATED 
   CONNECTION='mysql://user:pass@127.0.0.1/test/lag_test'; </pre>

<p>A simple join and the TIMESTAMPDIFF function can now show the microseconds of lag between the time the query executed on the master and the slave:</p>

<pre>SELECT m.id, TIMESTAMPDIFF(FRAC_SECOND, m.now_usec, s.now_usec) AS usec_lag
FROM test.lag_test as s
   INNER JOIN test.master_val AS m USING(id); 
+----+----------+ 
| id | usec_lag | 
+----+----------+ 
|  1 |      476 | 
+----+----------+ </pre>

<p>I inserted a thousand rows into the master with a simple Perl script, with a 10-millisecond delay between rows to keep help the master and slave instances from fighting each other for CPU time. I then built a temporary table with the lag of each event, and grouped the results by lag time, to see what the most frequent lag times are:</p>

<pre>SELECT ROUND(lag / 1000000.0, 4) * 1000 AS msec_lag, COUNT(*)
FROM lag
GROUP BY msec_lag
ORDER BY msec_lag;
+----------+----------+ 
| msec_lag | COUNT(*) | 
+----------+----------+ 
|   0.1000 |      392 | 
|   0.2000 |      468 | 
|   0.3000 |       75 | 
|   0.4000 |       32 | 
|   0.5000 |       15 | 
|   0.6000 |        9 | 
|   0.7000 |        2 | 
|   1.3000 |        2 | 
|   1.4000 |        1 | 
|   1.8000 |        1 | 
|   4.6000 |        1 | 
|   6.6000 |        1 | 
|  24.3000 |        1 | 
+----------+----------+</pre>

<p>Not all that bad, eh?  It looks to me like MySQL can replicate most small queries in <em>200 to 300 microseconds</em>(!!!).  Of course, the speed is bounded by a) how long it takes to transfer the binary log event across the network and b) how fast the query executes.  In this case, both are very fast, showing that MySQL doesn&#8217;t add much overhead of its own to the replication process.</p>

<p>If anyone knows of a way to measure the delay between the event being logged in the master&#8217;s binary log, and the event being logged in the slave&#8217;s relay log, I&#8217;d be interested in seeing the results.  I&#8217;m guessing it&#8217;s practically instantaneous for small events like this, and most of the lag is in reading, parsing, and executing the SQL.</p>

<p><strong>Further Reading:</strong><ul><li><a href='http://www.xaprb.com/blog/2007/11/08/how-mysql-replication-got-out-of-sync/' rel='bookmark' title='Permanent Link: How MySQL replication got out of sync'>How MySQL replication got out of sync</a></li>
<li><a href='http://www.xaprb.com/blog/2008/02/29/how-to-sync-tables-in-master-master-mysql-replication/' rel='bookmark' title='Permanent Link: How to sync tables in master-master MySQL replication'>How to sync tables in master-master MySQL replication</a></li>
<li><a href='http://www.xaprb.com/blog/2007/05/12/how-fast-is-mysql-table-checksum/' rel='bookmark' title='Permanent Link: How fast is MySQL Table Checksum?'>How fast is MySQL Table Checksum?</a></li>
<li><a href='http://www.xaprb.com/blog/2008/03/09/a-very-fast-fnv-hash-function-for-mysql/' rel='bookmark' title='Permanent Link: A very fast FNV hash function for MySQL'>A very fast FNV hash function for MySQL</a></li>
<li><a href='http://www.xaprb.com/blog/2008/01/13/how-pre-fetching-relay-logs-speeds-up-mysql-replication-slaves/' rel='bookmark' title='Permanent Link: How pre-fetching relay logs speeds up MySQL replication slaves'>How pre-fetching relay logs speeds up MySQL replication slaves</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.xaprb.com/blog/2007/10/23/how-fast-is-mysql-replication/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

