<?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>Alunduil&#039;s Hosting &#187; optimization</title>
	<atom:link href="http://www.alunduil.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alunduil.com</link>
	<description>Gentoo Hackery and Other Fun ...</description>
	<lastBuildDate>Sun, 01 May 2011 22:00:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Optimizing Gentoo CFLAGS (Part II)</title>
		<link>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/</link>
		<comments>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 23:00:46 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cflags]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=205</guid>
		<description><![CDATA[Introduction As I mentioned las﻿t time, you want to be comfortable with the existing documentation on CFLAGS before going crazy trying to play with. It also helps to have a good understanding of what you&#8217;re doing to the code when you modify these &#8220;sacred&#8221; parameters. Alright, now that the CYA is out of the way <a href='http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>As I mentioned <a href="http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/">las﻿t time</a>, you want to be comfortable with the existing documentation on CFLAGS before going crazy trying to play with.  It also helps to have a good understanding of what you&#8217;re doing to the code when you modify these &#8220;sacred&#8221; parameters.</p>
<p>Alright, now that the CYA is out of the way let&#8217;s take this one step further.  Last time we talked about figuring out which instruction sets your processor understood and how to figure out what `-m` flags would get those instruction sets into the binaries on your system.  This time we&#8217;ll be talking about making sure those same flags are in your use flags (just to be sure they&#8217;re picked up by the system).</p>
<h1>Finding Flag Names</h1>
<p>So how do we find the flags that do what we want?  Well, as always BASH is our friend and can be used to find this answer in a mostly automated fashion:</p>
<pre>. /etc/make.conf &amp;&amp; gcc -Q -c -v ${CFLAGS} --help=target | grep enabled</pre>
<p>This displays the currently enabled flags based on your CFLAGS parameter and allows us to find which flags have use flags with the following one liner:</p>
<pre>gawk '/-m.*/ { print $1 }' | cut -d 'm' --complement -f 1 | xargs -I{} equery h "{}"</pre>
<h1>Conclusion</h1>
<p>Using a little scripting we can extract the necessary information to quickly determine if there are any use flags we should be adding for particular compiler flags that our system might support.  With this last level of optimization beyond the previous time&#8217;s we should be ready to move on to -O3 (for the daring) and watch our machine&#8217;s nose bleed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mailing Portage Output</title>
		<link>http://www.alunduil.com/2011/01/18/mailing-portage-output/</link>
		<comments>http://www.alunduil.com/2011/01/18/mailing-portage-output/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 23:49:06 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[emerge]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=282</guid>
		<description><![CDATA[Introduction Portage is an amazingly simple and complex piece of technology.  The simplicity in each piece&#8217;s ability to do a specific function comes together in a complex package management system that rivals all other forms of package management (at least in my opinion).  Automating updates is something that admins everywhere do out of necessity.  Heck, <a href='http://www.alunduil.com/2011/01/18/mailing-portage-output/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Portage is an amazingly simple and complex piece of technology.  The simplicity in each piece&#8217;s ability to do a specific function comes together in a complex package management system that rivals all other forms of package management (at least in my opinion).  Automating updates is something that admins everywhere do out of necessity.  Heck, automating everything is an admin&#8217;s life.  Automating portage&#8217;s updates is a bit more harrowing than other package management systems but it isn&#8217;t impossible.</p>
<h1>Problem</h1>
<p>As admins we attempt to simplify the work we actually do by writing scripts and programs to do most of our job for us.  It&#8217;s often been said that systems admins are the only people whose job description is to remove their job responsibilities.</p>
<p>Portage doesn&#8217;t have any default automation for doing nightly or even weekly portage updates but that doesn&#8217;t stop the creative from coming up with their own solution.  A simple but elegant solution is to create a small cron script that runs every day.  The problem comes when you want to read the wonderful output of portage (sometimes these messages can guide you when problems are about to occur) to avert disasters.  If the updates are performed from cron, the output will be preserved in an e-mail to the appropriate user but then we have to sift through all of the output at once.  This also doesn&#8217;t solve the issue if the updates are performed by another utility such as puppet.  These annoying little changes to the problem require a slightly more elegant solution.</p>
<h1>Solution</h1>
<p>The solution is to take advantage of portage&#8217;s logging specifications.  From the make.conf man file:</p>
<ul>
<li>﻿﻿PORTAGE_ELOG_CLASSES</li>
<li>PORTAGE_ELOG_SYSTEM</li>
<li>PORTAGE_ELOG_COMMAND</li>
<li>PORTAGE_ELOG_MAILURI</li>
<li>PORTAGE_ELOG_MAILFROM</li>
<li>PORTAGE_ELOG_MAILSUBJECT</li>
</ul>
<p>Using a combination of these directives in the make.conf file allows us to log the reports from portage to a large number of locations.  If we wanted to simply add mailing output (not the full build output just the messages) we would add the following directives to make.conf:</p>
<pre>PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILFROM="portage@alunduil.com"</pre>
<p>This simply adds the mailing log utility to portage and specifies that the e-mails come from the address portage@alunduil.com.  Of course, much more complex configurations can be crafted to suit any admins&#8217; needs.</p>
<h1>Conclusion</h1>
<p>Letting your servers notify you of possible actions is one way of automating maintenance tasks; making maintenance eventually disappear from your task list. By starting with the tasks that are repeated the most frequently, you can quickly free up time for higher level automation and organization which leads to a cleaner and sturdier infrastructure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/01/18/mailing-portage-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is Load Average?</title>
		<link>http://www.alunduil.com/2010/09/09/what-is-load-average/</link>
		<comments>http://www.alunduil.com/2010/09/09/what-is-load-average/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 15:05:26 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[load average]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[system health]]></category>
		<category><![CDATA[system load]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=195</guid>
		<description><![CDATA[Introduction Often in administration people make reference to a magic number known as load average but it&#8217;s not always clear what this number means (besides being a magical indicator of whether or not the server is going to barf in a terrible fashion soon). This number doesn&#8217;t have a whole lot of detail in and <a href='http://www.alunduil.com/2010/09/09/what-is-load-average/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Often in administration people make reference to a magic number known as load average but it&#8217;s not always clear what this number means (besides being a magical indicator of whether or not the server is going to barf in a terrible fashion soon).  This number doesn&#8217;t have a whole lot of detail in and of itself (it&#8217;s meant to be a quick-glance overall health check afterall).</p>
<h1>What is it already?</h1>
<p>The load average is an exponentially damped/weighted moving average that is similar to a running n^2 average. This number is calculated not on every clock tick but in accordance with the jiffies the kernel is tracking. Every time slice (which <span style="text-decoration: underline;">can</span> although shouldn&#8217;t be tweaked in the kernel) the average is calculated based on the previous values. This rolling average allows us to keep a minimal amount of information on hand and still have an average since boot.</p>
<p>The load that gets placed into this average algorithm is simply a count of the number of processes in the run queue at that instant. Thus, since processes who are waiting on I/O (those in the D state) need to periodically check in or wait to be woken up by the kernel; these processes can contribute to the count of processes in the run queue. Since these processes aren&#8217;t taking CPU time but are taking space in the run queue they can increase the apparent load on the server (thus bringing in the I/O wait of the system into the load average) without raising the CPU usage time.</p>
<h1>Conclusion</h1>
<p>The load average doesn&#8217;t tell you a whole lot of information but coupled with information from `iostat` or your CPU usage you can quickly use it to gauge whether your server is falling over itself or not.  Since it reports the number of processes in the run queue it is safe to assume a reasonably efficient use of hardware would dictate you want n+1 as your load average where n is the number of cores in the system.</p>
<h1>References</h1>
<p>More information (including source code for this calculation) can be found here: <a href="http://en.wikipedia.org/wiki/Load_%28computing%29">http://en.wikipedia.org/wiki/Load_%28computing%29</a></p>
<p>An excellent reference on how the Linux process life cycle works is Robert Love&#8217;s Linux Kernel Development (which recently had a third edition released).</p>
<p>Another reference on the Linux process life cycle is <a href="http://wiki.kldp.org/wiki.php/ProcessManagement">http://wiki.kldp.org/wiki.php/ProcessManagement</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/09/09/what-is-load-average/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Memcached Remote Memory Sharing</title>
		<link>http://www.alunduil.com/2010/06/24/memcached-remote-memory-sharing/</link>
		<comments>http://www.alunduil.com/2010/06/24/memcached-remote-memory-sharing/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 22:15:03 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=150</guid>
		<description><![CDATA[Introduction Memcached is a simple key/value memory store that allows values from pretty much any application to be stored in memory for quick retrieval. Most languages have simple APIs that make this very easy from a programming standpoint. This also means that it&#8217;s not quite as simple to configure as APC (but similar for modern <a href='http://www.alunduil.com/2010/06/24/memcached-remote-memory-sharing/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Memcached is a simple key/value memory store that allows values from pretty much any application to be stored in memory for quick retrieval.  Most languages have simple APIs that make this very easy from a programming standpoint.  This also means that it&#8217;s not quite as simple to <a href="http://www.alunduil.com/2010/05/26/apc-caching-php/">configure as APC</a> (but similar for modern applications).</p>
<h1>Installation and Configuration</h1>
<p>To install memcached I recommend using your choice of installation (mine being emerge) and then checking the configuration (again in the case of Gentoo) located at /etc/conf.d/memcached.</p>
<p>Update the file to listen on the interface you want, use the memory you want, etc and then start the daemon up.  Now if you&#8217;re using memcached on the same server as your apache server most webapps will be able to just turn on memcached and connect and work, but if you&#8217;re using memcached and apache on separate servers it&#8217;s a little more work.</p>
<h1>WordPress and memcached</h1>
<p>I&#8217;ve already touted the wordpress plugin: <a href="http://www.w3-edge.com/wordpress-plugins/w3-total-cache/">W3 Total Cache</a> but unfortunately this plugin doesn&#8217;t allow you to easily configure memcached usage through the web interface.  It defaults to using the memcached server located at 127.0.0.1:11211 which if we&#8217;re using separate servers is less than ideal.  The file we need to modify with a simply sed (or by hand if you prefer knowing what&#8217;s going on) is %{DOCROOT}/wp-content/w3-total-cache-config.php.</p>
<p>We just need to change the memcached servers to point at our server&#8217;s location before enabling it in the interface.  To easily accomplish this we can use sed:</p>
<p>sed -i -e &#8216;s/127.0.0.1:11211/: /g&#8217; %{DOCROOT}/wp-content/w3-total-cache-config.php</p>
<h1>Mediawiki and memcached</h1>
<p>The other application we can easily setup for memcached is mediawiki.  Mediawiki wants us to modify its LocalSettings.php with the following additions:</p>
<p>## Shared memory settings<br />
$wgMainCacheType = CACHE_MEMCACHED;<br />
$wgParserCacheType = CACHE_MEMCACHED;<br />
$wgMessageCacheType = CACHE_MEMCACHED;<br />
$wgMemCachedServers = array(&#8220;giskard.alunduil.com:11211&#8243;);</p>
<p>$wgSessionsInMemcached = true;</p>
<p>These settings simply turn on memcached (CACHE_MEMCACHED) for the various caching areas that mediawiki uses and specifies an array of memcached servers to store that caching information in.</p>
<p>If you do have more than one memcached server configured and available you can use the following syntax to include all of them with various weights:</p>
<p>$wgMemCachedServers = array(array(&#8220;host:port&#8221;, weight), array(&#8220;host2:port2&#8243;, weight));</p>
<h1>Conclusion</h1>
<p>Using memcached can greatly improve the performance of webapps or other applications that don&#8217;t need to present the most up to date information.  This can reduce traffic to an overloaded database or configuration file or whatever other store you want to place a cache in front of.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/06/24/memcached-remote-memory-sharing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>APC Caching PHP</title>
		<link>http://www.alunduil.com/2010/05/26/apc-caching-php/</link>
		<comments>http://www.alunduil.com/2010/05/26/apc-caching-php/#comments</comments>
		<pubDate>Thu, 27 May 2010 00:42:57 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[w3 total cache]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=132</guid>
		<description><![CDATA[Introduction Making PHP run faster is usually pretty easy when you see some of the code that people can write (myself included) but what if we either don&#8217;t want to look at their code or don&#8217;t want to fix the code? What else can we do to improve the runtime and the load time of <a href='http://www.alunduil.com/2010/05/26/apc-caching-php/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Making PHP run faster is usually pretty easy when you see some of the code that people can write (myself included) but what if we either don&#8217;t want to look at their code or don&#8217;t want to fix the code?  What else can we do to improve the runtime and the load time of PHP web sites (this website included)?</p>
<p>We&#8217;ll cover how to use APC (Alternative PHP Cache) to help alleviate some of the issues of a slow web site.  Just like <a href="http://www.alunduil.com/2010/05/23/optimizing-the-am-out-of-lamp/">last time</a> we optimized MySQL and talked about optimizing Apache we&#8217;ll continue on the path to getting PHP applications as fast as we can (without touching a line of code).</p>
<h1>Enter APC</h1>
<p>APC is PEAR project and a PHP module that after installed and a restart of Apache is already doing some work to make life better.  By default APC turns on op-code caching which saves on the compile and execution times of PHP.  The configuration for this module is pretty straight forward, but let&#8217;s look at a copy of the one I&#8217;m using:</p>
<p>; /etc/php/apache2-php5/ext-active/apc.ini (On Gentoo anyways &#8230;)<br />
extension=apc.so<br />
apc.enabled=&#8221;1&#8243;<br />
apc.shm_segments=&#8221;4&#8243;<br />
apc.shm_size=&#8221;128&#8243;<br />
apc.num_files_hint=&#8221;1024&#8243;<br />
apc.ttl=&#8221;7200&#8243;<br />
apc.user_ttl=&#8221;7200&#8243;<br />
apc.gc_ttl=&#8221;3600&#8243;<br />
apc.cache_by_default=&#8221;1&#8243;<br />
;apc.filters=&#8221;"<br />
;apc.mmap_file_mask=&#8221;/tmp/apcphp5.XXXXXX&#8221;<br />
apc.slam_defense=&#8221;0&#8243;<br />
apc.file_update_protection=&#8221;2&#8243;<br />
apc.enable_cli=&#8221;0&#8243;<br />
apc.max_file_size=&#8221;1M&#8221;<br />
apc.stat=&#8221;1&#8243;<br />
apc.write_lock=&#8221;1&#8243;<br />
apc.report_autofilter=&#8221;0&#8243;<br />
apc.include_once_override=&#8221;0&#8243;<br />
apc.rfc1867=&#8221;0&#8243;<br />
apc.rfc1867_prefix=&#8221;upload_&#8221;<br />
apc.rfc1867_name=&#8221;APC_UPLOAD_PROGRESS&#8221;<br />
apc.rfc1867_freq=&#8221;0&#8243;<br />
apc.localcache=&#8221;0&#8243;<br />
apc.localcache.size=&#8221;512&#8243;<br />
apc.coredump_unmap=&#8221;0&#8243;</p>
<h1>Zooming In</h1>
<p>These options are documented fairly thoroughly in the <a href="http://php.net/manual/en/apc.configuration.php">APC PHP Manual</a>.</p>
<p>Most of these options can stay at their defaults and provide a pleasant experience but if we have the memory we should probably tweak these to get more out of them:</p>
<ul>
<li>apc.shm_segments &#8211; The number of chunks to use from /dev/shm.</li>
<li>apc.shm_size &#8211; The size of aforementioned chunks.</li>
</ul>
<p>These two parameters are the heart of APC and dictate the memory usage you&#8217;ll get out of it.  If you take segments*size you&#8217;ll get the maximum amount of shm space used by APC for the cache.  A limitation on shm_size is usually in place through the kernel and to determine what this is you can simply `cat /proc/sys/kernel/shmmax` (remember this command prints out B and APC expects MB).</p>
<h1>Further Caching</h1>
<p>APC also has an object cache available which can be used for just about anything but the application has to be modified to support this.  If you&#8217;re using <a href="http://wordpress.org/">WordPress</a> to host your site an excellent plugin for doing this is <a href="http://www.w3-edge.com/wordpress-plugins/w3-total-cache/">W3 Total Cache</a>.</p>
<h1>Conclusion</h1>
<p>APC can help you get an edge out of your server but, without careful tuning, won&#8217;t get you more than the last inch of performance.  Play with the memory settings until it isn&#8217;t over-utilizing memory (have a larger cache than your code base needs) or under-utilizing memory (having a smaller cache than your code base needs) but don&#8217;t forget you don&#8217;t want it to run into your swap space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/05/26/apc-caching-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing the AM out of LAMP</title>
		<link>http://www.alunduil.com/2010/05/23/optimizing-the-am-out-of-lamp/</link>
		<comments>http://www.alunduil.com/2010/05/23/optimizing-the-am-out-of-lamp/#comments</comments>
		<pubDate>Mon, 24 May 2010 02:22:34 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=127</guid>
		<description><![CDATA[A hot topic for anyone running MySQL and Apache on any machine is optimization and I hope to quickly explain how to optimize MySQL and where to tweak Apache to help with it&#8217;s operational efficiency as well. First things first &#8230; A few common things to possibly turn on, install, or enable: APC (Another PHP <a href='http://www.alunduil.com/2010/05/23/optimizing-the-am-out-of-lamp/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>A hot topic for anyone running MySQL and Apache on any machine is optimization and I hope to quickly explain how to optimize MySQL and where to tweak Apache to help with it&#8217;s operational efficiency as well.</p>
<h1>First things first &#8230;</h1>
<p>A few common things to possibly turn on, install, or enable:</p>
<ul>
<li>APC (Another PHP Cache)</li>
<li>Memcached</li>
</ul>
<h1>MySQL Optimization</h1>
<p>The easiest way (and the quickest) to determine what can be done to optimize MySQL is to use a script called mysqltuner.pl.  The really interesting thing about this script is that to get it you simply run the following:</p>
<p>wget mysqltuner.pl</p>
<p>After you&#8217;ve gotten this script run it with your perl interpreter:</p>
<p>perl mysqltuner.pl</p>
<p>It will prompt you for your username and password for mysql and then print out a nice report outlining how your mysql daemon has been running.  Here&#8217;s an example of this output:</p>
<p>&gt;&gt;  MySQLTuner 1.0.1 &#8211; Major Hayden<br />
&gt;&gt;  Bug reports, feature requests, and downloads at http://mysqltuner.com/<br />
&gt;&gt;  Run with &#8216;&#8211;help&#8217; for additional options and output filtering<br />
Please enter your MySQL administrative login: root<br />
Please enter your MySQL administrative password:</p>
<p>&#8212;&#8212;&#8211; General Statistics &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
[--] Skipped version check for MySQLTuner script<br />
[OK] Currently running supported MySQL version 5.0.90-log<br />
[OK] Operating on 32-bit architecture with less than 2GB RAM</p>
<p>&#8212;&#8212;&#8211; Storage Engine Statistics &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster<br />
[--] Data in MyISAM tables: 28M (Tables: 96)<br />
[--] Data in InnoDB tables: 1M (Tables: 55)<br />
[!!] Total fragmented tables: 2</p>
<p>&#8212;&#8212;&#8211; Performance Metrics &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
[--] Up for: 1h 39m 49s (24K q [4.163 qps], 354 conn, TX: 9M, RX: 34M)<br />
[--] Reads / Writes: 60% / 40%<br />
[--] Total buffers: 148.6M global + 960.0K per thread (100 max threads)<br />
[OK] Maximum possible memory usage: 242.3M (11% of installed RAM)<br />
[OK] Slow queries: 0% (0/24K)<br />
[OK] Highest usage of available connections: 28% (28/100)<br />
[OK] Key buffer size / total MyISAM indexes: 64.0K/6.3M<br />
[OK] Key buffer hit rate: 99.6% (164K cached / 682 reads)<br />
[OK] Query cache efficiency: 81.3% (14K cached / 17K selects)<br />
[OK] Query cache prunes per day: 0<br />
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 463 sorts)<br />
[!!] Joins performed without indexes: 42<br />
[OK] Temporary tables created on disk: 12% (54 on disk / 417 total)<br />
[OK] Thread cache hit rate: 70% (106 created / 354 connections)<br />
[!!] Table cache hit rate: 2% (48 open / 2K opened)<br />
[OK] Open file limit used: 9% (95/1K)<br />
[OK] Table locks acquired immediately: 98% (7K immediate / 7K locks)<br />
[!!] Connections aborted: 7%<br />
[OK] InnoDB data size / buffer pool: 1.0M/4.0M</p>
<p>&#8212;&#8212;&#8211; Recommendations &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
General recommendations:<br />
Run OPTIMIZE TABLE to defragment tables for better performance<br />
MySQL started within last 24 hours &#8211; recommendations may be inaccurate<br />
Adjust your join queries to always utilize indexes<br />
Increase table_cache gradually to avoid file descriptor limits<br />
Your applications are not closing MySQL connections properly<br />
Variables to adjust:<br />
join_buffer_size (&gt; 128.0K, or always use indexes with joins)<br />
table_cache (&gt; 48)</p>
<p>The first thing to notice is that mysql should be running for 24 to 48 hours before you trust the results of this script. The second thing to acknowledge is that it isn&#8217;t omniscient.  Understanding how these parameters affect your memory footprint and your runtime efficiency are what we&#8217;re most interested in though.</p>
<h1>Glossary of Parameters</h1>
<p>The best source of my.cnf parameters is of course the MySQL documentation, but I&#8217;ll clarify a few of the more pertinent items from the above output.</p>
<ul>
<li>Maximum Possible Memory &#8211; This is not the actual hard limit on your memory usage but a calculated theoretical maximum based on the parameters in your my.cnf and if this is over ~90% you may use your swap more than you want to.  After making any changes I suggest you check this to make sure you haven&#8217;t over-allocated yourself.</li>
<li>Highest Usage of Available Connections &#8211; This is the historical max connections used by mysql and if it&#8217;s at 100% this isn&#8217;t a guarantee that you need to increase max_connections but may just indicate that your connections spiked once.  That being said I recommend following its advice if you have the memory for it.</li>
<li>Query Cache Efficiency &#8211; The hit rate for the cache on your queries (I hope you have enabled).  As with any hash table if you&#8217;re not hitting what&#8217;s in the top bucket you need to increase the number of buckets.</li>
<li>Temporary Tables Created on Disk &#8211; This can be a finicky parameter to get right and is the first place I would recommend cutting if you don&#8217;t have the memory to run mysql like you would want, but if you do have the memory then up this as far as you can within reason.</li>
<li>Thread Cache Hit Rate &#8211; Just like any other cache.</li>
<li>Table Cache Hit Rate &#8211; Just like any other cache.</li>
</ul>
<h1>Fragmented Tables</h1>
<p>If you noticed the fragmented tables along with the recommendation to run OPTIMIZE TABLE that&#8217;s not something that will typically slow mysql down noticeably with today&#8217;s disks, but if you want to defragment them I recommend reading <a href="http://www.dufault.info/blog/a-script-to-optimize-fragmented-tables-in-mysql/">this article on the topic</a>.</p>
<h1>Apache Tweaking</h1>
<p>The following parameters are usually in httpd.conf unless you run a distribution that organizes apache in an easier to work with manner (my preference of course is Gentoo which stores these parameters in: 00_mpm.conf).</p>
<p>The parameters for tweaking apache&#8217;s processes depend on which worker module you have in use.  The following is the pertinent sections from my configuration:</p>
<p>#prefork MPM<br />
# This is the default MPM if USE=-threads<br />
#<br />
# MinSpareServers: Minimum number of idle child server processes<br />
# MaxSpareServers: Maximum number of idle child server processes</p>
<p>StartServers            5<br />
MinSpareServers         5<br />
MaxSpareServers         10<br />
MaxClients                      50<br />
MaxRequestsPerChild     500</p>
<p># worker MPM<br />
# This is the default MPM if USE=threads<br />
#<br />
# MinSpareThreads: Minimum number of idle threads available to handle request spikes<br />
# MaxSpareThreads: Maximum number of idle threads<br />
# ThreadsPerChild: Number of threads created by each child process</p>
<p>StartServers            2<br />
MinSpareThreads         15<br />
MaxSpareThreads         50<br />
ThreadsPerChild         25<br />
MaxClients                      150<br />
MaxRequestsPerChild     1000</p>
<p>These parameters are pretty self explanatory but just for completeness&#8217; sake I&#8217;ll do a small recap on these here:</p>
<p>* StartServers &#8211; The number of servers to have running and handling connections at first launch.<br />
* MinSpareServers &#8211; The minimum number of servers to have running not currently handling connections.<br />
* MaxSpareServers &#8211; The maximum number of servers to have running not currently handling connections.<br />
* MaxClients &#8211; The maximum number of clients that can simultaneously connect to Apache.<br />
* MaxRequestsPerChild &#8211; The maximum number of requests that a child will respond to before terminating.</p>
<p>Using these parameters we can control the amount of memory that Apache will consume at the cost of other things we may want to have like lots of connections or many sequential requests.</p>
<h1>Conclusion</h1>
<p>There are a lot of different things that can be done for a server that seems to be performing less than ideally and I&#8217;ve only covered a fraction of things that can happen.  As always with this topic the situation will change based on your needs and how your server runs, but at least now you may have a starting point for what to modify after you&#8217;ve troubleshooted every other thing that could go wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/05/23/optimizing-the-am-out-of-lamp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Optimizing Gentoo CFLAGS</title>
		<link>http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/</link>
		<comments>http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 06:39:52 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cflags]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[isa]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=63</guid>
		<description><![CDATA[Starting Off Make sure you&#8217;ve at least looked at the following document: Gentoo Optimization Guide. Checking Flags The only real change we want to make to our system are simple things we know will not break it. Thus, we only look at making sure that we have the correct flags for enabling all of the <a href='http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1><strong>Starting Off</strong></h1>
<p>Make sure you&#8217;ve at least looked at the following document: <a href="http://www.gentoo.org/doc/en/gcc-optimization.xml">Gentoo Optimization Guide</a>.</p>
<h1><strong>Checking Flags</strong></h1>
<p>The only real change we want to make to our system are simple things we know will not break it.  Thus, we only look at making sure that we have the correct flags for enabling all of the instruction sets that our processor has available.</p>
<h1><strong>Checking Processor</strong></h1>
<p>grep flags /proc/cpuinfo | grep uniq</p>
<p>This pulls out all of the features of the processor as detected by the kernel.  Example output is shown (line breaks added for readability):</p>
<p>alunduil@elijah ~ $ grep flags /proc/cpuinfo | uniq<br />
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr<br />
pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall<br />
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good<br />
extd_apicid pni cx16 lahf_lm cmp_legacy svm extapic<br />
cr8_legacy 3dnowprefetch</p>
<h1><strong>Checking Default Flags</strong></h1>
<p>gcc does a great job of determining what flags should be set by using the new -march=native flag (which you should have set by this point).  Using the following command we can double check that all of the instructions we want enabled are enabled:</p>
<p>gcc -Q -c -v -march=native &#8211;help=target | grep disabled</p>
<p>If anything appears in the resulting list, it&#8217;s not enabled and should be enabled by adding the appropriate -m flag.  For my cpu this results in: -msse3 -m3dnow.</p>
<h1><strong>Putting it Together</strong></h1>
<p>By adding the original guide with a check for instructions, we allow gcc to utilize the instructions that were specifically created for uses we may have (multimedia, extended math, etc).</p>
<p>The resulting CFLAG variable that I placed in my make.conf from the above discussion:</p>
<p>CFLAGS=&#8221;-march=native -O2 -pipe -msse3 -m3dnow&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached (User agent is rejected)
Database Caching 4/22 queries in 0.022 seconds using memcached
Object Caching 549/593 objects using memcached

Served from: www.alunduil.com @ 2012-02-06 09:47:36 -->
