<?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"
	>

<channel>
	<title>Alex Tomic's tech blog</title>
	<atom:link href="http://tomictech.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tomictech.com</link>
	<description></description>
	<pubDate>Wed, 02 Jul 2008 17:11:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>mysql proxy 0.6.1 performance tests</title>
		<link>http://tomictech.com/2008/07/02/mysql-proxy-061-performance-tests/</link>
		<comments>http://tomictech.com/2008/07/02/mysql-proxy-061-performance-tests/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 17:11:13 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[mysql-proxy]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[sysbench]]></category>

		<guid isPermaLink="false">http://tomictech.com/?p=14</guid>
		<description><![CDATA[The mysql proxy project has tremendous potential to make mysql administration and usage easier. I decided to throw some load at it to get a feel for how stable and performant it is. On EC2, I set up 6 &#8220;small&#8221; images in an example proxy setup:- One client machine to run sysbench- One machine to [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://forge.mysql.com/wiki/MySQL_Proxy">mysql proxy project</a> has tremendous potential to make mysql administration and usage easier. I decided to throw some load at it to get a feel for how stable and performant it is. <br id="tw_32" /><br id="f6su" />On EC2, I set up 6 &#8220;small&#8221; images in an example proxy setup:<br id="lf25" /><br id="lf250" />- One client machine to run sysbench<br id="lf251" />- One machine to act as a mysql proxy machine, running 0.6.1 (FC4 binary)<br id="lf252" />- Four identical database servers, running mysql 5.0.45<br id="z.di" /><br id="z.di0" />The database configuration was largely default, with InnoDB configured for 64MB buffer pool (just enough to ensure the sysbench table was entirely in memory), 512MB log files, and 1024 max connections.<br id="z.di1" /><br id="z.di2" />mysql-proxy was run with the following command:<br id="z.di3" /><br id="z.di4" />mysql-proxy &#8211;proxy-backend-addresses=ip-10-251-66-63.ec2.internal:3306 &#8211;proxy-backend-addresses=ip-10-251-71-21.ec2.internal:3306 &#8211;proxy-backend-addresses=ip-10-251-43-70.ec2.internal:3306 &#8211;proxy-backend-addresses=ip-10-251-75-52.ec2.internal:3306<br id="z.di5" /><br id="z.di6" />Using the sysbench database benchmark utility to generate some heavy load on the boxes individually (to verify they were all more or less equal), and on the proxy itself, I got some interesting results:<br id="kjc84" /></p>
<p><span style="text-decoration: underline;">Read/write operations/second:</span><br />
<br id="a6q-" /><img src="http://spreadsheets.google.com/pub?key=pP8KmhvZIzEceeZoKrtmxYw&amp;oid=1&amp;output=image" alt="" /><br id="a6q-0" /><br id="xyrj0" /><span style="text-decoration: underline;">Transactions/second:</span></p>
<p><img src="http://spreadsheets.google.com/pub?key=pP8KmhvZIzEceeZoKrtmxYw&amp;oid=2&amp;output=image" alt="" /><br />
<br id="a6q-1" /></p>
<p>Somewhat as I expected, mysql-proxy presents a bit of overhead when load is light. With only 8 concurrent threads, running against the proxy pointing to 4 equal database servers is slower than hitting one server itself.<br id="eq68" /><br id="eq680" />As load goes up, however, you can see that the proxy scales reasonably well, while the accesses to the direct systems begin to tank rapidly after 64 concurrent threads (I lost some of my 128 thread results inadvertently and the instances are destroyed <img src='http://tomictech.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> I&#8217;m fairly comfortable in interoplating the result to be roughly in between 64 and 256 )<br id="p1qw" /><br id="p1qw0" />Somewhat unsettling, however, was the fact that sysbench or mysql proxy failed to work beyond about 500 concurrent threads. My debug output for sysbench just stops here:<br id="lrj3" /> <br id="lrj30" /> DEBUG: mysql_real_connect(0&#215;9adec70, &#8220;ip-10-251-75-160&#8243;, &#8220;sbtest&#8221;, &#8220;(null)&#8221;, &#8220;sbtest&#8221;, 4040, &#8220;(null)&#8221;, CLIENT_MULTI_STATEMENTS)<br id="lrj31" /> DEBUG: mysql_init(0&#215;9ae51b0)<br id="lrj32" /> DEBUG: mysql_options(0&#215;9ae51b0, MYSQL_READ_DEFAULT_<br id="lrj33" /></p>
<p>On the servers themselves, I can see the 125+ connections to each individual box, and all looks normal. I tried tweaking some of the thread settings in ulimit and sysbench itself to no avail, but didn&#8217;t have a ton of time to play with it. I decided the results were already interesting enough and will see if I can revisit this another time. <br id="u1ma" /> <br id="u1ma0" /> Another reason i am not so concerned is that more than one proxy can be utilised in many typical environments, so the ability of a single mysql-proxy instance to handle 512+ concurrent connections might not be show-stopper. <br id="ya:y" /> <br id="ya:y0" /> If anyone out there has done some similar tests with mysql proxy, i welcome your feedback!</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/07/02/mysql-proxy-061-performance-tests/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A lesson in never letting your filesystem fill up too much</title>
		<link>http://tomictech.com/2008/06/26/a-lesson-in-never-letting-your-filesystem-fill-up-too-much/</link>
		<comments>http://tomictech.com/2008/06/26/a-lesson-in-never-letting-your-filesystem-fill-up-too-much/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 16:01:04 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[archive]]></category>

		<guid isPermaLink="false">http://tomictech.com/?p=13</guid>
		<description><![CDATA[A good rule of thumb is that a DBA should not let the size of his/her database grow to much more than 50% of the available disk space. I&#8217;m sure everyone has a story of being burned in some way by not following this advice.
Before promoting 5.1 to some beefier hardware, I&#8217;ve got a few [...]]]></description>
			<content:encoded><![CDATA[<p>A good rule of thumb is that a DBA should not let the size of his/her database grow to much more than 50% of the available disk space. I&#8217;m sure everyone has a story of being burned in some way by not following this advice.</p>
<p>Before promoting 5.1 to some beefier hardware, I&#8217;ve got a few large tables sitting on a small SATA-based machine. Noticing that a few were growing faster than I expected, i decided to pause my loading and convert another one of them to the archive storage engine to save some space.</p>
<p>I certainly saved space.</p>
<p>By trying to do too much at one time, I had some other temp files lying around on the same filesystem, and my conversion to the archive storage engine failed at about 80% through with my disk full.</p>
<p>mysql&gt; alter table w_stats engine = Archive;<br />
ERROR 1030 (HY000): Got error -1 from storage engine</p>
<p>mysql 5.1 has <a href="http://bugs.mysql.com/bug.php?id=37648">an unfortunate bug</a> that I discovered, and reported, that causes the unfinished archive files to remain after the failed conversion, and not the original data. My disk space problems are no longer much of a problem <img src='http://tomictech.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now I know that this was basically my fault, and that I should have been more careful with my system, but I would have preferred maybe an embarassing error message, a slap on the wrist, not the loss of a 150GB table! For example:</p>
<p>mysql&gt; alter table w_stats engine = Archive;<br />
ERROR 1030 (HY000):  df -h is your friend</p>
<p>Well, it sounded funny in my head at least&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/06/26/a-lesson-in-never-letting-your-filesystem-fill-up-too-much/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Testing MySQL sequential IO performance with different IO schedulers - Part 1</title>
		<link>http://tomictech.com/2008/06/23/testing-mysql-sequential-io-performance-with-different-io-schedulers-part-1/</link>
		<comments>http://tomictech.com/2008/06/23/testing-mysql-sequential-io-performance-with-different-io-schedulers-part-1/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 19:52:06 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://tomictech.com/?p=12</guid>
		<description><![CDATA[Testing MySQL sequential IO performance with different IO schedulers - Part 1I stumbled upon an interesting article discussing the different Linux I/O schedulers that are available in the 2.6 kernel, and also discussing some of the deficiencies of the 2.4 &#8220;Linus elevator&#8221; I/O scheduler. The default scheduler as of Kernel 2.6.18 is the &#8220;Completely fair [...]]]></description>
			<content:encoded><![CDATA[<p>Testing MySQL sequential IO performance with different IO schedulers - Part 1<br id="ov.f" /><br id="ov.f0" />I stumbled upon an <a href="http://kerneltrap.org/node/7637">interesting article</a> discussing the different Linux I/O schedulers that are available in the 2.6 kernel, and also discussing some of the deficiencies of the 2.4 &#8220;Linus elevator&#8221; I/O scheduler. <br id="df9g" /><br id="gn2o" />The default scheduler as of Kernel 2.6.18 is the &#8220;Completely fair queuing&#8221; scheduler, or CFQ. The previous default was the anticipatory scheduler between 2.6.0 and 2.6.17. Also available is a buffed-up version of the 2.4 scheduler called the deadline scheduler, and a &#8220;noop&#8221; scheduler. <a href="http://www.fishpool.org/post/2008/03/31/Optimizing-Linux-I/O-on-hardware-RAID">This article</a> has a great discussion on what these schedulers mean for databases at a higher level. <br id="gn2o0" /><br id="ckz5" />Although old, <a href="http://www.linuxhq.com/kernel/v2.6/8/Documentation/as-iosched.txt">some documentation in the kernel</a> states  that database workloads should typically use the deadline scheduler. <a href="http://www.puschitz.com/TuningLinuxForOracle.shtml#KernelBootParameters">This tuning guide for Oracle on Linux</a> gives, without much explanation, the same advice . <br id="oi6j" /> <br id="df9g0" />I don&#8217;t have the time at the moment to do a full analysis (hence part 1), but I did some quick tests and already got some pretty surprising results. I&#8217;m hoping to see if anyone else has done some tests along these lines that can comment further.<br id="w1ve" /><br id="xlvy" />The test<br id="xlvy0" /><br id="w1ve0" />I have a 140GB table sitting on a test machine with a simple 320GB SATA drive.<br id="t9z6" /><br id="t9z60" />Changing the scheduler in newer kernels is a simple tunable parameter. You can change it to the deadline scheduler for your sda device, for example, as follows:<br id="t9z61" /><br id="t9z62" />echo deadline &gt; /sys/block/sda/queue/scheduler<br id="t9z63" /><br id="t9z64" />I ran a simple count(*) on one of the partitions, 13GB in size, to see if there was a measurable difference between the schedulers. Memory size on this system is 4GB.<br id="ndza" /><br id="ndza0" />These are the results I got on an otherwise idle machine. The CFQ and anticipatory results were very consistent, almost to the second each time, while the deadline and no-op schedulers fluctuated as much as 50s per test. Not sure at this point why this is the case.<br id="udh5" /><br id="udh50" /></p>
<div id="auaz">
<table id="h1di" border="1" cellspacing="0" cellpadding="3" width="100%" bordercolor="#999999">
<tbody id="auaz0">
<tr id="auaz1">
<td id="auaz2" width="33%">Scheduler<br id="auaz3" /></td>
<td id="auaz4" width="33%">Average runtime (s)<br id="auaz5" /></td>
<td id="auaz6" width="33%">Average Throughput (MiB/s)<br id="auaz7" /></td>
</tr>
<tr id="auaz8">
<td id="auaz9" width="33%">CFQ<br id="auaz10" /></td>
<td id="auaz11" width="33%">303<br id="auaz12" /></td>
<td id="auaz13" width="33%">43.04<br id="auaz14" /></td>
</tr>
<tr id="auaz15">
<td id="auaz16" width="33%">Anticipatory<br id="auaz17" /></td>
<td id="auaz18" width="33%">370<br id="auaz19" /></td>
<td id="auaz20" width="33%">35.4<br id="auaz21" /></td>
</tr>
<tr id="auaz22">
<td id="auaz23" width="33%">Deadline<br id="auaz24" /></td>
<td id="auaz25" width="33%">492<br id="auaz26" /></td>
<td id="auaz27" width="33%">26.5<br id="auaz28" /></td>
</tr>
<tr id="auaz29">
<td id="auaz30" width="33%">No-op<br id="auaz31" /></td>
<td id="auaz32" width="33%">471<br id="auaz33" /></td>
<td id="auaz34" width="33%">27.6<br id="auaz35" /></td>
</tr>
</tbody>
</table>
</div>
<p><br id="lued" /><br id="o_u3" /> Now, these results come with the following caveats:<br id="lued0" /><br id="lued1" />- These are not extensive, robust benchmarks, they&#8217;re just a few tests I ran against my very specific workload. I encourage people to try the different schedulers on different workloads and hardware and share results!<br id="lued2" />- These are test results with a large, sequential I/O workload that is very different from the random I/O intensive tests that most people are interested in. <br id="utbj" /> - These are test results against a single ATA drive. These results are probably irrelevant in a hardware RAID context<br id="uhuq" /> <br id="uhuq0" /> In a future blog post, I will try to dig a bit deeper into these results and try the tests against hardware and software RAID. What i think can be taken from this already, and the referenced articles, is that CFQ should probably be used if your kernel has direct knowledge of the physical layout of your disks, eg. through LVM. Otherwise, deadline or even noop is probably your best bet if you are using hardware RAID, putting the burden on the hardware to decide how best to execute reads and writes.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/06/23/testing-mysql-sequential-io-performance-with-different-io-schedulers-part-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Building a data warehouse on a budget with MySQL 5.1</title>
		<link>http://tomictech.com/2008/06/16/building-a-data-warehouse-on-a-budget-with-mysql-51/</link>
		<comments>http://tomictech.com/2008/06/16/building-a-data-warehouse-on-a-budget-with-mysql-51/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 02:59:13 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[data warehouse]]></category>

		<category><![CDATA[datawarehouse]]></category>

		<guid isPermaLink="false">http://tomictech.com/?p=11</guid>
		<description><![CDATA[If there is one thing that a DBA or data warehouse architect can count on, it is that data volumes will increase while budgets will decrease.This is why MySQL 5.1 and its partitioning capabilities are so interesting. I&#8217;m going to demonstrate how you can build a small/medium-sized data warehouse or data mart (1-10 TB range) [...]]]></description>
			<content:encoded><![CDATA[<p>If there is one thing that a DBA or data warehouse architect can count on, it is that data volumes will increase while budgets will decrease.<br id="zwv8" /><br id="zwv80" />This is why MySQL 5.1 and its partitioning capabilities are so interesting. I&#8217;m going to demonstrate how you can build a small/medium-sized data warehouse or data mart (1-10 TB range) on a shoe-string budget.</p>
<h3>the mission</h3>
<p>I decided to convert a relatively large statistics table (750m rows, 140GB in size in about 10 partitions) on a test machine from MyISAM to the Archive storage engine. After a long conversion process, my data, on disk, ended up being about 21GB, for an impressive compression ratio of 6.7:1.<br id="c1y6" /><br id="c1y60" />Prior to MySQL 5.1, one of the drawbacks to the archive storage engine was that you could not index it; however, with partition pruning, you can get yourself a &#8220;free&#8221; index on a large archive table by splitting it into date-based chunks, whether by day, week, month or year, depending on the volume of data you want to make accessible.<br id="k5ha" /><br id="k5ha0" />I decided to see how long it would take to run a simple aggregate query against a portion of one of the partitions I had created.<br id="mveb0" /><span style="font-family: Courier New;"><br id="o8.1" />mysql&gt; explain partitions select count(*) from stats where StatsTime between &#8216;2007-05-01&#8242; and &#8216;2007-05-31&#8242;;</span><br id="tfq:" style="font-family: Courier New;" /> <span style="font-family: Courier New;">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+</span><br id="tfq:0" style="font-family: Courier New;" /> <span style="font-family: Courier New;">| id | select_type | table        | partitions | type | possible_keys | key  | key_len | ref  | rows     | Extra       |</span><br id="tfq:1" style="font-family: Courier New;" /> <span style="font-family: Courier New;">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+</span><br id="tfq:2" style="font-family: Courier New;" /> <span style="font-family: Courier New;">|  1 | SIMPLE      | stats        | p_2007q2   | ALL  | NULL          | NULL | NULL    | NULL | 59558354 | Using where | </span><br id="tfq:3" style="font-family: Courier New;" /> <span style="font-family: Courier New;">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+</span><br id="tfq:4" style="font-family: Courier New;" /> <span style="font-family: Courier New;">1 row in set (0.00 sec)</span><br id="tfq:5" /> <br id="y3_0" />On disk, the partition was about 1.7G:<br id="y3_00" /><br id="i6tf0" /> -rw-rw&#8212;- 1 mysql mysql 1.7G Jun 16 17:16 stats#P#p_2007q2.ARZ<br id="y3_01" /><br id="tfq:6" />After issuing the query, I watched iostat. The file being accessed was completely absent from filesystem cache because i had previous run a long query against a large MyISAM table. This is what I saw, fairly consistently:<br id="jgk2" /> <br id="jgk20" /><span style="font-family: Courier New;">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span><br id="tt4k0" style="font-family: Courier New;" /> <span style="font-family: Courier New;"> 24.96    0.00    0.75    0.88    0.00   73.42</span><br id="tt4k1" style="font-family: Courier New;" /> <br id="tt4k2" style="font-family: Courier New;" /> <span style="font-family: Courier New;">Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util</span><br id="tt4k3" style="font-family: Courier New;" /> <span style="font-family: Courier New;">sda              48.55     0.40 62.44  0.60     7.36     0.00   239.32     0.39    6.20   5.42  34.20</span><br id="tt4k4" style="font-family: Courier New;" /> <br id="wfq4" /><br id="lst7" />As expected with a highly-compressed table, the query speed is CPU-limited: the disk can go much faster but we are fully utilizing one of the four cores (notice 25% cpu utilization).<br id="ht7e" /><br id="ht7e0" />Back-of-the-envelope calculations suggest that, at 7.3mb/s read throughput from disk, and a 1.7G file to be read, that the query will complete in about: <br id="clrg" /><br id="clrg0" />1700mb / 7.3mb/s = 232s = 3m52s<br id="o40y" /><br id="o40y0" /><span style="font-family: Courier New;">mysql&gt; select count(*) from stats where StatsTime between &#8216;2007-05-01&#8242; and &#8216;2007-05-31&#8242;;</span><br id="b:9:1" style="font-family: Courier New;" /> <span style="font-family: Courier New;">+&#8212;&#8212;&#8212;-+</span><br id="b:9:2" style="font-family: Courier New;" /> <span style="font-family: Courier New;">| count(*) |</span><br id="b:9:3" style="font-family: Courier New;" /> <span style="font-family: Courier New;">+&#8212;&#8212;&#8212;-+</span><br id="b:9:4" style="font-family: Courier New;" /> <span style="font-family: Courier New;">|        0 | </span><br id="b:9:5" style="font-family: Courier New;" /> <span style="font-family: Courier New;">+&#8212;&#8212;&#8212;-+</span><br id="b:9:6" style="font-family: Courier New;" /> <span style="font-family: Courier New;">1 row in set (3 min 52.19 sec)</span><br id="b:9:7" /> <br id="f_pj" />Dead on!</p>
<h3>the possibilities</h3>
<p>What is interesting is that from this we can deduce the effective throughput of an archive table based on how much data the disk is feeding the cpu.</p>
<p>If we attempted to run such a query on the original MyISAM partition (about 11.5GB), in order to complete the result in 232s, we would require a throughput of :<br id="g:811" /><br id="g:812" />11500 / 232 = 49mb/s<br id="btud" /><br id="btud0" />50mb/s is not lightning fast, it&#8217;s about what you&#8217;d expect from a single SATA disk, but it&#8217;s still fairly good considering the amount of compression we&#8217;re getting.<br id="o.-q" /><br id="o.-q0" />But wait! You still have 3 more cores left on the machine. Now to confirm another hypothesis:<br id="x9js" /><br id="x9js0" />Testing two simultaneous queries, against the same partition:<br id="j3i60" /> <br id="j3i61" /> <span style="font-family: Courier New;">select count(*) from stats where </span><span style="font-family: Courier New;">StatsTime </span><span style="font-family: Courier New;">between &#8216;2007-05-01&#8242; and &#8216;2007-05-29&#8242;;</span><br id="v9x-" style="font-family: Courier New;" /><span style="font-family: Courier New;"> select count(*) from stats where </span><span style="font-family: Courier New;">StatsTime </span><span style="font-family: Courier New;">between &#8216;2007-05-01&#8242; and &#8216;2007-05-30&#8242;;</span><br id="ti:t" style="font-family: Courier New;" /><br id="b-lz" />Most of the data was in fs cache, so our iostat looked like this for most of the time:<br id="lf6c" /><br id="f_pj0" style="font-family: Courier New;" /><span style="font-family: Courier New;">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span><br id="f_pj1" style="font-family: Courier New;" /><span style="font-family: Courier New;"> 50.70    0.00    0.85    0.00    0.00   48.45</span><br id="f_pj2" style="font-family: Courier New;" /><br id="f_pj3" style="font-family: Courier New;" /><span style="font-family: Courier New;">Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util</span><br id="f_pj4" style="font-family: Courier New;" /><span style="font-family: Courier New;">sda               0.00     0.50  0.00  0.80     0.00     0.01    13.00     0.00    0.38   0.37   0.03</span><br id="f_pj5" style="font-family: Courier New;" /><span style="font-family: Courier New;">hda               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00</span><br id="f_pj6" /><br id="j3i6" />Final runtime for both queries was 208s and 217s; suggesting that the queries were almost perfectly parallelized.<br id="t5ms" /><br id="t5ms0" />If we needed to run a beefy calculation against a year&#8217;s worth of data, for example, we could run four parallel queries (one per core per quarter) and aggregate the results for each query in a separate client. Now our &#8220;equivalent&#8221; 50mb/s throughput on one core has become 50mb/s * 4 = 200mb/s. <br id="ieou" /><br id="ieou0" />If you get a slightly faster disk, you could fully utilize an 8-core box for a throughput of 400mb/s. <br id="ltyv" /><br id="ltyv0" />And if your disk space is 750GB, factoring in the compression ratio, you are storing the equivalent of 5TB of non-compressed data with a potential read throughput of 200mb/s. Not too shabby for low-end hardware!<br id="x.i:" /><br id="jgk29" /></p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/06/16/building-a-data-warehouse-on-a-budget-with-mysql-51/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MySQL Repair/Optimize Partition Errors</title>
		<link>http://tomictech.com/2008/06/05/mysql-repair-optimize-partition-errors/</link>
		<comments>http://tomictech.com/2008/06/05/mysql-repair-optimize-partition-errors/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 06:24:52 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[partitioning]]></category>

		<guid isPermaLink="false">http://tomictech.com/blog/?p=10</guid>
		<description><![CDATA[mysql 5.1 is nearing release, with the present release candidate 5.1.24.
The most important new feature, in my eyes, is the new partitioning capability. When I get some time, I will write up a more complete post on my experiences so far with 5.1 partitioning, but I am going to try to keep the turnover on [...]]]></description>
			<content:encoded><![CDATA[<p>mysql 5.1 is nearing release, with the present release candidate 5.1.24.</p>
<p>The most important new feature, in my eyes, is the new partitioning capability. When I get some time, I will write up a more complete post on my experiences so far with 5.1 partitioning, but I am going to try to keep the turnover on posts a bit higher, and post smaller things on here more regularly.</p>
<p>Partitioning has the potential to make large tables in mysql manageable once again. This is music to the ears of anyone that has had the misfortune of having to learn, the hard way, about MyISAM&#8217;s often <a href="http://peter-zaitsev.livejournal.com/11772.html">painfully slow</a> &#8220;Repair by keycache&#8221; loading and repairing of large tables with unique keys. Add that to MyISAM&#8217;s propensity to table corruption, especially with large tables, and you have a ticking timebomb on many pre-5.1 servers out there. If you are lucky, you can repair a 10GB table in a few hours, something you don&#8217;t want to have to wait around for at 3am which is invariably when those big tables get screwed up and you have to repair them.</p>
<p>Of course, many people use application-level partitioning to deal with this problem, or used the inadequate MERGE storage engine to deal with this. But partitioning at the database level has the potential to make things just so much easier. If you partition wisely, you can turn a 10GB behemoth table into a series of 500mb chunks, each of which is (I&#8217;m hoping here) less likely to corrupt, and far more manageable by MySQL individually.</p>
<p>Beware of <a href="http://bugs.mysql.com/bug.php?id=20129">this bug</a> though! It&#8217;s duplicated many times, and might catch you off guard if you plan to be an early adopter of 5.1.  Essentially, you can&#8217;t really repair or optimize partitioned tables, at least not directly. The documentation <a href="http://dev.mysql.com/doc/refman/5.1/en/alter-table.html">still contains references</a> to the ALTER TABLE &#8230; REPAIR PARTITION statements which don&#8217;t work at all, as of 5.1.24. For eg, with my partitioned InnoDB table tst_p:</p>
<pre>mysql&gt; optimize table tst_p;
+-------------+----------+----------+-----------------------------------------------------------+
| Table       | Op       | Msg_type | Msg_text                                                  |
+-------------+----------+----------+-----------------------------------------------------------+
| stats.tst_p | optimize | note     | The storage engine for the table doesn't support optimize |
+-------------+----------+----------+-----------------------------------------------------------+
1 row in set (0.00 sec)
mysql&gt; alter table tst_p repair partition p_pre2007;
ERROR 1178 (42000): The storage engine for the table doesn't support repair partition</pre>
<p>Luckily, there is a workaround. Using ALTER TABLE REORGANIZE PARTITION, you can effectively rebuild the partition which will optimize/repair it. I&#8217;ve yet to test this with a truly corrupted table, however. The downside of this is that you have to have the partition definition handy. Luckily it seems to be smart enough to stop you from making a mess &#8212; notice the error in the first one, and the second statement goes through correctly:</p>
<pre>mysql&gt; alter table tst_p reorganize partition p_pre2007 into (partition p_pre2007 values less than (to_days('2007-12-31')));
ERROR 1520 (HY000): Reorganize of range partitions cannot change total ranges except for last partition where it can extend the range
mysql&gt;
mysql&gt; alter table tst_p reorganize partition p_pre2007 into (partition p_pre2007 values less than (to_days('2007-01-01')));
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0</pre>
<p>As I get more time i&#8217;ll post more cool partitioning tricks.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/06/05/mysql-repair-optimize-partition-errors/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sun caught in a pincer with MySQL</title>
		<link>http://tomictech.com/2008/06/02/sun-caught-in-a-pincer-with-mysql/</link>
		<comments>http://tomictech.com/2008/06/02/sun-caught-in-a-pincer-with-mysql/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 07:20:44 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[bigtable]]></category>

		<category><![CDATA[hbase]]></category>

		<category><![CDATA[postgresql]]></category>

		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://tomictech.com/blog/?p=9</guid>
		<description><![CDATA[Over the years, the database world has been buzzing with the strategic threat posed to the established players by upstart open-source database systems. Oracle and IBM would no longer be able to gouge defenseless small and medium-sized businesses of non-trivial portions of their IT budgets for a mere database licence. Oracle, IBM and Microsoft, for [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, the database world has been buzzing with the strategic threat posed to the established players by upstart open-source database systems. Oracle and IBM would no longer be able to gouge defenseless small and medium-sized businesses of non-trivial portions of their IT budgets for a mere database licence. Oracle, IBM and Microsoft, for their part, have tried their best to respond to this threat, but it is clear that they cannot simply squash open-source products, but rather evolve with the changing landscape.</p>
<h3>the countered threat from Oracle</h3>
<p>Oracle made some strategic purchases in the past few years to establish a foothold in the embedded and front-end database market by acquiring Sleepycat (maintainers of BerkeleyDB) and InnoBase (makers of InnoDB storage engine for MySQL). These two also happened to provide the only two transactional backends for MySQL, whlie InnoDB is the only one to be used widely in practice. While this was looked upon as a disaster for MySQL, it was really not a major issue for a couple of reasons:</p>
<ul>
<li>The InnoDB source has been GPL&#8217;d, so even if Innobase were to completely abandon maintenance of the codebase (which it has not), the community can step in to fix bugs. For now, the status quo prevails</li>
<li>MySQL acquired Netfrastructure (sp?) and begun the process of porting the backend to the new Falcon transactional storage engine</li>
<li>MySQL also began the process of fixing up some of the severe defecits in the MyISAM storage engine and branded it <a href="http://dev.mysql.com/downloads/maria/index.html">Maria</a></li>
</ul>
<p>So, from a strategic perspective, it looks like MySQL is taking the right steps to counter the threat from Oracle. An infusion of money from Sun will speed up development on many of these initiatives.</p>
<h3>a general picture of the database landscape</h3>
<p>Let&#8217;s take a step back for the moment and take an unscientific look at a few players in the current database market. This is not rigorous, exhaustive market research, it&#8217;s just my observations over the past 9-10 years or so:</p>
<p>Teradata: The data-warehousing champ, a reputation for high quality but also prohibitively expensive for many with large data volumes</p>
<p>DB2: Strong in the institutional market, mainframes and data warehousing; not much use in the web/internet world</p>
<p>Oracle: The jack of all trades. Expensive, but no CTO would ever be fired for picking Oracle for almost any purpose, whether its an OLTP system or data warehouse</p>
<p>PostgreSQL: The Betacam of open source databases. Highly-functional, stable and scalable. Over the years, unfortunately saddled with a somewhat-unjustified reputation for being slow and difficult to use (in comparison to MySQL) and a militant userbase that spends an inordinate amount of time bashing MySQL instead of evangelising its capabilities</p>
<p>MySQL: A simple, fast database with a reduced featureset that works well for web applications</p>
<p>My belief is that MySQL owes its popularity mostly due to the fact it is perceived to be very fast when using it to build simple apps. Over the years it became the &#8216;default&#8217; web database, with most hosting providers using it as the backend in combination with PHP. Many are now providing PostgreSQL hosting, but this wasn&#8217;t always the case.</p>
<h3>mysql vs. postgresql</h3>
<p>While they are both OSS databases, MySQL and PostgreSQL are very different. <a href="http://www.postgresql.org/docs/7.4/static/history.html">PostgreSQL has its roots in academa and the defense industry</a>, and a trip into the source code is like a trip down <a href="http://www.google.com/codesearch?hl=en&amp;q=show:BdE2aF3-8-4:_2IWH1yq2KM:Sya6mTOdewo&amp;sa=N&amp;ct=rd&amp;cs_p=http://ftp.osuosl.org/pub/nslu2/sources/postgresql-8.1.4.tar.bz2&amp;cs_f=postgresql-8.1.4/src/backend/optimizer/geqo/geqo_main.c&amp;start=1">a memory from a computer science class</a>. <a href="http://www.antihoe.org/oreilly/weblinux/sql/ch01_04.htm">MySQL, on the other hand</a>, feels and has been developed much more like a commercial product, with a focus on functionality and speed and less interest in elegance and standards compliance. These are sweeping generalisations of course.</p>
<p>My reason for bringing up this comparison is to make the following important assertion:</p>
<p><em>For a particular project, given the choice, DBAs choose PostgreSQL, developers choose MySQL.</em></p>
<p>DBAs like tablespaces. Good query optimizers. Tables that don&#8217;t randomly corrupt.</p>
<p>Developers like databases that reduce their need to think. A system that will let you send 100 queries over 100 separate connections without any apparent overhead compared to sending 100 queries over the same connection.</p>
<p>I come to this conclusion after nearly 2.5 years as a MySQL &#8220;DBA&#8221; working for companies of various sizes in the internet industry. MySQL, in many cases, has been reduced to a glorified flat file system, and many non-junior developers do not even understand the most basic SQL optimization.</p>
<p>It&#8217;s not hard to see why MySQL is far more popular than PostgreSQL, given that developers are more numerous and higher up the application stack.</p>
<h3>Amazon SimpleDB and Google BigTable</h3>
<p>The users of MySQL may prove to be a fickle bunch, however. Oracle never was never that much of a threat all along, and two unlikely competitors in the database space will change the rules of the game.  Developers like the simplicity and avoiding-of-thinking they get with MySQL. Once a site gets to a certain scale, the database become a major bottleneck. Complex yet surprisingly-robust <a href="http://highscalability.com/unorthodox-approach-database-design-coming-shard">sharding architectures</a> have been developed to deal with scaling MySQL beyond the capacity of one machine, but this is not for the faint of heart.</p>
<p><a href="http://labs.google.com/papers/bigtable.html">BigTable </a>and <a href="http://www.amazon.com/SimpleDB-AWS-Service-Pricing/b?ie=UTF8&amp;node=342335011">SimpleDB </a>look ready to take developers back to the simpler days when MySQL was a fast, reliable persistent store, allowing them to focus on their strengths. <a href="http://wiki.apache.org/hadoop/Hbase">HBase</a>, while still very alpha-ish, also holds great promise. Many people have criticised BigTable and SimpleDB for being, well, just a big table and a simple database. But that&#8217;s precisely what MySQL was, and it did it quite well for a long time. Developers in the internet age simply don&#8217;t care about the things DBAs and database developers of a previous era did. They want three things: performance, availability and more performance. Strict ACID compliance is simply not that important in an age when entire internet empires are built off of clicks worth as little as $0.07 and page views worth $0.00001 &#8212; but high availability <em>is </em>important.</p>
<h3>the pincer</h3>
<p>Sun has acquired MySQL at a time when the old guard of the database world is becoming more aggressive, and the new guard of software-as-a-service providers are swooping into the space to appeal to IT managers initially happy with the open source licensing, but not thrilled with the non-trivial total cost of ownership (read: paying a DBA who must continually wake up at 230 to repair your corrupted MyISAM tables)</p>
<h3>prognosis</h3>
<p>Well, let&#8217;s put it this way &#8212; as someone that abandoned the proprietary database world a few years ago to work solely with open-source technologies, I feel that I need to start learning more about HBase, BigTable and the like to survive in this marketplace. MySQL may not have seen this strategic threat coming, but they better start working, quickly, to make MySQL scale better and more easily, or it will begin to lose its place as the &#8220;default&#8221; database of new web applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/06/02/sun-caught-in-a-pincer-with-mysql/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ALTER TABLE flakiness and mysql replication</title>
		<link>http://tomictech.com/2008/05/20/alter-table-flakiness-and-mysql-replication/</link>
		<comments>http://tomictech.com/2008/05/20/alter-table-flakiness-and-mysql-replication/#comments</comments>
		<pubDate>Wed, 21 May 2008 04:37:32 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[replication]]></category>

		<category><![CDATA[alter table]]></category>

		<category><![CDATA[memory corruption]]></category>

		<guid isPermaLink="false">http://tomictech.com/blog/?p=8</guid>
		<description><![CDATA[Over the past few years of dealing with mysql in larger environments, one thing I&#8217;ve always felt that ALTER TABLE statements are flaky with replication, but could never really prove it. I never had a chance to dig into some of strange things I saw, and would tend to overlook and fix them
While working for [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past few years of dealing with mysql in larger environments, one thing I&#8217;ve always <em>felt </em>that ALTER TABLE statements are flaky with replication, but could never really prove it. I never had a chance to dig into some of strange things I saw, and would tend to overlook and fix them</p>
<p>While working for a client, I encountered <a href="http://bugs.mysql.com/bug.php?id=36839">an issue</a> that I could no longer ignore. In order to reload a small table from a master database to a number of slaves, I simply piped the output of mysqldump into the master and expected everything to flow into the slaves.</p>
<p>The bug is very specific, and probably not very common. If you send a statement like below, as mysqldump automatically adds, to your master:</p>
<p>/*!40000 ALTER TABLE table_name DISABLE KEYS */;</p>
<p>and have configured something like</p>
<p>replicate-rewrite-db=mydb-&gt;mydb_slave</p>
<p>on your slave,  it will cause memory corruption on the slave.</p>
<p>You might see something like this in your mysql error logs:</p>
<p>*** glibc detected *** /opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug: double free or corruption (out): 0&#215;0a2eb1f0 ***<br />
======= Backtrace: =========<br />
/lib/libc.so.6[0x166f5d]<br />
/lib/libc.so.6(cfree+0&#215;90)[0x16a5b0]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug(my_no_flags_free+0&#215;64)[0x8481d8c]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug(free_root+0&#215;122)[0x848279a]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug(free_rows+0&#215;1c)[0x82e62d7]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug(unpack_fields+0&#215;3fb)[0x82e734b]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug[0x82e9a72]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug(mysql_real_query+0xdf)[0x82e9c82]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug[0x82d6f66]<br />
/opt/mysql-5.0.51a-linux-i686-glibc23/bin/mysqld-debug(handle_slave_io+0&#215;3c7)[0x82dd0cd]<br />
/lib/libpthread.so.0[0xcf82db]<br />
/lib/libc.so.6(clone+0&#215;5e)[0x1ce12e]<br />
This goes to show the risk involved in using &#8216;nifty&#8217; but perhaps not-so-often used features in a complex product like a database. If we&#8217;d just kept the same database names we&#8217;d have been fine. C&#8217;est la vie.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/05/20/alter-table-flakiness-and-mysql-replication/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A case for Kettle for your next ETL or data warehouse project</title>
		<link>http://tomictech.com/2008/05/10/a-case-for-kettle-for-your-next-etl-or-data-warehouse-project/</link>
		<comments>http://tomictech.com/2008/05/10/a-case-for-kettle-for-your-next-etl-or-data-warehouse-project/#comments</comments>
		<pubDate>Sat, 10 May 2008 19:44:25 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[kettle]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[ETL]]></category>

		<category><![CDATA[pentaho data integration]]></category>

		<guid isPermaLink="false">http://tomictech.com/blog/?p=6</guid>
		<description><![CDATA[I am, for the most part, a do-it-yourself type of person. I fix my own car if I can; I even have four healthy tomato plants growing in pots outside as we speak &#8212; the plants will take that little extra CO2 out of the air and give me great tasting tomatoes (soon&#8230; i hope!)
But [...]]]></description>
			<content:encoded><![CDATA[<p>I am, for the most part, a do-it-yourself type of person. I <a href="http://forums.tdiclub.com/showthread.php?t=140063">fix my own car</a> if I can; I even have four healthy tomato plants growing in pots outside as we speak &#8212; the plants will take that little extra CO2 out of the air and give me great tasting tomatoes (soon&#8230; i hope!)</p>
<p>But I digress.</p>
<p>Whether to use an ETL tool such as <a href="http://kettle.pentaho.org/">Kettle</a> (aka Penatho Data Integration) for a project involving large data transfers is a typical &#8220;build vs. buy&#8221; type of decision, one that is fairly well understood and I don&#8217;t wish to repeat it all here &#8212; putting together some Perl scripts to do the job, you typically get great performance, development speed and accessibility. This would need to be balanced against the benefits of ETL tools and their potential drawbacks  (development speed, license costs and performance implications).</p>
<p>A few things have happened in the last couple of years that make some of the typical reasons why you&#8217;d build your own no longer valid.</p>
<p><strong>cost</strong></p>
<p>Kettle is an open-source product, so not only is it priced right, you have access to the source code, which can be surprisingly handy. The 2.x series had some nasty bugs, and there were many times we dug into the source code to diagnose problems at my previous company. Don&#8217;t worry though, the 3.0 series from my experience is vastly improved.</p>
<p><strong>a new multi-core order</strong></p>
<p>Entry-level desktops today typically come with dual-core CPUs, and four or more cores on server hardware<br />
is now common. This trend will continue as chip makers shift towards adding <a href="http://en.wikipedia.org/wiki/Multi-core_(computing)">cores</a> to improve performance rather than simply increasing clock speed.</p>
<p>I&#8217;m willing to bet that your average Perl ETL script is not written in a multi-threaded fashion. Perhaps you can architect the process so that you can run several of them at once to take full advantage of the hardware, but this is essentially polluting your ETL logic with hardware dependencies.</p>
<p>With Kettle, leveraging all the cores on your ETL machine is almost free. Each transformation step instantiates a thread within the java virtual machine (JVM) which in turn will be run as a native thread. If you have more than a few steps in your transformation, and data is flowing through fairly evenly (no large bottlenecks), chances are that you are coming close to maximizing use of your hardware.</p>
<p>Surprisingly there are some still out there that have been underneath a rock since 1998 and think java is &#8220;slow&#8221;; all modern JVMs just-in-time compile your Java code natively and performance in <a href="http://kano.net/javabench/">some cases can be faster than C/C++</a>. It is definitely much faster than any interpreted language like Perl.</p>
<p>In my experience, I&#8217;ve noticed Kettle can be much faster at sorting and grouping large volumes of data than MySQL itself, at least out of the box, without turning too many knobs on the MySQL end. Good software should do that. I will post some tests of this assertion when I get a chance.</p>
<p><strong>visibility</strong></p>
<p>Kettle allows me to see, if I want to, exactly how much data each step has processed and get row counts/second to measure throughput and performance. Now that I&#8217;ve been spoiled, I can never go back to issuing a query like the below:</p>
<p>SELECT uid, count(*)<br />
FROM hundred_million_row_table GROUP BY uid;</p>
<p>The corresponding operation in Kettle:</p>
<p><a href="http://tomictech.com/wp-content/uploads/2008/05/spoon_sort_group_test1.png"><img class="alignnone size-medium wp-image-7" title="spoon_sort_group_test1" src="http://tomictech.com/blog/wp-content/uploads/2008/05/spoon_sort_group_test1-300x200.png" alt="Spoon UI in action" width="300" height="200" /></a></p>
<p>No more running iostat, top and hacking around to get a vague idea how long it might take MySQL (or whatever RDBMS) to run that beast of a query! Kettle gives you output at select intervals, so you can see how many rows the sort has processed (the most time consuming part of this process).</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/05/10/a-case-for-kettle-for-your-next-etl-or-data-warehouse-project/feed/</wfw:commentRss>
		</item>
		<item>
		<title>mysql I/O performance analysis with iostat</title>
		<link>http://tomictech.com/2008/04/02/mysql-io-performance-analysis-with-iostat/</link>
		<comments>http://tomictech.com/2008/04/02/mysql-io-performance-analysis-with-iostat/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 05:27:47 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[iostat]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[mysql performance iostat]]></category>

		<guid isPermaLink="false">http://tomictech.com/blog/?p=4</guid>
		<description><![CDATA[Here is a situation I&#8217;ve run into a few times when dealing with mysql databases. We&#8217;re trying to run a one-off query against a high-traffic, large table and the WHERE condition is against a non-indexed field. Let&#8217;s say our table is 5GB in size. We issue the following:
SELECT  count(*) from five_gb_myisam_table WHERE non_idx_field = [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a situation I&#8217;ve run into a few times when dealing with mysql databases. We&#8217;re trying to run a one-off query against a high-traffic, large table and the WHERE condition is against a non-indexed field. Let&#8217;s say our table is 5GB in size. We issue the following:</p>
<p><code>SELECT  count(*) from five_gb_myisam_table WHERE non_idx_field = 'asdf';</code></p>
<p>and we wait&#8230;</p>
<p>and wait some more.</p>
<p>5GB is not a small table, but this ideally should not take more than a few minutes on a relatively modern system.</p>
<h3>iostat is your friend</h3>
<p>In cases like this, <code>iostat -x 5</code> is your friend. While the query was running, this was a typical 5 second interval:<br />
<code><br />
avg-cpu:  %user   %nice    %sys %iowait   %idle<br />
2.30    0.00    1.30   96.40    0.00</code></p>
<p>Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util<br />
sda          0.00   0.70 <strong>172.50 </strong>1.20 3340.00   15.20  <strong>1670.00</strong> 7.60    <strong>19.32</strong> 1.02    5.90   5.60  <strong>97.22</strong></p>
<p>While the numbers fluctuated, the effective read throughput never went much over 1800 kb/s. The drive is certainly not the problem &#8212; a quick run of hdparm -T -t showed an average read throughput of nearly 50mb/s on this 7200RPM SATA drive.</p>
<p>The numbers for this 5 second period tell an interesting story.</p>
<p>The system sent an average 172.5 read requests/second to the drive, with each read fetching only 19.32 512-byte sectors (about 9.6kb),  giving you 9.6*172.5 = 1656kb/s.<br />
The average wait time (apart from queuing) was 5.6ms, so (172.5+1.20)*5.6 = 972ms of each second was spent waiting on some I/O.</p>
<p>Needless to say, the statistics suggest the single disk head is scrambling around fetching data from all different parts of the drive and returning the data back quite slowly overall.</p>
<h3>myisamchk statistics</h3>
<p>Taking the server down to do some deeper investigation, myisamchk -r -i reports a key statistic:</p>
<p><code>Blocks/Record    1.34</code></p>
<p>The table has about 6 million rows, so over 8 million records are stored with as many as 34% of the rows fragmented. This is a common problem for myisam tables containing variable-length fields that are frequently updated. Refer to <a href="http://dev.mysql.com/doc/refman/5.0/en/dynamic-format.html" target="_blank">this page</a> for details.</p>
<h3>the way it should be</h3>
<p>While I was running the stats above, i tried the same query on a different box with the same table and disk that i had recently restored. Running the same query takes nearly 1/20th of the time, and the iostat (with -m) shows:</p>
<p><code>avg-cpu:  %user   %nice %system %iowait  %steal   %idle<br />
0.50    5.30   25.40   27.00    0.00   41.80 </code><br />
<code><br />
Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util<br />
sda              47.50     0.00 378.64  0.00    <strong>40.62</strong> 0.00   219.69     1.68    4.30   2.01  76.01<br />
</code><br />
Now that&#8217;s more like it!</p>
<p>We manage nearly double the reads/s, and each read is pulling 219.69 segments = 109kb of data. Our effective throughput is over 20 times what it was before.</p>
<h3>the lesson</h3>
<p>While painful for large tables, this is an example of why frequent OPTIMIZE statements, especially against myisam tables, are a very good idea. Not only do they defragment your tables, improving performance on any queries involving table scans, they reduce the risk of table corruption by reducing the number of pointers between split records.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/04/02/mysql-io-performance-analysis-with-iostat/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Subtle mysqlhotcopy bug fix finally accepted!</title>
		<link>http://tomictech.com/2008/04/02/subtle-mysqlhotcopy-bug-fix-finally-accepted/</link>
		<comments>http://tomictech.com/2008/04/02/subtle-mysqlhotcopy-bug-fix-finally-accepted/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 03:57:22 +0000</pubDate>
		<dc:creator>atomic</dc:creator>
		
		<category><![CDATA[mysql]]></category>

		<category><![CDATA[mysqlhotcopy]]></category>

		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://tomictech.com/blog/?p=3</guid>
		<description><![CDATA[I&#8217;m happy to report that my patch for a potentially nasty bug in the mysqlhotcopy script has been accepted into the mysql codebase. It&#8217;s a great feeling to finally contribute something, however small, back to the mysql community.
If you have a master/slave environment with multiple slaves, and you do periodic backups of your system on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to report that <a title="my patch" href="http://bugs.mysql.com/bug.php?id=27101">my patch</a> for a potentially nasty bug in the mysqlhotcopy script has been accepted into the mysql codebase. It&#8217;s a great feeling to finally contribute something, however small, back to the mysql community.</p>
<p>If you have a master/slave environment with multiple slaves, and you do periodic backups of your system on the slave with mysqlhotcopy, the &#8211;record_log_pos parameter will pull the wrong co-ordinates from the master and cause you to restore new copies of your database that are potentially corrupt.<br />
An example failure scenario can be found <a href="http://forums.mysql.com/read.php?26,143765,143765">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomictech.com/2008/04/02/subtle-mysqlhotcopy-bug-fix-finally-accepted/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
