Apache, Nginx性能比较, Nginx完胜

本文为yaozer原创, 文章比较长, 先放结论:  不管是用ab, 还是webbench进行并发测试, 10个并发用户访问时, apache与nginx差别不大,  但是随着并发量增加, 100个并发用户访问时, nginx优势巨大, 测试结果是apache的 6~8 倍.nginx 完胜!

使用软件ab, webbench进行测试Apache, Nginx性能, 测试页面为Magento 1.4.2.0的首页,环境如下:

测试环境:
IBM x3250 服务器 xeox 2.4G, 4G RAM, 250G RAID1
Centos 5.5, apache 2.2.17, mysql 5.1.52, nginx 0.9.3, php 5.2.16, magento1.4.2.0

webbench小巧简单, 测试结果如下:

—————————————-开始 webbench 测试 ———————————————————–

Apache Nginx Apache Nginx
webbench -c 10 -t 30 webbench -c 10 -t 30 webbench -c 100 -t 30 webbench -c 100 -t 30
10个并发用户访问30s 10个并发用户访问30s 100个并发用户访问30s 100个并发用户访问30s
速度 (页面/分钟) 1678 1618 1902 15432
速度 (字节/秒) 311045 299464 339006 1184762
成功请求个数 839 809 951 7716
失败请求个数 0 0 0 0
CPU占有率 90.30% 78.60% 99.90% 83.20%

webbench测试结论:
10个并发用户访问时, apache速度略优于nginx, 但是CPU占有率明显高于nginx;
100个并发用户访问时, nginx优势巨大,速度是apache的8倍左右, CPU占有率明显低于apache.

—————————————-开始 ab 测试 ———————————————————–

Apache Nginx Apache Nginx
ab -c 10 -n 1000 ab -c 10 -n 1000 ab -c 100 -n 1000 ab -c 100 -n 10000
文档长度(字节): 10684 10684 10684 3696
并发数: 10 10 100 100
测试运行时间(秒): 34.886 38.412 27.091 4.547
成功请求个数: 1000 1000 1000 1000
失败请求个数: 0 0 110 117
非2xx常规响应: 0 0 110 883
总传输字节: 11122000 11105000 10129032 4709431
HTML 传输直接: 10684000 10684000 9712262 4513596
平均每秒请求个数 28.66 26.03 36.91 219.91
每次请求平均时间 (ms毫秒): 348.861 384.12 2709.072 454.732
在某时间内(ms毫秒), 请求得到响应的比例
50.00% 318 326 2838 174
66.00% 373 423 3130 200
75.00% 412 461 3368 350
80.00% 430 477 3612 522
90.00% 478 523 4123 646
95.00% 523 565 4509 946
98.00% 599 683 5009 1590
99.00% 1016 787 5388 3150
100% (longest request) 1304 1233 5956 3578
CPU 88.80% 83.00% 99.90% 82.50

测试结论:
10个并发用户访问时, apache速度略优于nginx, 但是CPU占有率高于nginx;
100个并发用户访问时, nginx优势巨大,速度是apache的6倍左右,  CPU占有率明显低于apache.

—————————————-最终结论 ———————————————————–

最后结论, 不管是用ab, 还是webbench进行并发测试, 10个并发用户访问时, apache与nginx差别不大,  但是随着并发量增加, 100个并发用户访问时, nginx优势巨大, 测试结果是apache的 6~8 倍.

分享家:Addthis中国

ubuntu安装lamp的最简单方法

ubuntu 如何搭建 lamp ?那还不容易, apache2, php5, mysql-server 之类的装一下不就可以了吗? 但是有时候也会遇到一些问题, 比如ubuntu 9.04上面安装mysql-server5.1是有些问题的。
怎么安装最简单呢? 答案是这样的:

sudo apt-get install lamp-server^

别忘了最后面那个 ^ , 这条命令和一般命令不一样哦, 原理见此处:https://help.ubuntu.com/community/Tasksel

分享家:Addthis中国

本地域名解析–hosts文件

域名解析一般是通过2个地方设置的,一个是本地的hosts文件,另一个是指定的DNS服务器。在 /etc/nsswitch.conf 指定了两者的解析顺序, 一般是hosts优先, 当hosts找到时, 就停止查找,不会继续去DNS服务器查。这就是本地域名解析的基本知识。

关于hosts文件的相关内容, 见wikipedia : http://en.wikipedia.org/wiki/Hosts_file

