How the tests were performed:
I wanted to simulate a VPS environment similar to a basic Linode. A base install of Ubuntu Server 10.04 was installed in VMWare with an older/slower 7200RPM sata drive for storage. This drive was not in use by any other system during the test, nor were any other VMs active on the host. The guest was given 512MB of RAM and 1 CPU core of the host's 8 cores. The host's CPUs are dual Xeon X5365 @ 3Ghz.
Apache 2.2 was installed along with nginx 0.7.65, later Apache 2.4 was compiled on this same system.
Testing was performed using Apache JMeter on an 8 core Xeon workstation running Windows 7 and 32GB of RAM with a 1Gb/s link to the VMWare host. Requests per second were determined by rounding off the throughput displayed in the Summary Report listener. Each test was run until the requests per second stabilized.
The Apache 2.2 server was only tested with the Prefork MPM, while the Apache 2.4 server was tested with both Prefork and Event. Apache's KeepAlive setting was on throughout the testing and set at 2 seconds.
Update:
I received several requests to post memory usage statistics so I've updated the Jquery test with memory results. Again, care was not taken to keep the Apache builds consistent. It concerns me that the Prefork build of Apache 2.4 was using so much memory compared to the other Apache builds. Take these results with a grain of salt, but trust that Nginx definitely uses significantly less memory than Apache.
Update 2 - Nginx 1.0.12:
I received some flak for using an older version of Nginx, so I tested with Nginx 1.0.12 and it was around 4% slower than the results shown here.
Test 1 - 21KB text file
HTTP Server | Req/s |
---|---|
Apache 2.2 Prefork | 2220 |
Apache 2.4 Prefork | 2250 |
Apache 2.4 Event | 2300 |
Nginx | 2600 |
Test 2 - 2B text file consisting of a single period.
HTTP Server | Req/s |
---|---|
Apache 2.2 Prefork | 4400 |
Apache 2.4 Prefork | 4700 |
Apache 2.4 Event | 4810 |
Nginx | 6650 |
Test 3 - jquery.min.js (92KB)
HTTP Server | Req/s | Memory Usage |
---|---|---|
Apache 2.2 Prefork | 650 | 12MB |
Apache 2.4 Prefork | 770 | 72MB |
Apache 2.4 Event | 820 | 20MB |
Nginx | 1000 | 2MB |
Test 4 - PHP output of phpinfo()
HTTP Server | Req/s |
---|---|
Apache 2.2 Prefork | 525 |
Apache 2.4 Prefork | 575 |
Nginx FastCGI | 450 |