<?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>Vvvegard! &#187; apc</title>
	<atom:link href="http://www.vvvegard.net/blog/tag/apc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vvvegard.net/blog</link>
	<description>Learn me a book!</description>
	<lastBuildDate>Sun, 27 Feb 2011 03:11:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Benchmarking opcode php-cachers with Apache2 on Debian Lenny</title>
		<link>http://www.vvvegard.net/blog/benchmarking-opcode-php-cachers-with-apache2-on-debian-lenny/181/</link>
		<comments>http://www.vvvegard.net/blog/benchmarking-opcode-php-cachers-with-apache2-on-debian-lenny/181/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 04:20:35 +0000</pubDate>
		<dc:creator>Vegard Hansen</dc:creator>
				<category><![CDATA[Cache]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[eaccelerator]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[php5-memcache]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[xcache]]></category>

		<guid isPermaLink="false">http://www.vvvegard.net/blog/?p=181</guid>
		<description><![CDATA[In this article I will focus on how to squeeze (No, not the SID/testing release of Debian) the last drop of juice from your Apache2-installation with small measurements, focusing on PHP performance. And if you&#8217;re really serious you might want to look into my articles about Varnish as well! Welcome to the world of caching [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I will focus on how to squeeze (No, not the SID/testing release of Debian) the last drop of juice from your Apache2-installation with small measurements, focusing on PHP performance. And if you&#8217;re really serious you might want to look into my articles about <a href="http://www.vvvegard.net/blog/category/varnish/" target="_blank">Varnish</a> as well! Welcome to the world of caching dynamic data! Not really, just some parts of it&#8230;<span id="more-181"></span></p>
<p>All the benchmarks in this article is based on Apache Benchmarking (ab) tool, so the numbers <strong>will not</strong> translate directly to a production environment. This was all done locally on a virtually hosted Debian Lenny (5.0.4) on VMWare Fusion. You should see much higher numbers than this in a real world scenario. If not you should highly consider buying a new server. The virtual server was running on a single 2,4Ghz shared core, with 1024MB virtually allocated memory and 8GB virtual drive.</p>
<p>For the actual tests i make ab run a series of 1000 requests with 10 concurrent requests at a time. In order for it to be a fair fight I run all tests twice. The page that is requested is a Pressflow-installation with a story consisting of three paragraphs of random bits and bytes, in total the document is 6755 bytes (very small). Apache is set up to respond to rewrites too, as most servers are.</p>
<p>My main configuration consists of Apache2, php5, phpmyadmin and mysql-server. In a production environment you might not need packages such as phpmyadmin and mysql-server, this is just installed for testing purposes. For bleeding edge packages i suggest taking a look at <a href="http://www.dotdeb.org/" target="_blank">dotdeb</a>, but i cannot vouch for the stability of said repository.</p>
<blockquote>
<pre>apt-get install apache2 php5 phpmyadmin mysql-server</pre>
</blockquote>
<p style="text-align: left;">With this fairly plain and simple setup up and running it&#8217;s time to crack some numbers. What we are focusing on is average request time, requests per second and time per request. On a basic Apache2 setup with default configuration and MPN Worker we get these numbers. You find the whole output at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a>.</p>
<blockquote>
<pre>Apache2 Default Configuration
Time taken for tests:   97.409 seconds
Requests per second:    10.27 [#/sec] (mean)
Time per request:       974.094 [ms] (mean)</pre>
</blockquote>
<p>From this we can read that we get around 10 req/s. This is not bad &#8211; <em>considering the setup</em> &#8211; but you&#8217;d want to see a lot more if you are to survive a sudden traffic rush, keep in mind that most of a sites traffic hits within a short time. Also, it took a whopping 974ms (on average, 10 concurrent!) to load each page. That almost 1 second, and that&#8217;s not counting in other factors such as network latency and the rendering speed of your visitors browser. This is just to actually get the damn data!</p>
<p>Moving on we&#8217;re going to try out some of the most popular opcode cachers for PHP. First of is my personal favorite, as before of writing this article, APC &#8211; Alternative PHP Cache.</p>
<blockquote>
<pre>apt-get intall php-apc
apt-cache show php-apc</pre>
</blockquote>
<p>As the last command shows us we&#8217;ve installed &#8220;Version: 3.0.19-2&#8243; of php-apc. This is the latest version of APC in the repository as of writing this. APC is very minimalistic in it&#8217;s design and does not require a lot of configuration to get it working. But we add the following line in order to beef it up a bit, you might want to experiment with this, depending on how many sites you host or how heavy the scripts are. Numbers are in MB, duh.</p>
<blockquote>
<pre>echo "apc.shm_size = 128" &gt;&gt; /etc/php5/conf.d/apc.conf
apache2ctl restart</pre>
</blockquote>
<p>Now that we&#8217;ve got that settled we move on to the actual benchmarking. As with Apache2 default configuration you can access the full benchmark at<a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a>. You will also find a <a href="http://static.vvvegard.net/files/benchmarking/config" target="_blank">sample configuration</a> here.</p>
<blockquote>
<pre>APC Default Configuration
Time taken for tests:   26.041 seconds
Requests per second:    38.40 [#/sec] (mean)
Time per request:       260.414 [ms] (mean)</pre>
</blockquote>
<p>We see a great improvement in time taken, requests served per second and the time it took per request. As we can see it&#8217;s almost 4 times faster with little to none actual work done.</p>
<p>Moving on we&#8217;re going to test a bit more advanced opcode cacher, XCache. It&#8217;s actually a side project from the super snappy and lightweight web server lighttpd but since is&#8217;s made for PHP it works with Apache2 to.</p>
<blockquote>
<pre>apt-get install php5-xcache
apt-cache show php5-xcache</pre>
</blockquote>
<p>The latest stable release in the repository is &#8220;Version: 1.2.2-3&#8243;. Like with APC I  did little modifications to the configuration shipped with Debian. Please note that XCache is a lot more flexible and secure because of it&#8217;s design; but also more complex and easier to break.</p>
<blockquote>
<pre>nano /etc/php5/conf.d/xcache.ini
Edit xcache.size to 128M</pre>
</blockquote>
<p style="text-align: left;">Just as with the others you find the complete benchmark at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a> and configurations in <a href="http://static.vvvegard.net/files/benchmarking/config">http://static.vvvegard.net/files/benchmarking/config</a>.</p>
<blockquote>
<pre>XCache Default Configuration
Time taken for tests:   25.523 seconds
Requests per second:    39.18 [#/sec] (mean)
Time per request:       255.233 [ms] (mean)</pre>
</blockquote>
<p>As we can see it&#8217;s only slightly faster than APC with a pretty basic configuration, but you should be able to squeeze a little more juice out of it by tuning the configuration a little more. Not groundbreakingly much faster than APC, but I guess the added flexibility might make XCache a better choice than APC.</p>
<p>Moving further along we hit the first obstacle, eAccelerator. It&#8217;s not in Debian Lenny repository, so we have to compile it from source. This will probably make eAccelerator much more up to date and some of the difference shown might be because of this. There are also people who have made their <a href="http://kevin.deldycke.com/2009/08/how-to-install-eaccelerator-php5-debian-lenny/" target="_blank">own packages</a> of this, use at own risk!</p>
<p>First we need to install some essentials for building a package form source. I will not get into detail in how to install and configure eAccelerator but if you run into any problems be sure to drop a line. These commands should do the magic! Please note that due to restrictions, (that you can remove) the maximum allowed shared memory under Linux Kernel 2.6 is 32MB so we run it on 32MB. This should not show any effects during this test as it&#8217;s a small site and not that much to actually cache, in bytes.</p>
<blockquote>
<pre>apt-get install build-essential autoconf automake libtool m4 php5-dev
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
tar -xjvf eaccelerator-0.9.6.tar.bz2
phpize5
./configure
make; make install
cd /etc/php5/conf.d/
wget http://static.vvvegard.net/files/benchmark/config/eaccalerator.ini
mkdir /var/cache/eaccelerator
chmod 777 /var/cache/eaccelerator
apache2ctl restart</pre>
</blockquote>
<p>Like with XCache eAccelerator has a lot more flexible features than APC. There is a lot of tuning that can be done if you take your time. As with the rest you&#8217;ll find the complete benchmark at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a> and configurations at <a href="http://static.vvvegard.net/files/benchmarking/config">http://static.vvvegard.net/files/benchmarking/config</a>.</p>
<blockquote>
<pre>eAccelerator Default Configuration
Time taken for tests:   24.341 seconds
RRequests per second:    41.08 [#/sec] (mean)
Time per request:       243.408 [ms] (mean)</pre>
</blockquote>
<p style="text-align: left;">Here we see a marginal speed increase from both XCache and APC, but this might just be because if runs the latest available version of eAccelerator as of writing. You might also tweak eAccelerator a lot for more juice by visiting their <a href="http://eaccelerator.net/wiki/Settings" target="_blank">wiki</a> to get some good hint&#8217;s and tips. When it comes to security I guess eAccelerator is in for a beating, from my point of perspective you should not run this in a multi-user environment as users potentially can access and read each others PHP-files.</p>
<p style="text-align: left;">Moving yet again along we&#8217;re going to put php5-memcache up to the tests. Php5-memcache is a lot like APC with fewer possible configurations than XCache and eAccelerator. And like the others you find the complete benchmark at <a href="http://static.vvvegard.net/files/benchmarking/" target="_blank">http://static.vvvegard.net/files/benchmarking/</a> and configurations in <a href="http://static.vvvegard.net/files/benchmarking/config">http://static.vvvegard.net/files/benchmarking/config</a>. We&#8217;re using the default configuration shipped with Debian, no modifications.</p>
<blockquote>
<pre>apt-get install php5-memcache
apt-cache show php5-memcache</pre>
</blockquote>
<p>We&#8217;re getting &#8220;Version: 3.0.1-1&#8243; of php5-memcache. This seems to be quite new as far as I could see. And that makes what comes next even more depressing.</p>
<blockquote>
<pre>php5-memcache Default Configuration
Time taken for tests:   98.439 seconds
Requests per second:    10.16 [#/sec] (mean)
Time per request:       984.391 [ms] (mean)</pre>
</blockquote>
<p>Woha! It&#8217;s actually worse than native PHP. This might be because of the configuration, but my gut feeling tells me there is something more in the grass, the server load went trough the roof with php5-memcache.</p>
<p>To sum it all up, most OPCode cachers do a really good job in both speeding up you requests and makes your server scale a little more than it does without any caching capability. Running a cacher is highly recommended as it reduces hits on your disks and makes your server scale a lot better. The tests also showed that most cachers make the server peak 4x as much on requests per second, witch should do the trick if you experience slowdown during peak hour on your server. In a combination with Varnish and a fine tuned setup you should be able to get around 150-200 req/s on backend servers while serving 1500+ req/s from Varnish, with a 90% cache-hit rate.</p>
<p>Next time I&#8217;ll make some nice graphs with rrdtool too <img src='http://www.vvvegard.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.vvvegard.net/blog/benchmarking-opcode-php-cachers-with-apache2-on-debian-lenny/181/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
