An Easy Way to Improve Your Website's Performance: Xcache
The Opcode Cache "Xcache" Can Quickly and Significantly Improve Your Drupal Site's Load Time
It’s always important to consider how you can optimize your website for maximum performance. Andrew King, author of Website Optimization, cites a study that shows “tests at Amazon revealed…every 100 ms increase in load time of Amazon.com decreased sales by 1%.” The study also links slowness with “lower perceived credibility and quality,” which is certainly important whether you’re selling goods or organizing a team of people.
While performance optimization is a multi-step process, one tool that can get you a lot of additional performance with little effort is a PHP opcode cache. Instead of parsing and compiling PHP code into bytecode on every page load, an opcode cache saves a copy of the bytecode so that the next time the same request is made and the code has not changed, it will not get re-parsed and recompiled but rather be read directly from the cache on the server.
There are several opcode caches available. You can read about several of them here. Another great resource is Drupal.org, where a search turns up many posts on people’s experiences with particular opcode caches. We are using Xcache. To give you an idea of the effect this has on a Drupal site, we did a quick comparison of a Drupal site without Xcache, and then a Drupal site with Xcache enabled. While the tests run are certainly not extensive, the limited results are telling.
Testing parameters
- Four calls to Apache AB were run, like: ~$ ab -c1 -n500 http://example.com (which is 500 requests with no concurrency)
- A set of two calls (with and without Xcache) to AB was run from a separate server, over the internet but from same data center
- A set of two calls to AB was run on a local development machine
- There was no traffic on either server besides the tests themselves
Results
The average page load times and standard deviation were as follows:
Location Without Xcache *With Xcache* On server 585ms/page load, 109.6ms standard deviation 333ms/page load, 75.1ms standard deviation On localhost 746ms/page load, 176.2ms standard deviation 427ms/page load, 76.2ms standard deviationAs you can see, even while keeping the standard deviation in mind, the Drupal site running Xcache is considerably faster than the site not running Xcache. Such is the case for the test run on the two development servers, as well as the test run on localhost. The greatest difference is noticeable in the overall time it took to run the two tests. For example, this is the test run on the servers:
- Without Xcache: 292.365 seconds
- With Xcache: 166.533 seconds
Conclusion
Our small test set shows that the site using Xcache loads over much faster than the site without Xcache. This is an improvement that not only your servers will feel, but also your site users will notice. While there are many things you can do to increase the performance of your website, starting with the data center where your website is hosted all the way to how you design your website, this is one easy way to improve your site’s performance, either as part of a greater plan or as a one-off change. The Xcache site has helpful installation documentation to get you started.
xcache is great
Xcache is great. I use it over on DrupalModules.com, and it makes a huge difference in performance. I haven’t seen any instability issues.
Memory reduction is key.
The biggest benefit by far is the reduction in memory usage for each PHP script. On Apache at least with prefork, each apache child will consume less memory you’ll be able to serve more requests as you can have more processes running.
A service to users and your hardware
It’s true, when you increase the performance of your website, not only can your users benefit, but it can also save infrastructure resources, and even money. Thanks for pointing this out, Oscar.
Ian
Comparing accelerators
Xcache is a decent option. I like that it has a Debian/Ubuntu package and hence the easiest to get installed on that distro.
However, it is not the only option out there, and can be unstable with certain PHP versions.
Here is an article benchmarking Drupal with different PHP op-code caches: APC, eAccelerator and Xcache compared.
Great article Khalid; It’s
Great article Khalid; It’s interesting to see the results side by side. I should mention we’re using Xcache with PHP 5.2.x, in some cases as a package, and others compiled from source. It’s working great so far.
Ian
Xcache in particular or any opcode cache for performance?
I’ve been using APC for a long time now, and I find it’s easier to install and more reliable than the others I had tried. Granted, I’ve not tried other opcode caches in a few years, and I never tried Xcache.
Does Xcache offer benefits over APC or other opcode caches?
I’ve also noticed that the memory consumption on each Drupal page request is significantly reduced when the opcode cache is used. I went from 40-50M per request to 4-8M!
Hi Benjamin, the author of
Hi Benjamin, the author of Xcache discusses why he wrote Xcache over here http://xcache.lighttpd.net/wiki/Introduction as well as a full feature list here http://xcache.lighttpd.net/wiki/FeatureList. Khalid’s article to which he links above does a nice side by side comparison of APC, Xcache, and eAccelerator in terms of performance gains. So far we’ve not experienced any stability issues with Xcache.
Ian