{
    "href": "/post/2008/09/04/rasmus-lerdorfs-laconica-performance/",
    "relId": "2008/09/04/rasmus-lerdorfs-laconica-performance",
    "title": "Rasmus Lerdorf's Laconic(a) Performance",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/benchmarks/",
            "relId": "benchmarks",
            "title": "Benchmarks",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2008-09-04 16:44:38 UTC",
    "updated": [
        "2008-09-04 16:44:38 UTC"
    ],
    "html": "<p>As many of you know, I maintain a series of web framework benchmarks. The project codebase is <a href=\"http://code.google.com/p/web-framework-benchmarks/\">here</a> and the most recent report is <a href=\"http://paul-m-jones.com/?p=315\">here</a>.</p>\n<p>It was with some interest, then, that I viewed Rasmus Lerdorf's <a href=\"http://talks.php.net/show/froscon08\">slides</a> on the subject of performance benchmarking.  I'm beginning to think there's something unexpected or unexamined in his testing methodology.</p>\n<p><!--more--></p>\n<p><em>Note: see the update at the end of this entry.</em></p>\n<p>On <a href=\"http://talks.php.net/show/froscon08/24\">this slide</a>, Rasmus notes the following:</p>\n<ul>\n<li>Static HTML nets 611.78 trans/sec</li>\n<li>Trivial PHP nets 606.77 trans/sec</li>\n</ul>\n<p>This would seem to indicate that the mere invocation of PHP, on Rasmus' setup, reduces Apache's performance from serving static pages by less than 1%.</p>\n<p>In my testing on Amazon EC2 small instances, I note somewhat different results:</p>\n<ul>\n<li>Static HTML nets 2309.14 req/sec</li>\n<li>Trivial PHP nets 1320.47 req/sec</li>\n</ul>\n<p>The net reduction there is about 43%.  Yes, this is with opcode caching turned on.</p>\n<p>I then became really curious as to how Rasmus might have his system set up, to see only a 1% bit of \"added overhead\" from PHP being invoked.  It would be nice if I could set up my own systems the same way.</p>\n<p>When I asked about that <a href=\"http://omniti.com\">at work</a>, my colleague <a href=\"http://elizabethmariesmith.com/\">Elizabeth Smith</a> opined that maybe Rasmus' web server is running <em>all</em> requests through the PHP interpreter, not just PHP files.  That sounded like a good intuition to me, so I set up an EC2 instance to try it out.</p>\n<p>Per the setup instructions on <a href=\"http://code.google.com/p/web-framework-benchmarks/wiki/ServerSetup\">this page</a> I built an EC2 server the same as I've done for my own benchmarking reports.  I didn't check out the whole project, though; this time we just need the \"bench\", \"baseline-html\", and \"baseline-php\" directories.</p>\n<p>As a reminder, the baseline index.html page is just the following plain text ...</p>\n<pre><code>Hello World!\n</code></pre>\n<p>... and the baseline index.php page is the following single line of PHP code:</p>\n<pre><code>&lt;?php echo 'Hello World!'; ?&gt;\n</code></pre>\n<p>The php5.conf file for Apache looks like this by default ...</p>\n<pre><code>&lt;IfModule mod_php5.c&gt;\n  AddType application/x-httpd-php .php .phtml .php3\n  AddType application/x-httpd-php-source .phps\n&lt;/IfModule&gt;\n</code></pre>\n<p>... and we're going to leave it alone for a bit.</p>\n<p>Using <code>ab -c 10 -t 60</code> to benchmark baseline-html and baseline-php with the default php5.conf gives us these results (an average over 5 runs each):</p>\n<pre><code>               |      avg\n-------------- | --------\nbaseline-html  |  2367.02\nbaseline-php   |  1270.15\n</code></pre>\n<p>That's a 47% drop for invoking PHP.  (That is itself 4 points different than the numbers I show above, so it appears there are some variables I have not controlled for, or maybe I just need to let this run longer than 5 minutes to smooth out the deviations.)</p>\n<p>To test our hypothesis, we modify the php5.conf file to add .html to the list of files that get passed through PHP ...</p>\n<pre><code>&lt;IfModule mod_php5.c&gt;\n  AddType application/x-httpd-php .html .php .phtml .php3\n  AddType application/x-httpd-php-source .phps\n&lt;/IfModule&gt;\n</code></pre>\n<p>... restart Apache, and run the same <code>ab</code> tests again:</p>\n<pre><code>framework      |      avg\n-------------- | --------\nbaseline-html  |  1348.80\nbaseline-php   |  1341.31\n</code></pre>\n<p>That's less than a 1% drop -- close enough to make make me think that Rasmus might be pushing everything through the PHP interpreter, regardless of whether or not it's a PHP file.</p>\n<p>If that is true (and it's a big \"if\"), then merely invoking PHP <strong>does</strong> appear to cause about a 45% drop (give or take) in Apache's responsiveness, which is contrary to the point Rasmus makes on <a href=\"http://talks.php.net/show/froscon08/7\">this slide</a> about PHP \"rarely\" being a bottleneck  -- and I say that as someone who works with PHP almost exclusively.  In fairness, I am depending only on the text of his slides here, so he may have said something to that effect in the presentation itself. </p>\n<p>Failure modes on this analysis:</p>\n<ul>\n<li>\n<p>I am using XCache and not APC for the opcode cache.  (Why? Because it works with both Lighttpd+FCGI and Apache+modphp, at least the last time I checked, and I'm interested in the differences between those two setups.)</p>\n</li>\n<li>\n<p>I am using an EC2 server, which is more production-ish than Rasmus' laptop. </p>\n</li>\n<li>\n<p>I am using <code>ab</code> to benchmark with, not <code>siege</code>.  I tried using Siege and did not notice any significant differences, so I'm sticking with the <code>ab</code> tools I've built for now.</p>\n</li>\n</ul>\n<p>I can't imagine those three differences would lead to the kind of disparity in performance that I'm seeing, but it's possible.</p>\n<p>Has anyone else tried doing this?</p>\n<p>Rasmus, if you have the time and inclination, would you care to shed some light on these prognostications?</p>\n<h3>Update: Is It EC2?</h3>\n<p>Rasmus replies below that he did not, in fact, have PHP running for all .html files.</p>\n<p>For me, the next question was to see what the real difference on EC2 is between no cache, XCache, and APC.</p>\n<p>No cache:</p>\n<pre><code>\n               |      avg\n-------------- | --------\nbaseline-html  |  2339.25\nbaseline-php   |  1197.28\n</code></pre>\n<p>XCache (copied from above)</p>\n<pre><code>\n               |      avg\n-------------- | --------\nbaseline-html  |  2367.02\nbaseline-php   |  1270.15\n</code></pre>\n<p>APC:</p>\n<pre><code>\n               |      avg\n-------------- | --------\nbaseline-html  |  2315.83\nbaseline-php   |  1433.91\n</code></pre>\n<p>So on EC2, you get about 1200 req/sec without caching, about 1300 req/sec with XCache, and about 1400 req/sec with APC, in the \"hello world\" baseline scenarios.</p>\n<p>Maybe this is all an artifact of how EC2 works, then?  I have no idea.  Next step is to test on non EC2 systems, if I can find one that others can reasonably build on themselves (since one of the goals here is for others to be able to duplicate the results).</p>\n"
}
