Web Server Performance Comparison

From DreamHost
Revision as of 11:21, 17 January 2012 by JHeckman (Talk | contribs)

Jump to: navigation, search

VPS

Overview

Over the years, myriads of web servers have been written.

Browsershare.png

Apache, being one of the oldest, is the most widely used today. However, it was implemented with a scaling mechanism that can be relatively inefficient in some ways. Some newer webservers have come out in the last few years that attempt to address some of the shortcomings of Apache.... the most prominent of which being Lighttpd and Nginx.

Note that all three of these web servers are supported and available pre-configured on DreamHost PS; regular Happy Hosting is all done on Apache, mainly because of its broader feature support.

In this article, we'll examine the relative performance of each webserver to see how they compare head-to-head. Keep in mind that this is not (currently) meant to be an exhaustive be-all end-all performance comparison. The hope is to simply give a relative performance comparison under common conditions.

Testing Method

  • The method used to test these webservers involved using ApacheBench (an HTTP server benchmarking tool).
  • In each test 25,000 requests are made for a 5k PNG file locally from a DreamHost PS to remove potentially variable network conditions from the equation.
  • Before each test the webserver in question was restarted to clear out any potential caching or other issues that may interfere with results.
  • Each test was run with different numbers of concurrent requests to gauge performance at different levels of usage. (Consider that it's very common for browsers to allow up to 6 concurrent connections per single user you have browsing a site.. therefor 10 users browsing your site at the same time would amount to approximately 60 concurrent connections.)

The commands that were used in this test followed this format:

ab -n 25000 -c 50 http://www.example.com/dreamhost_logo.png

where the -c flag increased with the concurrency level.

Memory Usage

This is important to measure, especially on a DreamHost PS where your memory usage has a hard cap and raising it costs you additional money! (Note that memory is in megabytes.)

Webserver memory graph.jpg

As you can see, both Lighttpd and Nginx come out as clear leaders in this test. In fact, the difference is SO dramatic it's almost a bit unbelievable. How can such a huge disparity exist?

It has to do with how Apache handles scaling with more incoming requests. To handle additional requests, it spawns new threads (i.e., processes). As more and more connections come in, more and more Apache processes are spawned to handle them. This causes memory usage to grow fairly quickly.

In comparison, you see that Nginx and Lighttpd both have fairly static memory usage. Lighttpd actually increases more over time (and purportedly has issues with memory leaking), whereas nginx stays fairly static across the board from start to finish.

Requests Per Second

This is essentially a measure of how fast the server can receive and serve requests at different levels of concurrency. The more requests they can handle per second, the more able the server is to handle large amounts of traffic. Here's how the servers compare in this arena:

Webserver requests graph.jpg

Nginx clearly dominates in the raw number of requests per second it can serve. At higher levels of concurrency, it can handle fewer requests per second, but still can serve double what Lighttpd does (which was already doing nearly 4x what Apache was able to do).

Remember, the results shown are good only for measuring relative (and not absolute) performance, as the tests were conducted locally on the server.

Caveat

Remember, Apache supports a larger toolbox of things it can do immediately and is probably the most compatible across all web software out there today... and most websites really don't get so many concurrent hits as to gain large performance/memory benefits from Lighttpd or nginx.

But hey, it never hurts (too much) to swap your web servers around and see what works best for you!