In late December I started looking at alternative web servers, having hit a point where I actually asked aloud (though to no one in particular) why I still use Apache for any http or php needs that may arise.
I sat down, installed nginx (nginx 0.6.33) from the EPEL (Extra Packages for Enterprise Linux) repositories and lighttpd (lighttpd 1.4.20) from the RPMforge repositories (both third party repositories worth writing about in detail at a later date). Apache was already installed (httpd 2.2.3), so a virtualhost was configured to serve data from the same docroot using all three servers, and PHP through fastcgi was configured for lighttpd and nginx1.
I then set up a stock WordPress 2.7 blog, some large images, some thumbnails, and created what amount to approximately a 20k index page with nothing cached. Using ApacheBench to fetch 1000 requests, 100 requests at a time, I came up with some simple numbers showing how long it took to return the same page for each web server.
While I openly admit that the benchmarks produced here are arbitrary and superficial, they do give some rough insight (10,000ft overview level insight) as to how much faster nginx and fastcgi are over apache 2.2 and mod_php. lighttpd also performed admirably, and with less hassle involved in set up than nginx, but I suspect that may just be previous familiarity with the configuration.
A table of numbers (soon to be a graph, when I feel like making it) and some thoughts as to what they mean and why we (the web hosting community) still use Apache religiously follows after the jump.
| Metric | Apache | ligHTTPD | nginx |
|---|---|---|---|
Time taken for testslower is better |
45.584 seconds | 24.199 seconds | 17.395 seconds |
Total transferredcompression was enabled |
21691000 bytes | 22059912 bytes | 21894000 bytes |
HTML transferredcompression was enabled |
21464000 bytes | 21833686 bytes | 21671000 bytes |
Mean Requests per secondhigher is better |
21.94 [#/sec] | 41.32 [#/sec] | 57.49 [#/sec] |
Mean Time per requestlower is better |
4558.396 [ms] | 2419.853 [ms] | 1739.542 [ms] |
Mean Time per requestlower is better |
45.584 [ms] | 24.199 [ms] | 17.395 [ms] |
Transfer ratehigher is better |
464.69 [Kbytes/sec] | 890.26 [Kbytes/sec] | 1229.11 [Kbytes/sec] |
So what does all this mean? Well, the gist of it is that nginx is really, really god damned fast. Embarrassingly fast. Note that I didn't say that Apache is slow. It's just not nearly as fast as nginx. However, that being said, nginx is also not nearly as extensible as Apache is. The lack of support for things that are taken for granted nowadays (.htaccess files come to mind) can be a sticking point for use in a shared hosting environment. lighttpd doesn't support most of those "expected" bells and whistles either, and an argument could be made for such things being a waste of cycles… But the bottom line is that such bells and whistles are expected to work in a shared hosting environment.
As for why the web hosting community at large drops Apache into place whenever we need an http server, I think it boils down to comfort and laziness. It's bundled with most linux distros by default, we know it because it's been around forever, and its behavior is predictable and familiar. It's become the Microsoft Office of http serving, for better or for worse, and it's not going anywhere any time soon. Even the 800lb gorilla behemoth that is Microsoft IIS has failed to dethrone Apache for sheer ubiquity. I think the performance or security conscious are always going to migrate towards something with better speed and less attack vectors, but the typical admin probably just won't care.
And me? For now I'm going to continue using Apache, while I work out if using nginx for any of the sites I host for people would be a problem. If I can get the rewrite rules taken care of, and work out simple site provisioning, I might well make the switch. nginx seems like a no-brainer on single site virtual servers, where resources are scarce, and Apache isn't getting any more svelte these days.
--
-
Credit where credit is due. I couldn't have started to work out the nginx fastcgi configuration without help from this post on redemption in a blog. ↩
No Comments