Apache20、lighttpd、nginx的比较http://16hot.blog.isyi.com/post/1/641
Posted by 16hot under [ FreeBSD ]
[ (1) 评论 ] | [ (0) 引用 ]主机环境:
电脑: PC, CPU: AMD 1800+, MEM: 728M, DISK: IDE 7200RPM 2M, 160G
系统: FreeBSD 6.1-RELEASE-p11
软件:
   Apache-2.0.59
   Lighttpd-1.4.13-1
   nginx-0.5.5

测试机:
电脑: Latop IBM T20, P3-700, MEM: 256M
系统: FreeBSD 6.2-PRERELEASE
软件: WebBench 1.5

静态网页的比较:
index.html 是apache2 自带的 index.html.en 拷贝来的。

nginx(ports install):
mybsd# webbench -c 500 -2 http://192.168.8.249:82/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:82/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=429908 pages/min, 12360223 bytes/sec.
Requests: 214954 susceed, 0 failed.

lighttpd(ports install):
mybsd# webbench -c 500 -2 http://192.168.8.249:81/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:81/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=429182 pages/min, 12506485 bytes/sec.
Requests: 214591 susceed, 0 failed.

apache2+worker(ports install):
mybsd# webbench -c 500 -2 http://192.168.8.249:80/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:80/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=80118 pages/min, 2337701 bytes/sec.
Requests: 40059 susceed, 0 failed.

apache2+worker(ports install)
enable sendfile();
mybsd# webbench -c 500 -2 http://192.168.8.249:80/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:80/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=80728 pages/min, 2355835 bytes/sec.
Requests: 40364 susceed, 0 failed.

/opt/modules/apache2(手工安装):
mybsd# webbench -c 500 -2 http://192.168.8.249:83/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:83/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=95102 pages/min, 2774133 bytes/sec.
Requests: 47551 susceed, 0 failed.

/opt/modules/apache2 worker(手工安装):
mybsd# webbench -c 500 -2 http://192.168.8.249:83/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:83/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=79100 pages/min, 2307692 bytes/sec.
Requests: 39550 susceed, 0 failed.


/opt/modules/apache2p prefork(手工安装):
mybsd# webbench -c 500 -2 http://192.168.8.249:84/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:84/index.html (using HTTP/1.1)
500 clients, running 30 sec.

Speed=106000 pages/min, 3093523 bytes/sec.
Requests: 53000 susceed, 0 failed.


PHP支持比较
info.php:
<?php

phpinfo();

?>

/opt/modules/apache2 prefork(手工安装)

mybsd# webbench -c 500 -2 http://192.168.8.249:83/info.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:83/info.php (using HTTP/1.1)
500 clients, running 30 sec.

Speed=13628 pages/min, 9712975 bytes/sec.
Requests: 6814 susceed, 0 failed.


nginx(proxy)+apache2(/opt/modules/apache2(手工安装))
mybsd# webbench -c 500 -2 http://192.168.8.249:82/info.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:82/info.php (using HTTP/1.1)
500 clients, running 30 sec.

Speed=9954 pages/min, 7505740 bytes/sec.
Requests: 4977 susceed, 0 failed.


lighttpd(proxy)+apache2apache2(/opt/modules/apache2(手工安装))
mybsd# webbench -c 500 -2 http://192.168.8.249:81/info.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.8.249:81/info.php (using HTTP/1.1)
500 clients, running 30 sec.

Speed=10150 pages/min, 7732128 bytes/sec.
Requests: 5075 susceed, 0 failed.




另外lighttpd和nginx 在fastcgi的支持中,没有明显的差异,就没有将结果记录起来。
从上面的结果来看,在静态支持中,lighttpd和nginx 是比apache优胜很多很多的。
即使Apache2+worker,在支持PHP方面,还是不太让人满意。

另外从运行时对内存、CPU开销来看,最大是Apache,Lighttpd 和 Nginx 比较接近,但是Lighttpd相比Nginx更占资源一些。

因此,如果不考虑虚拟主机安全设置的问题,Nginx无疑是最好的选择,其次是Lighttpd。