<?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>All Night Diner &#187; MySQL</title>
	<atom:link href="http://micropipes.com/blog/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://micropipes.com/blog</link>
	<description>because at 3am anything sounds good</description>
	<lastBuildDate>Mon, 03 May 2010 17:34:44 +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>AMO Scalability: Then and Now</title>
		<link>http://micropipes.com/blog/2008/04/18/amo-scalability-then-and-now/</link>
		<comments>http://micropipes.com/blog/2008/04/18/amo-scalability-then-and-now/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 08:30:49 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[AMO]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/2008/04/18/amo-scalability-then-and-now/</guid>
		<description><![CDATA[Struggling with scalability on AMO is nothing new but the tools we use to solve the problems have changed over time.  Here is a bit of information on the performance evolution AMO has gone through.  I wanted to link to the wayback machine for all our old versions, but I get &#8220;Redirect Errors&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Struggling with scalability on <abbr title="addons.mozilla.org">AMO</abbr> is nothing new but the tools we use to solve the problems have changed over time.  Here is a bit of information on the performance evolution AMO has gone through.  I wanted to link to the <a href="http://www.archive.org/web/web.php">wayback machine</a> for all our old versions, but I get &#8220;Redirect Errors&#8221; for the addons.mozilla.org domain.  I&#8217;ll have to make due with code repositories.</p>
<p><a href="http://mxr.mozilla.org/mozilla/source/webtools/update/">Version 1</a> of AMO wasn&#8217;t concerned with caching.  It was straight <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> talking directly to a single MySQL box.  Short, easy, and not very scalable.</a></p>
<p><a href="http://lxr.mozilla.org/mozilla/source/webtools/addons/">Version 2</a> of AMO progressed through several caching systems.  The site used the <a href="http://www.smarty.net/">Smarty template engine</a> so our first step was to turn on the built in Smarty cache.  That didn&#8217;t give us the performance we needed, so <a href="http://morgamic.com/">Mike Morgan</a> started caching page output in <a href="http://pear.php.net/package/Cache_Lite"><abbr title="PHP Extension and Application Repository">PEAR</abbr>&#8217;s Cache_Lite</a>.  I don&#8217;t remember the specifics of this implementation since it was so short lived (less than a month), but the <a href="http://bonsai.mozilla.org/cvslog.cgi?file=mozilla/webtools/addons/public/inc/finish.php&#038;rev=HEAD&#038;mark=1.7">CVS log</a>, mentions problems with &#8220;scalability in a clustered environment.&#8221;  Our next step was to store the same page output in <a href="http://www.danga.com/memcached/">memcached</a> instead of Cache_Lite which brought pretty satisfying results.  Thus began our abuse of memcached.</p>
<p>In addition to memcached and expanding the number of web servers it ran on, version 2 also boasted two other significant performance improvements. The first was the ability to talk to a slave database for read-only queries which, when combined with a load balancer, let us scale database servers horizontally.  The second was installing a <a href="http://www.citrix.com/english/ps2/products/product.asp?contentID=21679">NetScaler</a> in front of addons.mozilla.org giving us the benefits of a reverse proxy cache and <abbr title="Secure Socket Layer">SSL</abbr> offloading.  These changes bought us precious time when hoards of Firefox 1.5 users were clamoring for add-ons.  In fact, I&#8217;d say we were in pretty good shape at that point.</p>
<p>Fast forward to <a href="http://svn.mozilla.org/addons/trunk/">Version 3</a> (the current version).  We&#8217;ve expanded the memcache servers from one to two and instead of page output we&#8217;re storing database queries and their results.  We&#8217;re still using a single master database but are using two slaves now for read only queries.  There are several NetScalers around the world caching pages locally[1] for closer regions.  We&#8217;ve survived quite a while on this system but we&#8217;re starting to push the envelope again and we&#8217;re going to need to make some changes to be able to scale for Firefox 3 and still provide a good user experience.  I&#8217;ll write more about our plans as they develop.</p>
<p>[1] Users who are logged in to AMO don&#8217;t get the local caches &#8211; their connection is always to San Jose, CA.</p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2008/04/18/amo-scalability-then-and-now/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>When is a TINYINT(1) not a TINYINT(1)?</title>
		<link>http://micropipes.com/blog/2008/03/07/when-is-a-tinyint1-not-a-tinyint1/</link>
		<comments>http://micropipes.com/blog/2008/03/07/when-is-a-tinyint1-not-a-tinyint1/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 23:50:30 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[o rly]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/2008/03/07/when-is-a-tinyint1-not-a-tinyint1/</guid>
		<description><![CDATA[When you&#8217;re using CakePHP!
Turns out CakePHP considers a TINYINT(1) to be a Boolean.  Judging from all the support tickets that have been filed, I&#8217;m not the first person to get taken off guard by this behavior.  When I asked about it on IRC, the response was that since MySQL considers a TINYINT(1) to [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re using <a href="http://cakephp.org/">CakePHP</a>!</p>
<p>Turns out CakePHP considers a TINYINT(1) to be a Boolean.  Judging from all <a href="https://trac.cakephp.org/ticket/1253">the</a> <a href="https://trac.cakephp.org/ticket/3903">support</a> <a href="https://trac.cakephp.org/ticket/4026">tickets</a> that have been filed, I&#8217;m not the first person to get taken off guard by this behavior.  When I asked about it on IRC, the response was that since MySQL considers a TINYINT(1) to be a Boolean, CakePHP does too.  That&#8217;s not true.</p>
<p>From the <a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html">MySQL manual</a>:</p>
<blockquote><p>As of MySQL 5.0.3, a BIT data type is available for storing bit-field values. (Before 5.0.3, MySQL interprets BIT as TINYINT(1).)</p></blockquote>
<p>That&#8217;s saying if I request a BIT it will make it a TINYINT, not if I request a TINYINT it will make it a BIT.  Having a framework change the definitions of my database columns sounds crazy to me, but judging from <a href="https://trac.cakephp.org/ticket/1253">the ticket filed in 2006</a> this has been CakePHP&#8217;s policy for a long time.  Despite the long standing precedent I can&#8217;t find any documentation about it online other than the closing remarks of those support tickets.  </p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2008/03/07/when-is-a-tinyint1-not-a-tinyint1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If it&#8217;s a string, call it a string</title>
		<link>http://micropipes.com/blog/2007/06/04/if-its-a-string-call-it-a-string/</link>
		<comments>http://micropipes.com/blog/2007/06/04/if-its-a-string-call-it-a-string/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 18:07:12 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/2007/06/04/if-its-a-string-call-it-a-string/</guid>
		<description><![CDATA[This is probably well documented, but it&#8217;s a good reminder anyway.  If you&#8217;ve got a column in MySQL that is textual (like a varchar), you need to make sure MySQL sees the data going into it as a string.  Here&#8217;s an example I stumbled across today when I left out some quotation marks [...]]]></description>
			<content:encoded><![CDATA[<p>This is probably well documented, but it&#8217;s a good reminder anyway.  If you&#8217;ve got a column in MySQL that is textual (like a varchar), you need to make sure MySQL sees the data going into it as a string.  Here&#8217;s an example I stumbled across today when I left out some quotation marks &#8211; `averagerating` is a varchar(255):</p>
<div class="code">
<pre>
mysql> select averagerating from addons where id=5001;
+---------------+
| averagerating |
+---------------+
| 0             |
+---------------+
1 row in set (0.00 sec)

mysql> UPDATE addons SET averagerating = 9.33 WHERE id = 5001;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select averagerating from addons where id=5001;
+-----------------------------------------------------+
| averagerating                                       |
+-----------------------------------------------------+
| 9.3300000000000000710542735760100185871124267578125 |
+-----------------------------------------------------+
1 row in set (0.00 sec)

mysql> UPDATE addons SET averagerating = '9.33' WHERE id = 5001;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select averagerating from addons where id=5001;
+---------------+
| averagerating |
+---------------+
| 9.33          |
+---------------+
1 row in set (0.00 sec)
</pre>
</div>
<p>Out of 1131 updates, 67 of them ended up with the extra characters and the rest looked just fine.  That means if you don&#8217;t double check the data pretty closely, something like this could slip by and lead to trouble later on.  Double check your SQL before you run it!</p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2007/06/04/if-its-a-string-call-it-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
