This is a quick benchmark of the 3 major *nix web servers, to see which gives the best performance.
Test system
Hardware: vps247 cloud VPS node, 512Mb ram.
Software: Ubuntu 10.10 RC (kernel 2.6.35-22), Apache 2.2.16 (mod_php), Nginx 0.7.67 (php-fpm), Lighttpd 1.4.26 (php-cgi), PHP 5.3.3 with Xcache.
Site: LiteMVC 0.1 Hello World.
Test process
Using ab with 10,000 requests, 10 concurrent requests.
Monitoring load/memory usage with htop.
All web servers with default configuration, 1 site enabled.
All tests were repeated 3 times.
Apache 2.2.16
Test 1 | Test 2 | Test 3 |
---|---|---|
Load at start: 0.03 Memory usage at start: 130 Mb Load average max: 15.88 Memory usage max: 290 Mb Requests per second: 400.04 Time per request: 2.5 ms Longest request: 806 ms | Load at start: 0.07 Memory usage at start: 130 Mb Load average max: 21.73 Memory usage max: 332 Mb Requests per second: 395.49 Time per request: 2.529 ms Longest request: 728 ms | Load at start: 0.06 Memory usage at start: 121 Mb Load average max: 20.95 Memory usage max: 253 Mb Requests per second: 385.82 Time per request: 2.592 ms Longest request: 937 ms |
Nginx 0.7.67
Test 1 | Test 2 | Test 3 |
---|---|---|
Load at start: 0.05 Memory usage at start: 129 Mb Load average max: 0.77 Memory usage max: 157 Mb Requests per second: 413.40 Time per request: 2.419 ms Longest request: 239 ms | Load at start: 0.05 Memory usage at start: 152 Mb Load average max: 0.93 Memory usage max: 169 Mb Requests per second: 409.15 Time per request: 2.444 ms Longest request: 232 ms | Load at start: 0.00 Memory usage at start: 163 Mb Load average max: 0.61 Memory usage max: 169 Mb Requests per second: 415.28 Time per request: 2.408 ms Longest request: 250 ms |
Lighttpd 1.4.26
Test 1 | Test 2 | Test 3 |
---|---|---|
Load at start: 0.00 Memory usage at start: 115 Mb Load average max: 0.81 Memory usage max: 139 Mb Requests per second: 427.92 Time per request: 2.337 ms Longest request: 120 ms | Load at start: 0.09 Memory usage at start: 136 Mb Load average max: 0.73 Memory usage max: 143 Mb Requests per second: 447.10 Time per request: 2.237 ms Longest request: 111 ms | Load at start: 0.03 Memory usage at start: 140 Mb Load average max: 0.69 Memory usage max: 159 Mb Requests per second: 454.13 Time per request: 2.202 ms Longest request: 178 ms |
Conclusions
Lighttpd was the fastest overall in this test, however what probably stands out the most is the inefficiency of Apache with both server load and memory usage increasing considerably during the test. The reason for this may be down to Apache spawning additional processes when it is receiving a large volume of requests, which results in the higher memory usage. The memory usage with Nginx and Lighttpd increases by a much smaller amount because each of them runs a fixed number of PHP CGI processes (20 in this case).
Apache is definitely the winner in terms of module support and ease of configuration, but I may have a somewhat biased view as I've worked with Apache for years. Nginx is probably the hardest to setup and configure, however after switching from PHP-CGI to PHP-FPM this made things easier and it does seam there are more configuration examples floating around on the net than for Lighttpd. Lighttpd is notorious for memory leaks, I'm not sure if this is still an issue with current versions.