测试从源里安装的LNMP和编译安装的LNMP的性能差距

2013-11-01 22:25:11 +08:00
 vibbow
看到了这个贴: http://v2ex.com/t/87708
突然奇想来测试一下,看从源里安装的LNMP和编译安装的LNMP性能差距到底有多少。

测试是在我本机的虚拟机里运行的(性能能超越绝大多数VPS,还没有网速限制问题)

母鸡硬件:
CPU: i7-3730QM, 内存: 4x4 DDR3 1600, 硬盘: 三星 PM830 msata 128G
已启用 Intel-VT 和 Direct-IO

母鸡软件:
Windows 7 SP1 x64 Professional,已打完所有补丁
VMware workstation 10.0.1 build-1379776

虚拟机硬件:
CPU: 1处理器2核心, 内存: 4GB, 硬盘: 西数 WD5000BPKT-75PK4T0

虚拟机软件:
Ubuntu 12.04.3 x64,已打完所有补丁,安装闭源版VMware Tool

服务器软件:
启用Obdrej Sury的PPA https://launchpad.net/~ondrej
使用他的PHP 5.5, Nginx, MySQL 5.6
PHP安装以下扩展:php5-gd php5-mysqlnd php5-curl php5-mcrypt

使用这个帖子内的lnmp http://v2ex.com/t/87708

测试方法:
环境配置基本保持默认
对于从PPA源里安装的LNMP,按照这个教程进行设置:
https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04

安装Wordpress 3.7.1英文版,导入Theme Unit Test文件(下载所有附件)
http://codex.wordpress.org/Theme_Unit_Test

使用ApacheBench测试访问Wordpress的第二页:
ab -n 25000 -c 50 http://192.168.40.128/wordpress/?paged=2


目测要跑很久......
7103 次点击
所在节点    服务器
20 条回复
qiuai
2013-11-01 22:50:09 +08:00
坐等结果.lnmp我跑过半个多小时...
coosir
2013-11-01 23:38:16 +08:00
等结果。。另外想问的是,如果生产环境用编译安装以后升级只要重新编译覆盖吗?
xLzgkddTywk9ALsX
2013-11-01 23:57:34 +08:00
等结果
jybox
2013-11-02 00:07:17 +08:00
应该不会有多大差距
vibbow
2013-11-02 00:07:54 +08:00
@jybox 所以这个测试的目的就是看到底有多大的差别
xLzgkddTywk9ALsX
2013-11-02 00:21:01 +08:00
Ngx-pagespeed也测试一下吧
vibbow
2013-11-02 00:23:23 +08:00
@buobuk Ngx-pagespeed在这种本地环境测试的情况下,只会拖慢速度。
AstroProfundis
2013-11-02 09:32:12 +08:00
真有趣,我看看也去跑个模拟低配VPS的测试好了...
qiuai
2013-11-02 10:27:37 +08:00
centos这种没有源直接安装的系统咋办....nginx到现在都没被收到源里...
046569
2013-11-02 11:15:34 +08:00
FPM数量受Web程序影响,无法简单固化.
YMate在搞的时候测试了很多方案:针对不同程序(现阶段是不同版本的Discuz!)调整进程数量,更换缓存程序等等,工程量巨大.相对来说,采用的是稳定而较快速的方案.
但并不是最快速的方案.即使针对网站程序去做特定的优化,编译的MySQL与源中的相比,性能差距也不足5%,考虑到误差,基本可以忽略不计.
现在的软件架构,基本上靠调整配置文件就能发挥大部分性能了,编译源中的软件实在是得不偿失,尤其是低配VPS上,更没多大意义.
xLzgkddTywk9ALsX
2013-11-02 11:19:27 +08:00
pm = dynamicy应该是pm = static 如果你不想切换子进程的话
likexian
2013-11-02 12:11:11 +08:00
自己编译更多的是为了定制,如果只是为了性能,浪费这时间干嘛,性能不够直接加机器就完事,而且php解析器本身就那个东西,你不改代码指望性能有多大的变化
AstroProfundis
2013-11-02 19:01:49 +08:00
我用楼主一样的方法试了一下真实VPS环境下的情况。
母机配置:
Intel(R) Xeon(R) CPU L5520 @ 2.27GHz
24GB RAM w/ 26GB Swap
一共是16个逻辑核心,系统是 CentOS 6 64bit w/ SolusVM w/ OpenVZ

因为机器基本上是闲置状态所以还专门开了一个小鸡跑了十个线程的 cgminer 拉高整机负载,开始测试之前母机的负载是
Load Average: 10.51 10.82 10.72

小鸡配置:
256MB RAM w/ 256MB vSwap
4 CPU Cores, 用的 SolusVM 默认的资源分配
系统是 Debian 7 64bit minimal

基本上感觉这个配置是比较接近大多数人上VPS折腾个人博客的条件的。

源安装用的 dotdeb 的 wheezy 源,除了 nginx 把 php 支持打开以外全部用默认配置,装了这些包:

apt-get install nginx php5-fpm php5-mysql php5-curl php5-mcrypt php5-gd mysql-server mysql-client

然后采用和楼主完全相同的方法在另一台干净的小鸡里面跑的 ab 测试:

Server Software: nginx/1.4.3
Server Hostname: masked ip addr
Server Port: 80

Document Path: /?paged=2
Document Length: 48670 bytes

