<?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>Transactions on InnoDB &#187; InnoDB Plugin</title>
	<atom:link href="http://blogs.innodb.com/wp/category/innodb-plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.innodb.com/wp</link>
	<description>&#34;The word&#34; about InnoDB Products and Technology</description>
	<lastBuildDate>Mon, 17 May 2010 16:28:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Only God can make random selections</title>
		<link>http://blogs.innodb.com/wp/2009/04/only-god-can-make-random-selections/</link>
		<comments>http://blogs.innodb.com/wp/2009/04/only-god-can-make-random-selections/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 22:51:28 +0000</pubDate>
		<dc:creator>Vasil Dimov</dc:creator>
				<category><![CDATA[InnoDB Builtin]]></category>
		<category><![CDATA[InnoDB Plugin]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=392</guid>
		<description><![CDATA[Recently, it was reported (see MySQL bug #43660) that &#8220;SHOW INDEXES/ANALYZE does NOT update cardinality for indexes of InnoDB table&#8221;.   The problem appeared to happen only on 64-bit systems, but not 32-bit systems.  The bug turns out to be a case of mistaken identity.  The real criminal here wasn&#8217;t the SHOW [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, it was reported (see MySQL <a href="http://bugs.mysql.com/43660">bug #43660</a>) that &#8220;SHOW INDEXES/ANALYZE does NOT update cardinality for indexes of InnoDB table&#8221;.   The problem appeared to happen only on 64-bit systems, but not 32-bit systems.  The bug turns out to be a case of mistaken identity.  The real criminal here wasn&#8217;t the SHOW INDEXES or the ANALYZE command, but something else entirely.  It wasn&#8217;t specific to 64-bit platforms, either.  Read on for the interesting story about this mystery and its solution &#8230;</p>
<p>InnoDB estimates statistics for the query optimizer by picking random pages from an index.  Upon detailed analysis, we found that the algorithm that picks random pages for estimation always picked the same page, thus producing the same result every time.    This made it appear that the index cardinality was not updated by ANALYZE TABLE. Going deeper, the reason the algorithm always selected the same page was that the random number generator always generated numbers that, when divided by 3, always gave the same remainder (2).</p>
<p>The sampling algorithm selects a random leaf page by starting from the root page and then selecting a random record from it, descending into its child page and so on until it reaches a leaf page. In the particular case that was reported in the bug report, the root page contained only 3 records and the tree height was only 2 (i.e., the leaf pages were all just below the root page).</p>
<p>You can already guess what happened.  The &#8220;random&#8221; numbers generated, not being so random, caused the algorithm to always pick the same record from the root page (the second one) and then descend to the leaf page below it. Every time.  So, the 8 random pages that were sampled in order to get an estimate of the whole picture were in fact the same page, even in isolated ANALYZE TABLE runs.  </p>
<p>So, clearly there was a problem with the random number generator.  But why didn&#8217;t this problem seem to appear on 64-bit platforms?   It would have, had we only enough time to wait.  The random number generator, always generating numbers like 3k+2 of type unsigned long, at some point wrapped around 4 billion on 32-bit machines and started generating numbers like 3k+1. On 64-bit machines, where unsigned long is much bigger, this wrap did not occur.   But it would have occurred if we ran the test for 1000 years!. </p>
<p><span id="more-392"></span></p>
<p>So, on 32-bit machines, at some point the first record from the root page was picked instead of the second one, and this caused some changes in the results produced by ANALYZE TABLE. Yet, on 64-bit machines, for all practical purposes, this &#8220;never&#8221; happens.  By only looking at the symptoms, one would get the impression that the flaw existed only on 64-bit machines and that 32-bit systems were ok.</p>
<p>Well, what about the fix?  A possible fix would be to change InnoDB in 64-bit environments to behave the same way it does in 32-bit environments. People who are used to the behavior of InnoDB on 32-bit machines and upgrade to a 64-bit machine might be satisfied, because the problem on 64-bit systems was &#8220;solved&#8221;.  But in reality, this approach in no way would fix the underlying problem.  The real solution is to replace the random number generator with a better one (fully realizing that algorithmic random number generators are only <em>pseudo</em>-random number generators).</p>
<p>Yet even that is not so simple.  Making any change would have caused changes to index cardinality estimations, thereby causing changes in decisions made by the optimizer, resulting in different execution plans &#8230; and different, possibly worse, performance for queries. Because MySQL 5.1 and 5.0 are frozen for such drastic changes, we fixed this bug in the upcoming 1.0.4 release of the <a href="http://www.innodb.com/innodb_plugin/">InnoDB Plugin</a>.</p>
<p>In order to not break existing applications, and since many people wanted a fix for MySQL 5.0 and 5.1, we implemented this fix for MySQL under the control of a new configuration parameter (innodb_use_legacy_cardinality_algorithm), which is turned on by default, preserving past behavior.  Because the &#8220;right fix&#8221; is to permanently change the random number generator, this new configuration parameter is not present in the InnoDB Plugin, and the &#8220;more random&#8221; random number generator will always be used.</p>
<p>And that is the end of the case of mistaken identity.   It turns out that it is really hard to generate truly random numbers, hence the title of this blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2009/04/only-god-can-make-random-selections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Software is Hard Sometimes &#8230;</title>
		<link>http://blogs.innodb.com/wp/2009/03/software-is-hard-sometimes/</link>
		<comments>http://blogs.innodb.com/wp/2009/03/software-is-hard-sometimes/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:00:59 +0000</pubDate>
		<dc:creator>Vasil Dimov</dc:creator>
				<category><![CDATA[InnoDB Plugin]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[mutex]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[portability]]></category>
		<category><![CDATA[Scalability]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=350</guid>
		<description><![CDATA[Some months ago, Google released a patch for InnoDB that boosts performance on multi-core servers.  We decided to incorporate the change into the InnoDB Plugin to make everybody happy: users of InnoDB don&#8217;t have to apply the patch, and Google no longer has to maintain the patch for new versions of InnoDB.  And [...]]]></description>
			<content:encoded><![CDATA[<p>Some months ago, Google released a <a href="http://code.google.com/p/google-mysql-tools/wiki/SmpPerformance">patch</a> for InnoDB that boosts performance on multi-core servers.  We decided to incorporate the change into the InnoDB Plugin to make everybody happy: users of InnoDB don&#8217;t have to apply the patch, and Google no longer has to maintain the patch for new versions of InnoDB.  And it makes us at Innobase happy because it improves our product (as you can in <a href="http://blogs.innodb.com/wp/2009/03/plug-in-for-performance-and-scalability/">this post</a> about InnoDB Plugin release 1.0.3).</p>
<p>However, there are always technical and business issues to address.  Given the low-level changes in the patch, was it technically sound?   Was the patch stable and as rock solid as is the rest of InnoDB?  Although it was written for the built-in InnoDB in MySQL 5.0.37, we needed to adapt it to the InnoDB Plugin. Could we make the patch portable to many platforms?   Could we incorporate the patch without legal risk (so it could be licensed under both the GPL and commercial terms)?</p>
<p>Fortunately Google generously donated the patch to us under the BSD license, so there was no concern about intellectual property (so long as we properly acknowledged the contribution, which we do in an Appendix to the manual and in the source code).  So, while the folks at Google are known for writing excellent code, we had to thoroughly review and test the patch before it could be incorporated in a release of InnoDB.</p>
<p>The patch improves performance by replacing InnoDB mutex and rw-mutex with atomic memory instructions. The first issue that arose was that the patch assigned the integer value -1 to a pthread_t variable, to refer to a neutral/non-existent thread identifier.  This approach worked for Google because they use InnoDB solely on Linux. As it happens, pthread_t is defined as an integer on Linux.</p>
<p>But we had problems when the patch was tested on FreeBSD.  We still needed to reference a non-existent thread, but in some environments (e.g. some versions of HPUX, Mac OS X) pthread_t is defined as a<br />
structure, not an integer.  As we looked at it, the problem became more complex.  For this scheme to work, it must be possible to change thread identifiers atomically, using a Compare-And-Swap instruction.  Otherwise, there will be subtle, mysterious and nasty failures.</p>
<p><span id="more-350"></span></p>
<p>We thought about enabling this patch only on Linux.  But that approach was not optimal, because the patch could work perfectly well on other platforms where pthread_t is the same size as the machine word, like FreeBSD and Solaris, for example.   We could have simply enumerated the operating system names where the patch would be supported, but this too was far from perfect.  The ability to use the atomic instructions depends not only on the operating system, but the GCC version (has to be 4.1 or newer) and the capabilities of the CPU (some CPUs do not support Compare-And-Swap!).</p>
<p>So, we developed a dynamic compile-time check for checking whether the target environment (pthread_t type and size, GCC version, CPU capabilities) supports the use of atomic instructions as intended. This seemed to be the best approach, but then another problem arose! </p>
<p>Dynamic compile-time checks (i.e. autoconf) are part of the MySQL&#8217;s ./configure script.  Innobase does not control this script, and so we must live with what is distributed by MySQL.  To make things simple for<br />
users, we wanted to avoid asking the users to re-create ./configure with the autotools. So we simply injected the required checks in the Makefile.  This seemed to work fine.   Only after release of the InnoDB Plugin 1.0.3 did a small crack in this approach arise.  Fortunately this problem turned out to be easy to fix and only occurs if one compiles with &#8220;make -j&#8221; (in order to perform the make in parallel). See <a href="http://bugs.mysql.com/43740">Bug#43740</a> for details and for a fix.</p>
<p>The bottom line is that sometimes more goes on &#8220;behind the scenes&#8221; than you might expect when it comes to incorporating a third-party contribution into a product.  We are grateful for the Google patch, and are glad that we have been able to include it in the InnoDB Plugin in a way that maximizes its portability, while keeping things as simple as possible for users.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2009/03/software-is-hard-sometimes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Plug In for Performance and Scalability</title>
		<link>http://blogs.innodb.com/wp/2009/03/plug-in-for-performance-and-scalability/</link>
		<comments>http://blogs.innodb.com/wp/2009/03/plug-in-for-performance-and-scalability/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 22:00:41 +0000</pubDate>
		<dc:creator>Ken Jacobs</dc:creator>
				<category><![CDATA[InnoDB Plugin]]></category>
		<category><![CDATA[Built-in]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Configuration parameter]]></category>
		<category><![CDATA[Hash index]]></category>
		<category><![CDATA[Insert buffer]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Mutexes]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Tuning]]></category>

		<guid isPermaLink="false">http://blogs.innodb.com/wp/?p=67</guid>
		<description><![CDATA[Why should you care about the latest &#8220;early adopter&#8221; release of the InnoDB Plugin, version 1.0.3?   One word: performance! The release introduces these features:

Enhanced concurrency &#38; scalability: the “Google SMP patch” using atomic instructions for mutexing
More efficient memory allocation: ability to use more scalable platform memory allocator
Improved out-of-the-box scalability: unlimited concurrent thread execution by [...]]]></description>
			<content:encoded><![CDATA[<p>Why should you care about the latest &#8220;early adopter&#8221; release of the InnoDB Plugin, version 1.0.3?   One word: <strong>performance!</strong> The release introduces these features:</p>
<ul>
<li>Enhanced concurrency &amp; scalability: the “Google SMP patch” using atomic instructions for mutexing</li>
<li>More efficient memory allocation: ability to use more scalable platform memory allocator</li>
<li>Improved out-of-the-box scalability: unlimited concurrent thread execution by default</li>
<li>Dynamic tuning: at run-time, enable or disable insert buffering and adaptive hash indexing</li>
</ul>
<p>These new performance features can yield <strong>up to twice the throughput</strong> or more, depending on your workload, platform and other tuning considerations.   In another post, we explore some details about these changes, but first, what do these enhancements mean for performance and scalability?</p>
<p>In brief, we&#8217;ve tested three different workloads (joins, DBT2 OLTP and a modified sysbench) using a memory-resident database.  In all cases, the InnoDB Plugin scales significantly better than the built-in InnoDB in MySQL 5.1.  And in some cases, the absolute level of performance is dramatically higher too!   The charts below illustrate the kinds of performance gains we&#8217;ve measured with release 1.0.3 of the InnoDB Plugin. Your mileage may vary, of course.  See the <a href="http://www.innodb.com/wp/innodb_plugin/plugin-performance">InnoDB website</a> for all the details on these tests.</p>
<p>This release of the InnoDB Plugin incorporates a <a href="http://code.google.com/p/google-mysql-tools/wiki/SmpPerformance" target="new">patch made by Ben Handy and Mark Callaghan at Google</a> to improve multi-core scalability by using more efficient synchronization methods (mutexing and rw-locks) to reduce cpu utilization and contention.   We&#8217;re grateful for this contribution, and you will be too!</p>
<p><span id="more-67"></span></p>
<p>Now to our test results &#8230;</p>
<p><strong>Joins: </strong>The following chart shows the performance gains in performing joins, comparing the built-in InnoDB in MySQL (in <span style="color:blue">blue</span>) with the InnoDB Plugin 1.0.3 (in <span style="color:red">red</span>).</p>
<div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em;" href="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=7&amp;output=image"><img src="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=7&amp;output=image" border="0" alt="" width="400" height="250" /></a></div>
<p>As you can see from the blue bars in the above chart, with MySQL 5.1 using the built-in InnoDB, the total number of joins the system can execute declines as the number of concurrent users increases.   In contrast, the InnoDB Plugin slightly improves performance even with one user, and maintains performance as the number of users rises.   This performance improvement is due in large part to the use of atomics for mutexing in the InnoDB Plugin.</p>
<p><strong>Transaction Processing (DBT2):</strong> The following chart illustrates a scalability improvement using  the OLTP read/write DBT2 benchmark, again comparing the performance of <span style="color:blue">the built-in InnoDB in MySQL</span> with the performance of <span style="color:red">InnoDB Plugin 1.0.3</span>.</p>
<div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em;" href="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=8&amp;output=image"><img src="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=8&amp;output=image" border="0" alt="" width="400" height="250" /></a></div>
<p>Here, the InnoDB Plugin scales better than the built-in InnoDB from 16 to 32 users and produces about 12% more throughput with 64 concurrent users, as other bottlenecks are encountered or system capacity is reached.  This improvement is likewise due primarily to the changes in mutexing.</p>
<p><strong>Modified Sysbench:</strong> This test uses a version of the well-known sysbench workload, modified to include queries based on a secondary index, <a href="http://mysqlha.blogspot.com/2009/02/update-for-sysbench.html">as suggested</a> by Mark Callaghan of Google.</p>
<div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em;" href="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=9&amp;output=image"><img src="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=9&amp;output=image" border="0" alt="" width="400" height="250" /></a></div>
<p>This time, the InnoDB Plugin shows significantly better scalability from 8 to 64 users than the built-in InnoDB in MySQL, yielding as much as 60% more throughput at 64 users.  Like the previous examples, this improvement is largely due to the use of atomics for mutexing.</p>
<p><strong>Modified Sysbench with tcmalloc:</strong> This test uses the same modified sysbench workload, but shows the difference between the built-in InnoDB (which uses the internal InnoDB memory allocator) and the InnoDB Plugin when using a more scalable memory allocator, in this case <a href="http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html">tcmalloc</a>.</p>
<div class="separator" style="clear: both; text-align: center;"><a style="margin-left: 1em;" href="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=10&amp;output=image"><img src="http://spreadsheets.google.com/pub?key=ppe5byK5r-M54VD8dWLF0Vw&amp;oid=10&amp;output=image" border="0" alt="" width="400" height="250" /></a></div>
<p>When the new configuration parameter <code>innodb_use_sys_malloc</code> is set to enable use of the memory allocator tcmalloc, the InnoDB Plugin really shines!  Transaction throughput continues to scale, and the actual throughput with 64 users has nearly doubled!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.innodb.com/wp/2009/03/plug-in-for-performance-and-scalability/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
