测试从源里安装的LNMP和编译安装的LNMP的性能差距 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
vibbow
V2EX    服务器

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

  •  
  •   vibbow 2013-11-01 22:25:11 +08:00 7423 次点击
    这是一个创建于 4367 天前的主题,其中的信息可能已经有所发展或是发生改变。
    看到了这个贴: 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


    目测要跑很久......
    第 1 条附言    2013-11-02 00:06:03 +08:00
    这是用源里的LNMP测试的结果...
    感觉很悲壮,Wordpress在不进行任何优化的情况下太吃CPU了...

    Server Software: nginx/1.4.1
    Server Hostname: 192.168.40.128
    Server Port: 80

    Document Path: /wordpress/?paged=2
    Document Length: 51782 bytes

    Concurrency Level: 50
    Time taken for tests: 7152.966 seconds
    Complete requests: 25000
    Failed requests: 0
    Write errors: 0
    Total transferred: 1300550000 bytes
    HTML transferred: 1294550000 bytes
    Requests per second: 3.50 [#/sec] (mean)
    Time per request: 14305.933 [ms] (mean)
    Time per request: 286.119 [ms] (mean, across all concurrent requests)
    Transfer rate: 177.56 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 8 21.1 2 308
    Processing: 628 14285 857.8 14221 20891
    Waiting: 628 14283 855.0 14220 20883
    Total: 629 14293 860.2 14228 20893

    Percentage of the requests served within a certain time (ms)
    50% 14228
    66% 14516
    75% 14721
    80% 14859
    90% 15285
    95% 15706
    98% 16197
    99% 16609
    100% 20893 (longest request)
    第 2 条附言    2013-11-02 03:32:58 +08:00
    编译的LNMP,实际测试出来的性能比想象中的要差很多。
    跑了两个多小时,才完成了一半左右的测试,因此直接终止了。

    下面是结果:

    Server Software: nginx
    Server Hostname: 192.168.40.128
    Server Port: 80

    Document Path: /wordpress/?paged=2
    Document Length: 51848 bytes

    Concurrency Level: 50
    Time taken for tests: 8142.049 seconds
    Complete requests: 13680
    Failed requests: 0
    Write errors: 0
    Total transferred: 712139760 bytes
    HTML transferred: 709280640 bytes
    Requests per second: 1.68 [#/sec] (mean)
    Time per request: 29758.952 [ms] (mean)
    Time per request: 595.179 [ms] (mean, across all concurrent requests)
    Transfer rate: 85.41 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 4 21.1 2 1013
    Processing: 9822 29699 3572.8 29776 43209
    Waiting: 9822 29694 3572.0 29769 43208
    Total: 9825 29703 3572.2 29783 43211

    Percentage of the requests served within a certain time (ms)
    50% 29783
    66% 31270
    75% 32213
    80% 32789
    90% 34227
    95% 35355
    98% 36662
    99% 37536
    100% 43211 (longest request)
    第 3 条附言    2013-11-02 03:39:15 +08:00
    从理论上讲,编译安装的LNMP应该比从源里安装的LNMP性能高稍微一点点。
    但是这个测试显示出来的编译的LNMP比从源里安装的LNMP性能差了非常的多。

    从源里安装的LNMP,平均每个请求耗时 286.119ms
    编译安装的LNMP,平均每个请求耗时 595.179mn
    编译安装的LNMP几乎是从源里安装LNMP性能的一半。

    那么问题出在哪里?

    问题就出在php-fpm的设置文件上。

    源里的LNMP,如果我没有记错的话,那么php-fpm开的子进程数应该是CPU核心数*2
    而编译安装的这个LNMP,php-fpm直接固定的开了32个子进程
    因此造成绝大多数的CPU时间浪费在了进程切换上。

    http://v2ex.com/t/87708 这个帖子里的LNMP,应该更适合那种12物理核心,32GB内存的独立服务器,而不是普通的2核心,4G内存的VPS。 cc @yesono
    第 4 条附言    2013-11-02 03:51:28 +08:00
    将php-fpm.conf里的部分设置改为如下的设置:
    pm = dynamic
    pm.max_children = 4
    pm.start_servers = 4
    pm.min_spare_servers = 4
    pm.max_spare_servers = 4
    pm.max_requests = 512

    再进行一次快速的测试:
    >ab -n 5000 -c 50 http://192.168.40.128/wordpress/?paged=2
    第 5 条附言    2013-11-02 04:36:20 +08:00
    虽然我不知道为什么结果会这样...
    但是决定以后继续坚定不移的使用软件源了

    Server Software: nginx
    Server Hostname: 192.168.40.128
    Server Port: 80

    Document Path: /wordpress/?paged=2
    Document Length: 51848 bytes

    Concurrency Level: 50
    Time taken for tests: 3134.855 seconds
    Complete requests: 5000
    Failed requests: 0
    Write errors: 0
    Total transferred: 260285000 bytes
    HTML transferred: 259240000 bytes
    Requests per second: 1.59 [#/sec] (mean)
    Time per request: 31348.553 [ms] (mean)
    Time per request: 626.971 [ms] (mean, across all concurrent requests)
    Transfer rate: 81.08 [Kbytes/sec] received

    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 17 128.3 2 6044
    Processing: 2170 31193 4086.0 30839 90617
    Waiting: 2170 31183 4071.3 30837 90605
    Total: 2170 31211 4090.6 30845 90710

    Percentage of the requests served within a certain time (ms)
    50% 30845
    66% 31717
    75% 32559
    80% 33144
    90% 35506
    95% 37345
    98% 38639
    99% 39237
    100% 90710 (longest request)
    20 条回复    2017-03-09 16:15:17 +08:00
    qiuai
        1
    qiuai  
    PRO
       2013-11-01 22:50:09 +08:00
    坐等结果.lnmp我跑过半个多小时...
    coosir
        2
    coosir  
       2013-11-01 23:38:16 +08:00
    等结果。。另外想问的是,如果生产环境用编译安装以后升级只要重新编译覆盖吗?
    xLzgkddTywk9ALsX
        3
    xLzgkddTywk9ALsX  
       2013-11-01 23:57:34 +08:00
    等结果
    jybox
        4
    jybox  
       2013-11-02 00:07:17 +08:00
    应该不会有多大差距
    vibbow
        5
    vibbow  
    OP
       2013-11-02 00:07:54 +08:00
    @jybox 所以这个测试的目的就是看到底有多大的差别
    xLzgkddTywk9ALsX
        6
    xLzgkddTywk9ALsX  
       2013-11-02 00:21:01 +08:00
    Ngx-pagespeed也测试一下吧
    vibbow
        7
    vibbow  
    OP
       2013-11-02 00:23:23 +08:00
    @buobuk Ngx-pagespeed在这种本地环境测试的情况下,只会拖慢速度。
    AstroProfundis
        8
    AstroProfundis  
       2013-11-02 09:32:12 +08:00
    真有趣,我看看也去跑个模拟低配VPS的测试好了...
    qiuai
        9
    qiuai  
    PRO
       2013-11-02 10:27:37 +08:00
    centos这种没有源直接安装的系统咋办....nginx到现在都没被收到源里...
    046569
        10
    046569  
       2013-11-02 11:15:34 +08:00   1
    FPM数量受Web程序影响,无法简单固化.
    YMate在搞的时候测试了很多方案:针对不同程序(现阶段是不同版本的Discuz!)调整进程数量,更换缓存程序等等,工程量巨大.相对来说,采用的是稳定而较快速的方案.
    但并不是最快速的方案.即使针对网站程序去做特定的优化,编译的MySQL与源中的相比,性能差距也不足5%,考虑到误差,基本可以忽略不计.
    现在的软件架构,基本上靠调整配置文件就能发挥大部分性能了,编译源中的软件实在是得不偿失,尤其是低配VPS上,更没多大意义.
    xLzgkddTywk9ALsX
        11
    xLzgkddTywk9ALsX  
       2013-11-02 11:19:27 +08:00
    pm = dynamicy应该是pm = static 如果你不想切换子进程的话
    likexian
        12
    likexian  
       2013-11-02 12:11:11 +08:00
    自己编译更多的是为了定制,如果只是为了性能,浪费这时间干嘛,性能不够直接加机器就完事,而且php解析器本身就那个东西,你不改代码指望性能有多大的变化
    AstroProfundis
        13
    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
        14
    iZr  
       2013-11-02 23:19:44 +08:00
    表示关注
    vibbow
        15
    vibbow  
    OP
       2013-11-03 00:41:44 +08:00
    @likexian 一直没搞懂所谓的“定制”,到底是定制了什么。
    vibbow
        16
    vibbow  
    OP
       2013-11-03 02:26:25 +08:00
    yesono
        17
    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
        18
    yesono  
       2013-11-20 09:37:34 +08:00
    @vibbow digitalocean 512M 版
    vibbow
        19
    vibbow  
    OP
       2013-11-20 16:36:31 +08:00
    @yesono 对比测试呢?
    wshcdr
        20
    wshcdr  
       2017-03-09 16:15:17 +08:00
    好帖留名
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1376 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 34ms UTC 17:02 PVG 01:02 LAX 10:02 JFK 13:02
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86