受人所托,要做一个比较正式的网站,可自己以前折腾都是 debian + lighttpd + php-fastcgi + sqlite 这样的奇葩组合,肯定不能这么用。
首先是系统,一直都是 debian 而且也没有什么不稳定的情况,但 centos 在很多人口中似乎都是:红帽亲儿子,企业,稳定。于是便纠结应该用自己熟悉的 debian 还是换到口碑似乎更好的 centos 。
第二是 web 服务器,自己用 lighttpd 只是为了低资源占用,普遍用的应该都是 apache 和 nginx 吧,但用法也有好多种。
开始动手测试,测试是在虚拟机下进行的,两台虚拟机都是 512M 内存,系统是 debian 8 和 centos 7 ,都用默认源,都用 apt/yum 安装。
Server version: Apache/2.4.6 (CentOS) Server built: Nov 19 2015 21:43:13
Server version: Apache/2.4.10 (Debian) Server built: Nov 28 2015 14:05:48
从版本号上看,是 debian 中的 apache 较新,但是有听到一种说法, centos 中的包都有 backport ,虽然版本号旧,但软件不旧,具体不知如何考证。
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
PHP 5.6.17-0+deb8u1 (cli) (built: Jan 13 2016 09:10:12)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
从版本号上看,是 debian 中的 php 较新。
但是安装 php-gd 的时候, centos 中是 bundle 版, debian 中是 dev 版, dev 字面上应该是开发版。明明用的是 debian 的 stable 源,为什么会是开发版?
mysql Ver 15.1 Distrib 5.5.44-MariaDB, for Linux (x86_64) using readline 5.1
mysql Ver 14.14 Distrib 5.5.47, for debian-linux-gnu (x86_64) using readline 6.3
数据库这里就不能看版本号了,因为 centos 用 yum 安装 mysql 会自动安装 mariadb 。
debian 和 centos 下分别安装 Discuz x3.2 后进行压力测试,放个雅黑探针观察系统负载。
使用 apache 的压力测试工具, ab -c 100 -n 100 http://127.0.0.1/forum.php ,之后逐步增加。
Server Software: Apache/2.4.6
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /forum.php
Document Length: 12872 bytes
Concurrency Level: 100
Time taken for tests: 3.589 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1359500 bytes
HTML transferred: 1287200 bytes
Requests per second: 27.86 [#/sec] (mean)
Time per request: 3589.014 [ms] (mean)
Time per request: 35.890 [ms] (mean, across all concurrent requests)
Transfer rate: 369.92 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 1 0.3 1 2
Processing: 74 1974 996.3 1995 3513
Waiting: 71 1974 996.3 1995 3513
Total: 74 1975 996.0 1997 3514
Percentage of the requests served within a certain time (ms)
50% 1997
66% 2560
75% 2925
80% 3046
90% 3374
95% 3484
98% 3494
99% 3514
100% 3514 (longest request)
Server Software: Apache/2.4.10
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /forum.php
Document Length: 12872 bytes
Concurrency Level: 100
Time taken for tests: 1.215 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 1367400 bytes
HTML transferred: 1287200 bytes
Requests per second: 82.30 [#/sec] (mean)
Time per request: 1215.040 [ms] (mean)
Time per request: 12.150 [ms] (mean, across all concurrent requests)
Transfer rate: 1099.02 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 3 25 4.0 26 27
Processing: 149 705 315.9 706 1187
Waiting: 134 694 316.7 705 1186
Total: 170 730 317.1 732 1212
Percentage of the requests served within a certain time (ms)
50% 732
66% 917
75% 1010
80% 1055
90% 1161
95% 1205
98% 1211
99% 1212
100% 1212 (longest request)
分别测试三次,取最好结果。
在 debian 虚拟机下快照还原后重新安装
结果忘了保存,压力测试结果比单 apache 更好,资源占用比单 apache 更低。
Server Software: nginx/1.6.2
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /forum.php
Document Length: 12871 bytes
Concurrency Level: 100
Time taken for tests: 1.024 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 1363960 bytes
HTML transferred: 1287100 bytes
Requests per second: 97.66 [#/sec] (mean)
Time per request: 1023.960 [ms] (mean)
Time per request: 10.240 [ms] (mean, across all concurrent requests)
Transfer rate: 1300.82 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 9 28 3.4 28 32
Processing: 56 519 288.0 503 991
Waiting: 45 514 287.2 501 991
Total: 73 547 290.2 531 1023
Percentage of the requests served within a certain time (ms)
50% 531
66% 720
75% 819
80% 866
90% 964
95% 1011
98% 1016
99% 1023
100% 1023 (longest request)
单 nginx 的测试结果是最好的,压力测试最好,资源占用最低
而且在压力测试参数增加后, nginx 的测试结果更好了,有点不解。
现在决定用 debian + nginx + php-fpm + mysql 这个组合了,但也留下几个疑问:
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.