发布时间:2014-09-05 16:34:57作者:知识屋
前文再续,话说历经《Windows下Apache VS Lighttpd VS Nginx(Ngwsx)静态文件对比》、《Windows下Zend Server VS Nginx VS Lighttpd PHP运行测试》,为了能更全面的展开Windows与Linux的各方面比较,我决定在同样的机器上安装Ubuntu Server。
为了四个现代化,我们要把测试进行到底!!
这也是我期待已久的测试,先附上Ubuntu Server环境的截图:
还是那台电脑,不过换了个硬盘装了Ubuntu Server。
手动编译Nginx、Lighttpd、PHP,为了快速完成测试,编译所需的依赖包都是用apt-get install,其中Pcre手动编译,使用最新的8.21版本,编译和安装的指令摘录如下:
Nginx为最新的1.1.14,Lighttpd为14.30, PHP 5.3.10 ,Zend Server为5.6(自带的PHP为PHP 5.3.9,不过不是说这个版本的PHP有漏洞吗?难道Zend自己不知道?但是因为是Zend Server自己整合安装的,所以没法变更),。
Nginx依赖库
1
apt-get install zlib1g-dev libssl-dev libpcre3-dev libaio-dev
Nginx编译指令
01
./configure /
02
--prefix=/usr/local/nginx /
03
--conf-path=/etc/nginx/nginx.conf /
04
--with-file-aio /
05
--with-http_ssl_module /
06
--with-http_realip_module /
07
--with-http_flv_module /
08
--with-http_gzip_static_module /
09
--with-http_stub_status_module /
10
--with-pcre=/usr/local/pcre
Nginx摘要信息
01
Configuration summary
02
+ using system PCRE library
03
+ using system OpenSSL library
04
+ md5: using OpenSSL library
05
+ sha1: using OpenSSL library
06
+ using system zlib library
07
08
nginx path prefix: "/usr/local/nginx"
09
nginx binary file: "/usr/local/nginx/sbin/nginx"
10
nginx configuration prefix: "/etc/nginx"
11
nginx configuration file: "/etc/nginx/nginx.conf"
12
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
13
nginx error log file: "/usr/local/nginx/logs/error.log"
14
nginx http access log file: "/usr/local/nginx/logs/access.log"
15
nginx http client request body temporary files: "client_body_temp"
16
nginx http proxy temporary files: "proxy_temp"
17
nginx http fastcgi temporary files: "fastcgi_temp"
18
nginx http uwsgi temporary files: "uwsgi_temp"
19
nginx http scgi temporary files: "scgi_temp"
Lighttpd依赖库
1
apt-get install libev-dev libev-libevent-dev libfam-dev libmemcache-dev libgamin-dev
Lighttpd编译指令
01
./configure /
02
--prefix=/usr/local/lighttpd /
03
--enable-lfs /
04
--disable-ipv6 /
05
--with-libev /
06
--with-pcre /
07
--with-zlib /
08
--with-bzip2 /
09
--with-fam /
10
--with-memcache
Lighttpd摘要信息
01
Plugins:
02
03
enabled:
04
mod_access
05
mod_accesslog
06
mod_alias
07
mod_auth
08
mod_cgi
09
mod_compress
10
mod_dirlisting
11
mod_evhost
12
mod_expire
13
mod_extforward
14
mod_fastcgi
15
mod_flv_streaming
16
mod_indexfile
17
mod_proxy
18
mod_redirect
19
mod_rewrite
20
mod_rrdtool
21
mod_scgi
22
mod_secdownload
23
mod_setenv
24
mod_simple_vhost
25
mod_ssi
26
mod_staticfile
27
mod_status
28
mod_trigger_b4_dl
29
mod_userdir
30
mod_usertrack
31
mod_webdav
32
disabled:
33
mod_cml
34
mod_magnet
35
mod_mysql_vhost
36
37
Features:
38
39
enabled:
40
auth-crypt
41
compress-bzip2
42
compress-deflate
43
compress-gzip
44
large-files
45
network-ipv6
46
regex-conditionals
47
stat-cache-fam
48
storage-memcache
49
disabled:
50
auth-ldap
51
network-openssl
52
storage-gdbm
53
webdav-locks
54
webdav-properties
PHP依赖库
1
apt-get install libmysqlclient-dev libxml2-dev libjpeg62-dev libpng12-dev libxpm-dev libfreetype6-dev libgd2-xpm-dev libmhash-dev libmcrypt-dev libevent-dev libbz2-dev curl libcurl4-openssl-dev libicu-dev autoconf libmemcached-dev libfcgi-dev libbz2-dev libltdl-dev
PHP编译指令
01
./configure /
02
--prefix=/usr/local/php-5.3.10 /
03
--enable-fpm /
04
--with-fpm-user=www /
05
--with-fpm-group=www /
06
--enable-fastcgi /
07
--with-openssl /
08
--with-pcre-regex=/usr/local/pcre /
09
--with-zlib /
10
--enable-bcmath /
11
--with-bz2 /
12
--enable-ftp /
13
--with-gd /
14
--with-mcrypt /
15
--with-jpeg-dir /
16
--with-png-dir /
17
--with-zlib-dir /
18
--with-xpm-dir /
19
--with-freetype-dir /
20
--enable-gd-native-ttf /
21
--with-mhash /
22
--with-curl /
23
--enable-intl /
24
--enable-mbstring /
25
--with-mysql /
26
--with-mysql-sock /
27
--with-mysqli /
28
--with-pdo-mysql /
29
--enable-shmop /
30
--enable-soap /
31
--enable-sockets /
32
--enable-zip /
33
--enable-calendar /
34
--enable-mysqlnd /
35
--with-pear /
PHP摘要信息
01
Installing PHP SAPI module: fpm
02
Installing PHP CLI binary: /usr/local/php-5.3.10/bin/
03
Installing PHP CLI man page: /usr/local/php-5.3.10/man/man1/
04
Installing PHP FPM binary: /usr/local/php-5.3.10/sbin/
05
Installing PHP FPM config: /usr/local/php-5.3.10/etc/
06
Installing PHP FPM man page: /usr/local/php-5.3.10/man/man8/
07
Installing PHP FPM status page: /usr/local/php-5.3.10/share/php/fpm/
08
Installing build environment: /usr/local/php-5.3.10/lib/php/build/
09
Installing header files: /usr/local/php-5.3.10/include/php/
10
Installing helper programs: /usr/local/php-5.3.10/bin/
11
program: phpize
12
program: php-config
13
Installing man pages: /usr/local/php-5.3.10/man/man1/
14
page: phpize.1
15
page: php-config.1
16
Installing PEAR environment: /usr/local/php-5.3.10/lib/php/
17
[PEAR] Archive_Tar - installed: 1.3.7
18
[PEAR] Console_Getopt - installed: 1.3.0
19
[PEAR] Structures_Graph- installed: 1.0.4
20
[PEAR] XML_Util - installed: 1.2.1
21
[PEAR] PEAR - installed: 1.9.4
22
Wrote PEAR system config file at: /usr/local/php-5.3.10/etc/pear.conf
23
You may want to add: /usr/local/php-5.3.10/lib/php to your php.ini include_path
24
/home/janpoem/php-5.3.10/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.3.10/bin
25
ln -s -f /usr/local/php-5.3.10/bin/phar.phar /usr/local/php-5.3.10/bin/phar
26
Installing PDO headers: /usr/local/php-5.3.10/include/php/ext/pdo/
27
28
/usr/local/php-5.3.10/lib/php/extensions/no-debug-non-zts-20090626/
29
30
/var/tmp/xcache/mmap
31
/var/tmp/xcache/coredump
32
/var/tmp/xcache/coveragedump
题外话:被某人回复的某邮件气得吐血了,我表示深度的无语和失望。
补充说明,php-fpm就是fastcgi,具体我就不罗嗦了。PHP编译的基本指导原则是,安装日常开发中用到的模块,具体编译内容参见php编译指令部分。
不过由于当时忘记截图了,所以我这里简单罗列一下,mbstring、PDO、iconv、json、pcre、xcache(Zend Server用的是Zend自带的那个opcode缓存cache)等扩展。
Zend Server安装,Zend Server的安装需要在官方网站下载一个脚本,这个脚本会为你添加Zend的更新源,然后通过远程下载的方式把Zend Server安装完毕。这个Zend Server比较讨厌,默认会给你装一大堆东西,也没有文档去说明究竟是些什么,好吧,暂时先不计较,继续测试。
测试服务器为192.168.33.120,Web端口为80。执行AB的机器在另外一台Ubuntu Server上进行,ip为192.168.33.6。然后我会用自己的笔记本开两个putty,分别通过ssh登录两台服务器,192.168.33.120打开top监控系统资源和进程,192.168.33.6则用来执行AB的测试指令。这样确保每个终端都只负责各所司职的功能。
而测试的文件与之前相似,测试两个静态文件,3个php脚本。分别为:
测试的方法,也和之前一样:
10秒:ab -t 10 http://192.168.33.120/
并发测试:ab -c 100 -n 1000 http://192.168.33.120/
每个测试执行三次,然后记录下rps的结果。其中,-t 10模式,通过rps值 * 10即其总共完成的请求数。而-c 100 -n 1000,必100%须完成了1000次请求的,才算达标。
第一次测试,主要为了找出同等环境下,rps分值较高者,每个服务器都使用的是默认的基础配置,而PHP-FPM也设置了最小10个php-fpm进程,最大30。PHP-FPM是以Socket的方式,运行在127.0.0.1:9000上。
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.12 | 116.78 | 145.57 | 276.33 | 17.94 |
19.13 | 117 | 145.81 | 276.62 | 17.94 |
19.14 | 117.37 | 145.85 | 276.26 | 18.06 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.28 | 124.53 | 174.96 | 1273.61 | 19.21 |
19.3 | 124.54 | 175.1 | 1270.29 | 19.25 |
19.26 | 124.55 | 174.83 | 1269.34 | 19.27 |
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.12 | 116.99 | 145.6 | 270.69 | 18.46 |
19.11 | 117.01 | 145.63 | 271.21 | 18.43 |
19.13 | 117.01 | 145.38 | 270.73 | 18.48 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.28 | 124.65 | 175.01 | 1270.95 | 19.24 |
19.3 | 124.65 | 175.44 | 1281.82 | 19.23 |
19.28 | 124.65 | 175.29 | 1276.84 | 19.32 |
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.06 | 114.07 | 114.96 | 236.97 | 18.12 |
19.06 | 114.75 | 114.62 | 237.15 | 18.12 |
19.06 | 114.84 | 114.53 | 235.41 | 18.12 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.32 | 122.93 | 143.83 | 1169.47 | 19.27 |
19.27 | 122.41 | 146.98 | 1172.19 | 19.29 |
19.26 | 123.08 | 147.41 | 1163.12 | 19.29 |
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.11 | 115.95 | 145.45 | 265.31 | 18.3 |
19.1 | 116.15 | 145.72 | 267.37 | 18.35 |
19.11 | 116.06 | 145.38 | 269.52 | 18.32 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.32 | 124.64 | 175 | 1288.84 | 19.27 |
19.25 | 124.64 | 175.17 | 1286.55 | 19.29 |
19.29 | 124.64 | 174.73 | 1286.36 | 19.28 |
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.09 | 115.89 | 145.62 | 271.86 | 18.48 |
19.1 | 115.93 | 145.77 | 269.88 | 18.48 |
19.1 | 115.88 | 145.68 | 269.12 | 18.48 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.26 | 124.5 | 175.27 | 1278.59 | 19.28 |
19.24 | 124.5 | 175.63 | 1285.4 | 19.28 |
19.22 | 124.5 | 175.62 | 1285.55 | 19.29 |
呃……
第二次的测试结果和第一次的测试结果,并没有太大的偏差,这个让人有些意外,但又觉得在情理之中。这个测试结果说明,这个数据已经是这台测试服务器下,最好的得分(最好的说法可能有些不妥,不过暂且这么一说),没有更多的硬件空间能让WebServer去挤压出更高rps出来。在这种情况,无论怎么调优,都不可能获得更好的测试结果。我想,如果换到更好的硬件环境下的服务器,可能才会获得更好的分数。
不过从Nginx的配置文件,可以看出,Nginx比较贴近新硬件的发展趋势,就是多核运算。他允许设置工作进程( worker_processes ),还允许分配不同的CPU核心。(诚如我在《Windows下Apache VS Lighttpd VS Nginx(Ngwsx)静态文件对比》,Ngwsx,开启了4个工作进程后,“但是高并发模式下,CPU占用高达25%,但是他也就是维持在25%,由于当时心急与想测试Lighttpd,没有注意看,他是不是将计算分摊到4个CPU的核心上了。”,这次我明确的看到,他允许为工作进程分配具体的CPU核心,说明他是可以将计算分摊到4个CPU的核心上了。)虽然Nginx具体表现上看似没有特别突出的表现,但是我相信换到更好的硬件环境里,具体的调优配置是会令他有更加出色的表现。
而相比之下,Lighttpd在运行过程中,始终是一个单进程的lighttpd在运行,他也不具备面向并行运算的可调优的着手点。而lighttpd,长久以来更新速度缓慢,几个年头过去了,还维持在14.x,这个实在是令人担忧这个产品的未来。
由于数据并没有较大的提升,所以,也不适合对他们进行比较了(只有在承受到更大的压力,通过数据的波动才能看出两者的差异)。
貌似测试可以告一段落了,不过此时,Max(同事甲)人说:你的Zend Server是测试在Windows XP SP2,那个破烂怎么算数呢?你搞个Server版本的Windows测试来看看啊!好,再来一场加时赛!
Sam(同事乙)一阵忙,下载,刻碟,安装,Server 2008 安装ing.....安装完毕!这里就不罗嗦了,上个截图:
还是那台电脑,还是那个CPU,还是那个内存,变了个脸。不过Server 2008是32bit的,因为目前PHP主要都是32bit的。64bit,不是不行,但是都凌晨2、3点了,我可不想再在windows上手动编译PHP了。Sam冒着胃疼坚持着,我自信告诉他,一个小时,给我一个小时,绝对完成所有任务。
开始安装,IIS 7,+CGI,配置fastcgi,一顿忙...然后亮了,截个图:
因为通过第一、第二次的测试,我们已经得到想要的答案了,只是为了更加全面些,才加测试了Server 2008,所以IIS直接就开了gzip什么的。
Zend Server用的还是之前测试的那个版本(没装新的),直接打开原来C盘的Zend目录,打开Apache/bin/httpd.exe,弹出一个黑窗口,哦耶,截个图:
大家可能会很迷惑,说,你小子会不会拿个Ubuntu Server下的Zend Server来这里糊弄事啊?哎哟,那对比着下面这张图,和再下面的这张图看吧:
这是Ubuntu上的Zend Server,看出究竟了吗?
这是Ubuntu上的lighttpd截图。
由于Windows上的Zend Server,之前已经测试过,而且也调优过,所以也就不再罗嗦了。
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
18.07 | 86.67 | 76.63 | 84.1 | 16.71 |
18.11 | 87.16 | 75.3 | 86.72 | 16.63 |
18.1 | 87.34 | 76.35 | 94.73 | 16.82 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.36 | 124.63 | 163.27 | 370.3 | 19.31 |
19.36 | 124.63 | 165.81 | 347.22 | 19.18 |
19.34 | 124.62 | 165.87 | 357 | 19.3 |
10秒 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
16.03 | 77.88 | 76.62 | 65.29 | 17.19 |
16.03 | 78.03 | 77.73 | 63.93 | 17.24 |
16.13 | 78.52 | 76.94 | 69.12 | 17.21 |
并发测试 | ||||
index.html | jquery-1.7.1.min.js | info.php | db.php | open.php |
19.34 | 124.35 | 134.83 | 941.01 | 19.34 |
18.9 | 124.43 | 135.51 | 995.14 | 19.31 |
19.29 | 124.34 | 134.37 | 1055.32 | 19.31 |
先说静态文件处理,没想到,IIS 7的成绩居然那么好,尤其是并发测试的结果(废话,Sam在旁边大叫,Zend Server是开外挂的,IIS那就是开内挂)。 虽然在-t的测试模式落后,但是一直被人诟病的Windows却在并发测试下和Linux的相差无二。连Apache也当仁不让,静态文件处理的RPS也优于xp的测试结果。
不过看php的处理方面,结果惨不忍睹啊,和Linux比,完全落后一大截。通过Windows和Linux在静态文件上所得到的相近的 RPS ,能够更加充分的说明,Windows绝对不是PHP运行的最佳环境。但是唯独一点有不同,就是IO的性能表现上。
“Windows的IO不如Linux”,这是一句我们常常看到人们在说的话题,可是事实上,通过open.php和index.html的对比测试结果可以看出,通过php的打开文件输出,其性能是接近WebServer输出的,当然他需要更大的开销。而通过横向对比5个测试结果,PHP在处理这种IO,在不同平台下的差异并没有那么大。而通过比较并发测试静态文件结果,也充分说明,Windows和Linux,在文件读取上,性能是接近的(当然,更好的硬件环境是不是会有差别呢?有待证实)。
当然,在测试数据以外的,是CPU使用率,系统剩余资源的情况,这方面我没有做截图比较,但是我去看服务器的时候,也会看到,Windows Server 2008在处理并发测试时,会有更高的CPU使用(远不似Linux下Nginx处理的那样平滑,而且可以多进程负载)。
历经2天余的折腾,针对Windows平台和Linux平台的对比测试终于告一段落了。
再次感谢Max和Sam整个过程给予的帮助,尤其是Sam,能在一下午之内在同一台机器上装好Ubuntu Server和Server 2008,多亏了他的协助。
这次测试的主要是风口浪尖中的4个主角,不过敢夸口自称性能卓越的 WebServer,仍有很多。而我,也打算继续对他们测试到底。这不,Sam又举了两个,据说其中一个是用.net实现的,支持fastcgi,我的手又痒了
摘自 曾建凯的博客
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能