October 30, 2006

Optimising Web Sites With A Separate Static Content Server

Filed under: Projects — James Holden @ 1:03 pm

I’ve been playing around over the weekend with speeding up this website a little. It runs on a virtual server with not much RAM, so it’s important that I keep the number of Apache processes as low as possible.

I’ve installed lighttpd another IP to serve static content such as images and stylesheets. This means that I won’t have the overhead of Apache to serve up all the little bits of content that don’t require PHP.

Here’s a little list of what I did:

  • Installed a minimal lighttpd setup pointing to the same document root, but listening on a different IP address
  • Tweaked the get_theme_root_uri() function Wordpress wp-includes/functions.php file to rewrite the hostname in the theme URI.
  • Implemented logresolvemerge.pl in the AwStats config for the site to merge the log files.
  • Configured lighttpd to not serve any PHP pages, in case anyone tries to get them.

All this means that images and CSS will get served from lighttpd instead of Apache. It also means that browsers will be able to open more simultaneous connections to the site and load the page objects faster.

The next thing I’m considering is a PHP accelerator, but I’ve not used any before. Does anyone have any recommendations?

5 Comments »

  1. Hi James - was just looking here coz I seemed to remember you ran an online shop selling linux cds, but perhaps I was wrong. Anyway, I’m a big lighttpd fan but I wonder if you’ve considered using it to serve PHP as well, via fastcgi. I’m using that on a side project which needs to serve a fairly busy site on an otherwise underpowered Xen virtual machine (provided by www.unixshell.com). I’m on their lowest possible account and it performs really, really well with lighty and fastcgi.

    The author of lighttpd also makes a PHP acccelerator that I’m playing with - ‘xcache’ - http://trac.lighttpd.net/xcache/ . Looks very promising.

    You’re right of course about separating static and dynamic content on different IPs for improved throughput - did you see that article the other day on slashdot or somewhere like that, a google engineer posted some benchmarks.

    Anyway, take care…

    Matt Saunders

    Comment by Matt Saunders — November 9, 2006 @ 10:51 am

  2. Hi Matt,

    Yes, I did used to run a shop selling Linux CDs. I have indeed used lighttpd to serve PHP via fastcgi and it works very well.

    The mean reasons were to keep the number of hefty Apache processes down, while still maintaining the Apache’s flexibility and compatibility.

    PHP accelerators are something I’ve not yet played with, but xcache was on my list of ones to start with.

    I didn’t specifically make the changes based on the benchmarks by the Google chap, but I recall seeing it.

    Cheers!

    James

    Comment by James Holden — November 9, 2006 @ 3:17 pm

  3. Hi, Im unsure why you dont want to serve php via lighttpd? Im not syaing its a bad decision, just curious as to your reasoning. Lighttpd can serve php much faster than apache, when used with the fastcgi version of php

    Also if lighty is serving images, you can gain some extra performance by enabling HTTP KeepAlives, something you probably wouldnt want to do on a high traffic multipurpose apache server

    For php acceleration, I fully reccomend eaccelerator. Setup is a breeze and it has a web front end so you can see whats going on. It caches compiled versions of each php page, cutting down on cpu and disk access. Ive seen a performance boost of over 70% just by enabling it on my site

    Comment by Carpii — November 10, 2006 @ 7:45 pm

  4. Hi Carpii,

    I’ve used PHP/fastcgi with lighty before and it does indeed work well. I’d consider serving the PHP through lighty on this site too, but it would mean rewriting some rewriting rules, and various other bits of migration work.

    HTTP KeepAlives are a good idea though - I’ll enable them.

    As for PHP acceleration, it looks like I’ll be trying eacceslerator and xcache :-) Perhaps I’ll do some benchmarks :-)

    James

    Comment by James Holden — November 12, 2006 @ 9:28 am

  5. Thanks for such an interesting and thoughtful perspective

    Comment by Lillie — December 2, 2006 @ 7:55 pm

RSS feed for comments on this post.

Leave a comment