The hosts file is a computer file used to store information on where to find a node on a computer network. This file maps hostnames to IP addresses. The hosts file is used as a supplement to (or a replacement of) the Domain Name System (DNS) on networks of varying sizes. Unlike DNS, the hosts file is under the control of the local computer’s administrator.bb

The hosts file has no extension and can be edited using most text editors.

Location and default content

The hosts file is located in different locations in different operating systems and versions.[1]

Operating System Version(s) Location
Windows 95, 98, Me %WinDir%\
Windows NT, 2000, XP, 2003, Vista, 7 %SystemRoot%\system32\drivers\etc\ by default. Actual location defined in Registry key \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath
Macintosh 9 and earlier System Folder: Preferences or System folder
Macintosh X /private/etc/hosts
Linux, BSD based, and similar /etc/hosts[2]
Novell NetWare SYS:etc\hosts
iPhone and iPod /private/etc/hosts
OS/2 and eComStation "bootdrive":\mptn\etc\
Symbian 1st and 2nd edition phones C:\system\data\hosts
Symbian 3rd edition phones C:\private\10000882\hosts (AllFiles capable only)
分享家:Addthis中国

大型网站在用什么web服务器?Apache, nginx, lighttpd?

Apache, nginx (发音 engine x), lighttpd ( 发音 lighty) 是主流的web server, 大型网站都在用哪些web 服务器? yaozer做了个简单的调查, 可以发现: Apache 目前还是占据主导地位, 但是nginx有异军突起之势,大型网站新上线的网站开始渐渐使用nginx了。 而 Microsoft-IIS 和 lighttpd 在大型网站中使用较少。

1.门户网站类:

www.sina.com Apache/2.0.54 (Unix)
blog.sina.com.cn nginx/0.6.36

www.sohu.com Apache
blog.sohu.com nginx
map.sougou.com Apache/2.2.4 (Unix) DAV/2 PHP/5.2.6

www.163.com nginx/0.6.36
news.163.com nginx/0.7.59

www.qq.com Apache

www.aol.com Apache-Coyote/1.1
www.bbc.com Apache
www.cnn.com Apache

2 搜索引擎类
www.baidu.com BWS/1.0
tieba.baidu.com apache 2.7.17.0
news.baidu.com apache2.0.29.0
zhidao.baidu.com apache 1.1.1.0
mp3.baidu.com apache 1.6.14.0
image.baidu.com apache 1.7.16.0
video.baidu.com apache 1.0.5.0

www.google.com gws
mail.google.com GFE/1.3
reader.google.com gws
maps.google.com mfe
docs.google.com GFE/2.0

3 视频网站类
www.tudou.com Apache
www.youku.com Apache
www.6.cn nginx/0.7.21

4 其他
www.hotmail.com Microsoft-IIS/6.0
www.msn.com Microsoft-IIS/6.0

www.cnbeta.com nginx/0.6.35
www.javaeye.com lighttpd/1.4.20
www.csdn.com.cn Microsoft-IIS/6.0

www.joomla.org Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7a mod_bwlimited/1.4 PHP/5.2.6
www.magentocommerce.com nginx/0.6.36

www.yaozer.cn Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g

分享家:Addthis中国

Apache ab介绍

开源性能测试工具-Apache ab介绍, 原文在此

Apache ab (ApacheBench) 可以用来进行简单的并发测试。 比如  ab -n 10 -c 10 http://www.yaozer.cn/ .

分享家:Addthis中国

Apache2.0性能优化—MPM的选择与配置zz and MySQL性能优化zz

Apache2.0性能优化—MPM的选择与配置: http://bbs.51cto.com/archiver/tid-32770.html
MySQL性能优化的参数简介:http://database.51cto.com/art/200512/13055.htm

分享家:Addthis中国

apache2 : (98)Address already in use

突然发现无法连接51kaiyuan.com, 于是准备restart apache2。结果如下:

* Starting web server apache2 (98)Address already in use: make_sock: could not bind to address 222.73.44.209:80
no listening sockets available, shutting down
Unable to open logs                          [fail]

参看端口占用情况: sudo netstat -antup

结果如下:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 222.73.44.209:80 0.0.0.0:*               LISTEN      4954/apache2
……

显然apache2还在运行,为什么restart不成功呢?先stop它再说,

sudo /etc/init.d/apache2 stop

* Stopping web server apache2

httpd (no pid file) not running                    [ OK ]
好了,显示stop成功。再次restart,却还是提示(98)Address already in use,为什么呢?一看端口占用情况,apache2还在?ft,stop apache2成功但是进程还在运行,这是怎么回事呢

强行kill 进程apache2, 再start apache2, 终于成功了。

分享家:Addthis中国