<?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>Todd Pinkerton &#187; mysql</title>
	<atom:link href="http://www.toddpinkerton.com/blog/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.toddpinkerton.com/blog</link>
	<description>have you tried turning it off and on again?</description>
	<lastBuildDate>Sat, 17 Oct 2009 00:09:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL tuning 101</title>
		<link>http://www.toddpinkerton.com/blog/2006/10/25/mysql-tuning-101/</link>
		<comments>http://www.toddpinkerton.com/blog/2006/10/25/mysql-tuning-101/#comments</comments>
		<pubDate>Wed, 25 Oct 2006 19:29:30 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[tech]]></category>

	<!-- AutoMeta Start -->
	<category>queries</category>
	<category>queries</category>
	<category>indexes</category>
	<category>query</category>
	<category>tune</category>
	<category>create</category>
	<category>show</category>
	<category>connections</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://www.toddpinkerton.com/blog/?p=6</guid>
		<description><![CDATA[In my last post, I talked about how hard it was to find good resources for newbies to learn database tuning, especially with the very popular MySQL database &#8212; the free or commercial version.
This post will talk you through the basics of database tuning. Ready? here we go:
1) hardware is important.
Ideally, your mySQL server will [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I talked about how hard it was to find good resources for newbies to learn database tuning, especially with the very popular MySQL database &#8212; the free or commercial version.</p>
<p>This post will talk you through the basics of database tuning. Ready? here we go:</p>
<p>1) hardware is important.</p>
<p>Ideally, your mySQL server will be on its own dedicated box.  Sharing it with Apache and the rest of your application may be fine starting off, but eventually you&#8217;ll want a dedicated machine for it. This also helps establish the right infrastructure for scalability, so you can add more webserver boxes which all connect to your database machine.</p>
<p>So of course, things like RAM (speed and amount of), disk (speed and size of), and CPU horsepower all matter. Get as much as you can.</p>
<p>2) get the right tools.  To even begin to tune the performance of your database, you need to be able to measure it.  So get some good tools like</p>
<p>* <a title="mytop" href="http://jeremy.zawodny.com/mysql/mytop/">mytop</a> (monitor mysql queries and performance)<br />
* <a title="ab -- apache benchmark" href="http://httpd.apache.org/docs/2.0/programs/ab.html">ab</a> (apache benchmark, for load-testing apache)<br />
* <a title="top" href="http://www.unixtop.org/">top</a> (cpu/memory performance, process management)<br />
* <a title="iostat" href="http://www.adminschoice.com/docs/iostat_vmstat_netstat.htm">iostat</a> (disk/cpu performance)</p>
<p>and and learn how to use them.  Test your database using whatever queries and scenarios your encounter in your &#8216;real world &#8216; application.  As you tune you want to see queries per second go up, and time per request go down.<br />
3) you run top, and find that your database is occupying 99% of the CPU.  Now what?</p>
<p>If your database is thrashing, now is the time to take action.  Start by looking at your sql queries in your application.  Turn on &#8216;<a title="slow query log" href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html">log slow queries</a>&#8216; in mysqldb &#8212; this will show you which sql statements are slowing down your db.  I had a situation where I was  calling &#8216;.lower()&#8217; on some columns before doing string comparisons in my application, but this was unnecessary &#8212; mySQL is case-insensitive by default, and using .lower() was causing my indexes to be ignored! So go through all your SQL statements very carefully, and pay special attention to the functions you call and any that show up in the slow queries log.<br />
4)  create good indexes.  Indexes make queries on your tables go faster.  Creating the right indexes is a fine art, but for starters create an index on everything in your WHERE clause. If there&#8217;s more than one column in your WHERE clause, create an index that covers both (or all) those columns.  Make sure your indexes are being used by running &#8216;describe&#8217; on your queries, for example : DESC select * from items;</p>
<p>This will show you what indexes are available, and which ones are being used.  Do this for every query in your application.<br />
5) Tune some mySQL parameters on the server.  Some basic ones are query-cache-type and query-cache-size (to turn on <a title="mySQL query caching" href="http://www.databasejournal.com/features/mysql/article.php/3110171">query caching</a>), and thread_cache_size (to enable <a title="mySQL thread caching" href="http://jeremy.zawodny.com/blog/archives/000173.html">thread caching</a>).  Turning on both of these should help.</p>
<p>At this point, you should have a reasonably fast database; you should also see your CPU usage for mysqld go way down.  But to make your entire app run smoothly, you&#8217;ll want to take a look at how mysql interacts with apache (httpd).  Although not everyone uses apache for their webserver, chances are you do, and if you adjust some of the apache params things will get even better.</p>
<p>For example, if Apache is set to allow 200 max connections, then your database should never get more than that number of simultaneous connections (one mysql connection per apache client), so you can scale back those attributes &#8212; which should free up ram and CPU.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.toddpinkerton.com/blog/2006/10/25/mysql-tuning-101/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>the S-word</title>
		<link>http://www.toddpinkerton.com/blog/2006/10/23/the-s-word/</link>
		<comments>http://www.toddpinkerton.com/blog/2006/10/23/the-s-word/#comments</comments>
		<pubDate>Mon, 23 Oct 2006 22:27:04 +0000</pubDate>
		<dc:creator>todd</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[scalability]]></category>

	<!-- AutoMeta Start -->
	<category>performance</category>
	<category>mysql</category>
	<category>tips</category>
	<category>support</category>
	<category>database</category>
	<category>commercial</category>
	<category>bandwidth</category>
	<category>application</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://www.toddpinkerton.com/blog/2006/10/23/the-s-word/</guid>
		<description><![CDATA[These days, everybody claims to be building the next YouTube, the next Google, &#8220;the Flickr of &#8230;&#8221; something.  They talk about slick AJAX web2.0 interfaces, or the awesome features they are building, or how great the content is.
But deep down, every one of these Web2.0-could-be site&#8217;s operator has a dreadful, paralyzing fear of the [...]]]></description>
			<content:encoded><![CDATA[<p>These days, everybody claims to be building the next YouTube, the next Google, &#8220;the Flickr of &#8230;&#8221; something.  They talk about slick AJAX web2.0 interfaces, or the awesome features they are building, or how great the content is.</p>
<p>But deep down, every one of these Web2.0-could-be site&#8217;s operator has a dreadful, paralyzing fear of the S-word:</p>
<p>Scalability.</p>
<p>Sooner or later, any moderately successful web application will need support a large number of users, lots of requests, and consume tons of bandwidth.  I wonder what percentage of those &#8220;google adsense whores&#8221; paychecks go to paying their bandwidth bills?</p>
<p>There exists all over the net tips to improve your website performance &#8212; from configuring Apache with Worker threads, to tuning your CSS &#8212; but usually the biggest performance bottleneck in a web application is the database.</p>
<p>I was having a chat last week with a web startup (that shall remain nameless) about how hard it is to get support for their MySQL database.  MySQL is the most popular open-souce and free database, but they also sell a commercial version. This company was trying to buy the commercial product &#8212; trying to give MySQL their money! &#8212; and having trouble getting the support they wanted. The developers at this startup reminded me, that when you call Oracle and ask to buy their expensive database, a swarm of sales engineers descend upon your site to help you get the most out of it. Why doesn&#8217;t MySQL (the company) rush to support buyers of MySQL (the database) ?<br />
So why is it so hard to find resources for this stuff? If you want to learn Java, there are 10 million places to start learning. But if you need to learn how to scale your site, how to increase performance and sustain higher traffic, there&#8217;s no one-stop destination for this.  Some of the best tips I&#8217;ve found are at <span class="l">Jeremy Zawodny&#8217;s</span> blog, but the problem remains: there are 1000 different little tips and tweaks to try, and depending on your situation it may do nothing for you.</p>
<p>So I want to pull together a top-5 list of MySQL (and webapp in general) performance tuning tips.  Where to start looking if you&#8217;re having trouble handling heavy load.</p>
<p>My next post will give my top-5 (or so) tips and strategies for tuning MySQL.  At the least, I hope it will provide developers and site administrators a place to start looking to enhance their database performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.toddpinkerton.com/blog/2006/10/23/the-s-word/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