Concurrency Level: 50
Time taken for tests: 9312.364 seconds
Complete requests: 25000
Failed requests: 0
Write errors: 0
Total transferred: 1222175000 bytes
HTML transferred: 1216750000 bytes
Requests per second: 2.68 [#/sec] (mean)
Time per request: 18624.728 [ms] (mean)
Time per request: 372.495 [ms] (mean, across all concurrent requests)
Transfer rate: 128.17 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 4
Processing: 1489 18607 958.7 18512 22655
Waiting: 218 17024 760.1 17017 19704
Total: 1492 18607 958.7 18512 22655

Percentage of the requests served within a certain time (ms)
50% 18512
66% 18890
75% 19171
80% 19355
90% 19772
95% 20129
98% 20551
99% 20854
100% 22655 (longest request)

----------------------------------------------------------

接下来是编译安装的,同样用的是主楼里面提到的那个脚本;脚本安装过程整体感觉不错,而且可选的功能很多,赞一发。
安装过程中没有选择 memcache 等等各种缓存/加速/优化组件,有一个没记清是啥的反正是必选所以就用默认值了。

因为楼主提到了脚本的默认 php-fpm 配置不科学,所以我安装好后就直接把参数改成了和源安装一样的值:

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

别的都保持不变,包括 nginx 配置都是默认添加了 php 支持的所以完全没动。
同样是部署好一个 WordPress 3.7.1 英文版过后导入主题测试用例然后 ab 第二页:

Server Software: nginx
Server Hostname: masked ip addr
Server Port: 80

Document Path: /?paged=2
Document Length: 48688 bytes

Concurrency Level: 50
Time taken for tests: 14751.522 seconds
Complete requests: 25000
Failed requests: 0
Write errors: 0
Total transferred: 1222125000 bytes
HTML transferred: 1217200000 bytes
Requests per second: 1.69 [#/sec] (mean)
Time per request: 29503.044 [ms] (mean)
Time per request: 590.061 [ms] (mean, across all concurrent requests)
Transfer rate: 80.91 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 5
Processing: 2311 29474 1752.4 29319 36814
Waiting: 2309 29473 1752.4 29318 36812
Total: 2315 29474 1752.3 29319 36814

Percentage of the requests served within a certain time (ms)
50% 29319
66% 30072
75% 30482
80% 30759
90% 31558
95% 32379
98% 33340
99% 33969
100% 36814 (longest request)

差距比预想的还要明显 0.0
从最后的时间统计来看源安装环境已经响应全部数据的时候编译安装的还有超过一半的请求没有处理,顺便一提跑前一个测试的时候后一个正在编译安装,所以整机的IO和CPU负担都比跑后一个的时候要高...

求解释这是为啥...
iZr
2013-11-02 23:19:44 +08:00
表示关注
vibbow
2013-11-03 00:41:44 +08:00
@likexian 一直没搞懂所谓的“定制”,到底是定制了什么。
vibbow
2013-11-03 02:26:25 +08:00
yesono
2013-11-20 09:30:17 +08:00
@vibbow 测试机器512M版,OS:Ubuntu 12.04.3 x64 wordpress-3.7.1 (英文版)+ Theme Unit Test文件

# ab -n 25000 -c 50 http://demo.linuxeye.com/?paged=2
Server Software: nginx
Server Hostname: demo.linuxeye.com
Server Port: 80

Document Path: /?paged=2
Document Length: 40304 bytes

Concurrency Level: 100
Time taken for tests: 539.276 seconds
Complete requests: 2500
Failed requests: 0
Write errors: 0
Total transferred: 101265000 bytes
HTML transferred: 100760000 bytes
Requests per second: 4.64 [#/sec] (mean)
Time per request: 21571.031 [ms] (mean)
Time per request: 215.710 [ms] (mean, across all concurrent requests)
Transfer rate: 183.38 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.2 0 19
Processing: 2743 21201 2344.4 21583 23536
Waiting: 2743 21201 2344.4 21583 23536
Total: 2761 21202 2341.6 21583 23536

Percentage of the requests served within a certain time (ms)
50% 21583
66% 21876
75% 22072
80% 22154
90% 22410
95% 22633
98% 22860
99% 22974
100% 23536 (longest request)

Server Software: nginx
Server Hostname: demo.linuxeye.com
Server Port: 80

Document Path: /?paged=2
Document Length: 40304 bytes

Concurrency Level: 50
Time taken for tests: 5410.895 seconds
Complete requests: 25000
Failed requests: 0
Write errors: 0
Total transferred: 1012650000 bytes
HTML transferred: 1007600000 bytes
Requests per second: 4.62 [#/sec] (mean)
Time per request: 10821.789 [ms] (mean)
Time per request: 216.436 [ms] (mean, across all concurrent requests)
Transfer rate: 182.76 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 12
Processing: 2923 10813 573.1 10760 13455
Waiting: 2923 10813 573.1 10760 13455
Total: 2934 10814 573.0 10760 13465

Percentage of the requests served within a certain time (ms)
50% 10760
66% 10988
75% 11147
80% 11257
90% 11550
95% 11794
98% 12088
99% 12272
100% 13465 (longest request)
yesono
2013-11-20 09:37:34 +08:00
@vibbow digitalocean 512M 版
vibbow
2013-11-20 16:36:31 +08:00
@yesono 对比测试呢?
wshcdr
2017-03-09 16:15:17 +08:00
好帖留名

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/87755

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX