Apache vs nginx vs lighttpd (And Cherokee!)

Status
Not open for further replies.

eLight

Active Member
3,487
2011
165
0
This thread was inspired by Lifetalk in the CB, sorry but I didn't set up Cherokee as I couldn't be bothered reading up as to how. But I'll include it next time! If you want to run some tests on your own machine that'd be cool for comparison (especially with hardware and stuff).

Server specs:
CPU: Xeon X3430 @ 2.40GHz
RAM: 8GB
HDD: 2x 1000GB in SW RAID 1.
BW: 100Mbps (Not that it matters...).

Server is CentOS 64bit, completely fresh format and the latest available kernel. Nothing has been ran on this server previously. There's no optimizations made server side, as this is to give a comparison of the http servers only. PHP 5.3.6 is used for all tests.

Apache is the "every mans" httpd. It is pretty good for hosting, very good at handling host names and what not, but it's kinda sucky for performance. That's not to say that it can't be configured well. But, to give a comparison to lighttpd and nginx, I've left Apache as is with a standard PHP CLI installation. Both nginx and lighttpd are very, very easy to install and configure with php-cgi. I've ran tests without any cache op as well as xCache and APC. Minimal configuration options are used besides the bare requirements for them to operate.

A concurrency of 10 is used for all tests, a total of 20,000 requests is made. Reading around the net you'll usually see recommendations such as "nginx for static" ... "lighttpd for php-cgi" for example, so, let's see if all these peoples thoughts are true :)

Static Files

WJ's logo.png

Apache:

Requests per second: 6309.83 [#/sec] (mean)
Time per request: 1.585 [ms] (mean)
Time per request: 0.158 [ms] (mean, across all concurrent requests)

lighttp:
Requests per second: 10981.46 [#/sec] (mean)
Time per request: 0.911 [ms] (mean)
Time per request: 0.091 [ms] (mean, across all concurrent requests)

nginx:
Requests per second: 11286.66 [#/sec] (mean)
Time per request: 0.886 [ms] (mean)
Time per request: 0.089 [ms] (mean, across all concurrent requests)

Winner: nginx

PHP file no xCache/APC

A PHP file with the following code is used. Nothing complex, just a simple piece of code that will out put "Hello!" 5 times.

PHP:
<?php
$arr = array(1, 2, 3, 4, 5);
foreach ($arr as $val) {
echo "Hello!";
}
exit;
?>
Apache:
Requests per second: 3495.35 [#/sec] (mean)
Time per request: 2.767 [ms] (mean)
Time per request: 0.277 [ms] (mean, across all concurrent requests)

nginx:
Requests per second: 3942.56 [#/sec] (mean)
Time per request: 2.536 [ms] (mean)
Time per request: 0.254 [ms] (mean, across all concurrent requests)

lighttpd:
Requests per second: 4091.25 [#/sec] (mean)
Time per request: 2.386 [ms] (mean)
Time per request: 0.239 [ms] (mean, across all concurrent requests)



Winner:
lighttpd

With xCache:

Please note Apache is skipped for this test.

nginx:
Requests per second: 4118.34 [#/sec] (mean)
Time per request: 2.428 [ms] (mean)
Time per request: 0.243 [ms] (mean, across all concurrent requests)

lighttpd:
Requests per second: 4596.48 [#/sec] (mean)
Time per request:
2.176 [ms] (mean)
Time per request:
0.218 [ms] (mean, across all concurrent requests)


With APC:

nginx:
Requests per second: 4075.07 [#/sec] (mean)
Time per request: 2.454 [ms] (mean)
Time per request: 0.245 [ms] (mean, across all concurrent requests)

lighttpd:
Requests per second: 4166.00 [#/sec] (mean)
Time per request: 2.400 [ms] (mean)
Time per request: 0.240 [ms] (mean, across all concurrent requests)


Winner: May as well be a tie. Except lighttpd does perform better with it's "native" xCache, which I guess can be expected considering it's made by the same people.

Take this as you may. I am unbiased between nginx or lighttpd. I've used both and they both have their pro's and con's. Overall I think nginx is a better performer for proxy setups and static files whilst PHP just takes the cake for PHP. I guess this simple test proves that in a way. But either way, if you set up your server correctly you won't notice much difference between them. I definitely recommend them over Apache.

Another thing to bear in mind is that these results may differ highly to your own server, this server is a completely stock standard machine and there's many things you can do to increase the performance!

Cherokee vs Apache vs lighttpd vs nginx (Static only).

Thanks to Lifetalk!

His vacant box:
CPU x3440 @ 2.53GHz
8GB Memory
2x1TB Drives in LVM (consider this equal to SW RAID 0)
BW: 1gbps, not that it matters.
Tested file: WJ logo

APACHE:
Requests per second: 10820.39 [#/sec] (mean)
Time per request: 0.924 [ms] (mean)
Time per request: 0.092 [ms] (mean, across all concurrent requests)

CHEROKEE:
Requests per second: 12190.83 [#/sec] (mean)
Time per request: 0.820 [ms] (mean)
Time per request: 0.082 [ms] (mean, across all concurrent requests)

NGINX:
Requests per second: 14842.53 [#/sec] (mean)
Time per request: 0.674 [ms] (mean)
Time per request: 0.067 [ms] (mean, across all concurrent requests)

LIGHTY:
Requests per second: 13922.32 [#/sec] (mean)
Time per request: 0.718 [ms] (mean)
Time per request: 0.072 [ms] (mean, across all concurrent requests)
 
35 comments
I would say and from my experience you can get great performance from Apache if you know how to tune it and understand the work of every directive .

most people set AllowOverrid directive to All in <Directory /> and that unfortunately decrease Apache webserver performance and increase Apache overhead searching for .htaccess files in every directory per request. (per request means its not cached imagine 1000 request per minute that will make Apache to look for .htaccess 1000 times in 1 minute).

the above is just 1 example of bad Directives using. it would give you a small idea of how big Apache is.

Apache is best web server in the world.
Nginx is great for reverse proxy and flv streaming solutions . (I use it personally)

Highest Regards
Mohammed H
 
At the end of the day, Apache still is inferior in terms of performance under a high load situation. Primarily because of the fact that it forks a new process to handle a new request that is not already handled by an otherwise child that's free. Compare that to the multi-threaded processes on nginx/lighty/cherokee.

I've, myself, had an exponential performance gain using Cherokee instead of Apache. Where Apache would stall for me after I had like 100,000 images hosted (and about a few thousand requests per minute), Cherokee's still going strong at over 600,000 images and there's still room for more.
 
Lifetalk have you ever used Apache MPM Worker, Event.

just to let you know Apache already have multithreaded MPM but none benchmark that I don't know why?? (I guess it's human nature though), I personally have used it, it will fork only 1 processor and that processor will handle all requests through threads.

Highest Regards
Mohammed H
 
I would say and from my experience you can get great performance from Apache if you know how to tune it and understand the work of every directive .

most people set AllowOverrid directive to All in <Directory /> and that unfortunately decrease Apache webserver performance and increase Apache overhead searching for .htaccess files in every directory per request. (per request means its not cached imagine 1000 request per minute that will make Apache to look for .htaccess 1000 times in 1 minute).

the above is just 1 example of bad Directives using. it would give you a small idea of how big Apache is.

Apache is best web server in the world.
Nginx is great for reverse proxy and flv streaming solutions . (I use it personally)

Highest Regards
Mohammed H

Bro Mohammed H, can you please create a thread with helpful tips to tweak apache , it will help lot of guys like me :)
 
My view with apache...there is no use flogging a dead horse.

I recently moved another one of my sites to the 'ol nginx and fpm combination and it runs far better than before. Plus now that php-fpm allows dynamic process spawning, its as good, if not better than apache.

At this point some of you are probably going to flame me about the difficulty of using nginx rewrite rules. Well, I have one answer for you: try_files. Problem solved.

Nginx ftw, apache for the bin!
 
+1 for nginx.

For lighttpd, I'd stay away from it. Lighttpd doesn't flush the cache, no matter how, all files will be kept in memory.
 
Hands down to nginx. I always try to use this on my servers when I can as I know for a fact it makes a big difference in the end.
 
Status
Not open for further replies.
Back
Top