<?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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"><channel><title>Disruptive Library Technology Jester &#187; MySQL</title> <atom:link href="http://dltj.org/tag/mysql/feed/" rel="self" type="application/rss+xml" /><link>http://dltj.org</link> <description>We&#039;re Disrupted, We&#039;re Librarians, and We&#039;re Not Going to Take It Anymore</description> <lastBuildDate>Mon, 06 Feb 2012 20:04:22 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <cloud domain='dltj.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/us/</creativeCommons:license> <item><title>WordPress/MySQL Tuning</title><link>http://dltj.org/article/wordpress-mysql-tuning/</link> <comments>http://dltj.org/article/wordpress-mysql-tuning/#comments</comments> <pubDate>Thu, 22 Feb 2007 18:56:45 +0000</pubDate> <dc:creator>Peter Murray</dc:creator> <category><![CDATA[Meta Category]]></category> <category><![CDATA[Raw Technology]]></category> <category><![CDATA[Gentoo]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[system administration]]></category> <category><![CDATA[WordPress]]></category><guid isPermaLink="false">http://dltj.org/2007/02/wordpress-mysql-tuning/</guid> <description><![CDATA[dltj.org runs on a relatively tiny box &#8212; a Pentium III with 512MB of RAM. I&#8217;m running a Gentoo Linux distribution, so I actually have a prayer of getting useful work out of the machine (it server is actually a &#8230; <a href="http://dltj.org/article/wordpress-mysql-tuning/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<abbr class="unapi-id ignore noPrint" title="http://dltj.org/2007/02/wordpress-mysql-tuning/"></abbr><p><i>dltj.org</i> runs on a relatively tiny box &mdash; a Pentium III with 512MB of RAM.  I&#8217;m running a <a href="http://www.gentoo.org/" title="Gentoo Linux homepage">Gentoo</a> Linux distribution, so I actually have a prayer of getting useful work out of the machine (it server is actually a recycled Windows desktop), but the performance just wasn&#8217;t great.  As it turns out, there are several easy things one can do to dramatically improve life.</p><p><h2>The Configuration</h2><br />The box is both a mail server (IMAP) and a WordPress server.  A rough eyeball at the process accounting on the server shows that it spends about 40% of the time doing mail (mostly taken up by Clamscan virus scanning and spam checking) and another 40% doing MySQL and web stuff.  Since there isn&#8217;t much dynamic content on the box and nothing else using the database but WordPress, I&#8217;m fairly confident that blog traffic is almost all of that 40%.  I&#8217;m using MySQL 5.0.x, Apache 2.0.x and WordPress 2.0.x with about two dozen plugins.</p><p><h2>Taking PHP Up A Notch</h2><br />PHP is an interpreted programming language, meaning that each time a script runs it needs to be translated into something closer to machine code (called the &#8216;opcode&#8217;).  (As opposed to compiler languages like C and Java where you compile the source code into an executable in one step and then run that executable in a second step.)  For an application like WordPress, where the source code is not changing, this translation causes a lot of overhead.  Fortunately, there is a PHP plug-in called the <a href="http://php.net/apc" title="Alternative PHP Cache home page">Alternative PHP Cache</a> that will saved the translated opcode the first time the script runs and use it for subsequent invocations.  Getting this set up is pretty easy (these are Gentoo-specific commands, your Linux distribution will vary and I am glossing over a number of distribution-specific details like how to install packages and where the configuration files will reside):</p><ol><li><code>emerge -aDNtuv pecl-apc</code> will download and install PHP APC and its dependencies (yep &#8212; that easy&#8230;I <em>love</em> Gentoo)</li><li>Change the configuration defaults in <code>/etc/php/apache2-php5/ext/apc.ini</code>.  I&#8217;ve found that one shared segment of 20MB is enough, so I set <code>apc.shm_size="20"</code>.  The rest of the settings are as they came in the distribution.</li><li>Restart your web server: <code>/etc/init.d/apache2 restart</code></li></ol><p>APC comes with a nifty PHP page that will give you cache statistics and details.  If you copy <code>/usr/share/php5/apc/apc.php</code> into your &#8216;htdocs&#8217; somewhere and execute that page from a browser, you&#8217;ll see what I mean.  (This is how I learned that 20MB of opcode cache space was fine for my application.)</p><p><h2>Kicking MySQL Into Gear</h2><br />Database tuning focuses a great deal on memory management.  Your RAM will always be an order of magnitude faster than reading blocks off a disk.  RAM, of course, costs more per MB than disk, though, so you have to select memory management strategies carefully.  WordPress is, of course, a read-intensive operation.  In other words, the majority of SQL statements are SELECTs rather than INSERTs, UPDATEs, or DELETEs.  With that in mind, we tune MySQL with a read-intensive strategy.  I found some of the best guidance in <a href="http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/" title="What to tune in MySQL Server after installation from MySQL Performance Blog"> Peter Zaitsev&#8217;s &#8220;What to tune in MySQL Server after installation&#8221;</a> and the ez.no documentation on <a href="http://ez.no/community/articles/tuning_mysql_for_ez_publish/optimizing_for_read_performance" title="">Optimizing for read performance</a>.</p><p>The changes I made to my MySQL configuration file, in the <code>[mysqld]</code> section are:</p><pre>key_buffer = 6M ; (Actually, a decrease from the default since I didn't seem to need as much)table_cache = 512max_connections = 25thread_cache = 16query_cache_type = 1query_cache_limit = 1Mquery_cache_size = 20M</pre><p>The 20MB query cache limit seems to be just about the right size for me.  I seem to get very close to the edge of that buffer, but never seem to go over.</p><p><h2>Finishing Up with a WordPress Plug-in</h2><br />One more thing is needed to make this all come together: Mark Jaquith&#8217;s <a href="http://txfx.net/code/wordpress/post-query-accelerator/" title="Post Query Accelerator WordPress Plug-in Homepage">Post Query Accelerator</a>.  As Mark points out on his blog, WordPress &#8220;always ask[s] for posts with post_date_gmt &lt;= &#8216;$now&#8217; where $now is set to the current time, to prevent posts in the future from showing up.&#8221;  If one turns on cache querying as described above, the &#8220;problem with $now is that it changes [with each query], so the query is never exactly the same again and the cache doesn’t help.&#8221;  Mark&#8217;s plug-in &#8220;freezes&#8221; the value of $now to 15 minute increments or to whenever a post is added/updated, which ever comes first.  That makes the query cache useful again and all is well.</p><p>Simply download the plug-in from Mark&#8217;s page and enable it in WordPress.  Note that this plug-in is not needed for WordPress 2.1 and higher as the core developers have solved the &#8220;$now&#8221; problem with the &#8220;future&#8221; post status.</p>]]></content:encoded> <wfw:commentRss>http://dltj.org/article/wordpress-mysql-tuning/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> </channel> </rss>
<!-- Served from: dltj.org @ 2012-02-11 09:28:56 by W3 Total Cache -->
