<?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>james young &#187; performance</title>
	<atom:link href="http://psyjinx.com/jyoung/category/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://psyjinx.com/jyoung</link>
	<description>web application developer</description>
	<lastBuildDate>Sun, 15 Aug 2010 14:31:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Apache Performance Tuning</title>
		<link>http://psyjinx.com/jyoung/2008/12/apache-performance-tuning/</link>
		<comments>http://psyjinx.com/jyoung/2008/12/apache-performance-tuning/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 21:09:45 +0000</pubDate>
		<dc:creator>James Young</dc:creator>
				<category><![CDATA[performance]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://psyjinx.com/wp/?p=28</guid>
		<description><![CDATA[<p>This is a variety of tips complied from various places listed below.  This is the notes that I took for myself while researching apache performance on several different machines.  Read more to see the rest.
</p>
Hardware

The single biggest hardware issue affecting webserver performance is RAM. A webserver should never ever have to swap, as [...]]]></description>
			<content:encoded><![CDATA[<p>This is a variety of tips complied from various places listed below.  This is the notes that I took for myself while researching apache performance on several different machines.  Read more to see the rest.<br />
<span id="more-28"></span></p>
<h2>Hardware</h2>
<ul>
<li>The single biggest hardware issue affecting webserver performance is RAM. A webserver should never ever have to swap, as swapping increases the latency of each request. You can control this by modifying the <code>MaxClients</code> setting in the apache conf file.</li>
<li>A simple calculation for MaxClients on a system that does only Drupal would be:
<ul>
<li>(Total Memory &#8211; Operating System Memory &#8211; MySQL memory) / Size Per Apache process.</li>
</ul>
</li>
<li>If your server is configured with all sorts of bells and whistles (like mod_perl, mod_python, in addition to mod_php), then Apache can easily be 21 MB per process. If your server has 512MB, then you can fit some 20 Apache processes. If you tune Apache well, and remove all the unneeded modules, and install a PHP op-code cache/accelerator, then you can make each Apache process take as little as 12 MB. These figures depend on how many modules you have loaded, how big they are, so there is no hard and fast rule. Even if one has 1GB of memory, and leaves 250 MB for the system and MySQL, with an Apache process of 15MB, this means 50 Apache processes can fit in the remaining 750MB.</li>
</ul>
<table border="0">
<tbody>
<tr>
<th> server type</th>
<th> hostname</th>
<th> processor</th>
<th> hardware</th>
<th> ram</th>
<th> apache process size</th>
</tr>
<tr>
<td>MAMP</td>
<td>piro</td>
<td>1.33Ghz PPC G4</td>
<td>Mac Mini</td>
<td>512mb</td>
<td>31mb</td>
</tr>
<tr>
<td>MAMP</td>
<td>yellow</td>
<td>1.83Ghz Intel Core 2 Duo</td>
<td>Mac Mini</td>
<td>1gb</td>
<td>12mb</td>
</tr>
<tr>
<td>10.5.4</td>
<td>kimiko</td>
<td>1.83Ghz Intel Core 2 Duo</td>
<td>Mac Mini</td>
<td>1gb</td>
<td>12mb</td>
</tr>
<tr>
<td>10.5.6</td>
<td>miho</td>
<td>2.4Ghz Intel Core 2 Duo</td>
<td>MacBook Pro</td>
<td>2gb</td>
<td>540k</td>
</tr>
</tbody>
</table>
<h2>Operating System / Software</h2>
<ul>
<li>Use Apache 2.x (MAMP installs this)</li>
<li>If your OS supports a sendfile(2) system call, make sure you install the release and/or patches needed to enable it. On systems where it is available, sendfile enables Apache 2 to deliver static content faster and with lower CPU utilization.
<ul>
<li>From what I can tell this supposedly shipped on 10.5.x, but I am not sure how to confirm this or verify it is working, we can test performance with this by turning on/off sendfile via <code>EnableSendfile</code></li>
</ul>
</li>
</ul>
<h2><span>Apache Settings</span></h2>
<h3><span>MaxClients</span></h3>
<ul>
<li>You can, and should, control the <code>MaxClients</code> setting so that your server does not spawn so many children it starts swapping.</li>
<li>determine the size of your average Apache process, by looking at <code>RSHRD</code> in <code>top</code>, and divide this into your total available memory, leaving some room for other processes.</li>
</ul>
<h3><span>HostnameLookups</span></h3>
<ul>
<li>Make sure this is <code>Off</code></li>
<li>This adds latency to every request because it requires a DNS lookup to complete before the request is finished. In Apache 1.3 this setting defaults to <code>Off</code>. If you need to have addresses in your log files resolved to hostnames, use the <code>logresolve</code> program that comes with Apache, or one of the numerous log reporting packages which are available.</li>
<li>Note that it&#8217;s possible to scope the directives, such as within a <code>&lt;Location /server-status&gt;</code> section. In this case the DNS lookups are only performed on requests matching the criteria. Here&#8217;s an example which disables lookups except for .html and .cgi files:</li>
</ul>
<blockquote>
<pre>HostnameLookups off
&lt;Files ~ "\.(html|cgi)$"&gt;
HostnameLookups on
&lt;/Files&gt;</pre>
</blockquote>
<h3><span>FollowSymLinks / SymLinksIfOwnerMatch</span></h3>
<ul>
<li>Wherever in your URL-space you do not have an <code>Options FollowSymLinks</code>, or you do have an <code>Options SymLinksIfOwnerMatch</code> Apache will have to issue extra system calls to check up on symlinks.</li>
<li>For highest performance, and no symlink protection, set <code>FollowSymLinks</code> everywhere, and never set <code>SymLinksIfOwnerMatch</code>.</li>
</ul>
<h3><span>AllowOverride</span></h3>
<ul>
<li>Wherever in your URL-space you allow overrides (typically .htaccess files) Apache will attempt to open .htaccess for each filename component.</li>
<li>For highest performance use <code>AllowOverride None</code> everywhere in your filesystem.</li>
</ul>
<h3><span>EnableSendfile</span></h3>
<ul>
<li>If this is available on the system it should be on, otherwise set <code>EnableSendfile off</code></li>
<li>All Mac OS X boxes that are not 10.5.x should have this off</li>
</ul>
<h2><span>Apache Modules</span></h2>
<ul>
<li>Since memory usage is such an important consideration in performance, you should attempt to eliminate modules that you are not actually using. If you have built the modules as DSOs, eliminating modules is a simple matter of commenting out the associated LoadModule directive for that module. This allows you to experiment with removing modules, and seeing if your site still functions in their absense.</li>
<li>If, on the other hand, you have modules statically linked into your Apache binary, you will need to recompile Apache in order to remove unwanted modules.</li>
<li>An associated question that arises here is, of course, what modules you need, and which ones you don&#8217;t. The answer here will, of course, vary from one web site to another. However, the minimal list of modules which you can get by with tends to include mod_mime, mod_dir, and mod_log_config.</li>
</ul>
<h2><span>Multi-Processing Modules (MPM)</span></h2>
<ul>
<li>There are two MPMs to choose from in Apache 2.x
<ul>
<li>The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.</li>
<li>The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork&#8217;s threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.</li>
</ul>
</li>
</ul>
<ul>
<li>There are a couple of ways to tell what MPM your apache server was compiled with.
<ul>
<li>In the phpinfo configure block there should be a -with-mpm= that tells.</li>
<li>from the command line do <code>$ httpd -l</code> (thats a lower case L)</li>
</ul>
</li>
<li>MAMP installs prefork</li>
</ul>
<h2><span>Need more info on / Questions</span></h2>
<ul>
<li>MinSpareServers, MaxSpareServers, StartServers, MaxRequestsPerChild, and KeepAliveTimeout</li>
<li>How can we determine if sendfile is working or not?</li>
</ul>
<h2><span>References</span></h2>
<ul>
<li> <a title="http://httpd.apache.org/docs/2.0/misc/perf-tuning.html" rel="nofollow" href="http://httpd.apache.org/docs/2.0/misc/perf-tuning.html">http://httpd.apache.org/docs/2.0/misc/perf-tuning.html</a></li>
<li> <a title="http://www.devside.net/articles/apache-performance-tuning" rel="nofollow" href="http://www.devside.net/articles/apache-performance-tuning">http://www.devside.net/articles/apache-performance-tuning</a></li>
<li> <a title="http://2bits.com/articles/tuning-the-apache-maxclients-parameter.html" rel="nofollow" href="http://2bits.com/articles/tuning-the-apache-maxclients-parameter.html">http://2bits.com/articles/tuning-the-apache-maxclients-parameter.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://psyjinx.com/jyoung/2008/12/apache-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Performance</title>
		<link>http://psyjinx.com/jyoung/2008/08/php-performance/</link>
		<comments>http://psyjinx.com/jyoung/2008/08/php-performance/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 04:55:29 +0000</pubDate>
		<dc:creator>James Young</dc:creator>
				<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://psyjinx.com/wp/?p=46</guid>
		<description><![CDATA[<p>I have some more PHP Performance notes somewhere, but this is all that I can find right now.</p>

Use for loops over foreach loops
Use &#8216; over &#8220;, unless you are parsing variables
Use echo over print

<p>For Loops
Use either of the following syntax for your for loops. They take about the same amount of time to execute</p>

$count = [...]]]></description>
			<content:encoded><![CDATA[<p>I have some more PHP Performance notes somewhere, but this is all that I can find right now.</p>
<ul>
<li>Use for loops over foreach loops</li>
<li>Use &#8216; over &#8220;, unless you are parsing variables</li>
<li>Use echo over print</li>
</ul>
<p><strong>For Loops</strong><br />
Use either of the following syntax for your for loops. They take about the same amount of time to execute</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>DO NOT use the following, it is significantly slower:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://psyjinx.com/jyoung/2008/08/php-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
