szopen
V2EX  ›  PHP

今天用 ab 工具测试了一下框架,高效的性能让我吃惊

  •  
  •   szopen · Mar 31, 2017 · 11354 views
    This topic created in 3334 days ago, the information mentioned may be changed or developed.

    首先展示一下其他主要框架的测试:

    https://github.com/kenjis/php-framework-benchmark

    框架地址:

    https://github.com/chopins/toknot

    测试用例是仓库中app/admin应用

    我的测试环境:

    与上面用 apache web 服务器不同,我用的是 nginx

    php 版本: 5.6.0

    php 扩展情况:

    [PHP Modules]
    Core
    date
    ereg
    mysqli
    mysqlnd
    pcre
    PDO
    pdo_mysql
    Reflection
    session
    SPL
    standard
    Zend OPcache
    
    [Zend Modules]
    Zend OPcache
    

    php-fpm 配置:

    pm.max_children = 8
    pm.start_servers = 4
    pm.max_spare_servers = 4
    pm.min_spare_servers = 2
    

    测试命令:

    ab -n 10000 -c 4 http://127.0.0.1/account/signup

    业务:

    1. 构造和输出了一个 HTML 表单
    2. 查询了一个 MySQL 空表
    3. 初始化了 session, session 存在了数据库的一个 memory 表中
    4. 路由用的是 symfony 的路由器

    测试结果:

    Server Software:        nginx/1.10.2
    Server Hostname:        127.0.0.1
    Server Port:            80
    
    Document Path:          /account/signup
    Document Length:        36 bytes
    
    Concurrency Level:      4
    Time taken for tests:   11.643 seconds
    Complete requests:      10000
    Failed requests:        0
    Total transferred:      2600000 bytes
    HTML transferred:       360000 bytes
    Requests per second:    858.89 [#/sec] (mean)
    Time per request:       4.657 [ms] (mean)
    Time per request:       1.164 [ms] (mean, across all concurrent requests)
    Transfer rate:          218.08 [Kbytes/sec] received
    

    858.89 RPS 比 CI-3.0 的 753.09 略高,比 fatfree3.5 的 965.16 略低

    内存占用:

    1. usage 2.4M
    2. peak 2.4M

    PHP 7.0 测试情况

    opcache 版本:

    Concurrency Level:      8
    Time taken for tests:   7.578 seconds
    Complete requests:      10000
    Failed requests:        7
       (Connect: 0, Receive: 0, Length: 7, Exceptions: 0)
    Total transferred:      102427973 bytes
    HTML transferred:       100177973 bytes
    Requests per second:    1319.60 [#/sec] (mean)
    Time per request:       6.062 [ms] (mean)
    Time per request:       0.758 [ms] (mean, across all concurrent requests)
    Transfer rate:          13199.60 [Kbytes/sec] received
    

    无 opcache 版本:

    Concurrency Level:      100
    Time taken for tests:   190.636 seconds
    Complete requests:      50000
    Failed requests:        41
       (Connect: 0, Receive: 0, Length: 41, Exceptions: 0)
    Total transferred:      512146699 bytes
    HTML transferred:       500896699 bytes
    Requests per second:    262.28 [#/sec] (mean)
    Time per request:       381.271 [ms] (mean)
    Time per request:       3.813 [ms] (mean, across all concurrent requests)
    Transfer rate:          2623.55 [Kbytes/sec] received
    

    有无 opcache 相差好大

    36 replies    2017-04-10 10:35:56 +08:00
    codespots
        1
    codespots  
       Mar 31, 2017
    优雅的框架连垫底都是这么的优雅
    codespots
        2
    codespots  
       Mar 31, 2017
    up 主可以添加个 pure php 做完基准,还有可以添加测试下 Yaf 的性能
    szopen
        3
    szopen  
    OP
       Mar 31, 2017
    @westooy 纯 PHP 的没有可比较性
    linghutf
        4
    linghutf  
       Mar 31, 2017 via Android
    laravel 惨不忍睹
    codespots
        5
    codespots  
       Mar 31, 2017
    @szopen 我的意思是用纯 PHP 的性能做为基准,比较各种框架的性能损失,或者性能达到原生的百分比。当然了,框架的主要目的并不是在性能。
    run2
        6
    run2  
       Mar 31, 2017
    7.0 的对比呢?
    levn
        7
    levn  
       Mar 31, 2017
    如果有 xdebug profiler 的记录就更有意思了
    predator
        8
    predator  
       Mar 31, 2017
    居然没有 thinkphp !老外的视野不够开阔 =。=
    gouchaoer
        9
    gouchaoer  
       Mar 31, 2017
    laravel 那复杂的优雅我欣赏不来
    run2
        10
    run2  
       Mar 31, 2017
    @predator #8 是个鬼子啊,而且它的头像。。。。
    laoyuan
        11
    laoyuan  
       Mar 31, 2017
    第一的应该是 Silex
    vjnjc
        12
    vjnjc  
       Mar 31, 2017
    好久没写 php 了,我以前用的 Codeigniter 怎么都看不到。。。
    nilai
        13
    nilai  
       Mar 31, 2017
    @vjnjc ci-3.0
    tabris17
        14
    tabris17  
       Mar 31, 2017
    啥功能都没有,当然快了
    szopen
        15
    szopen  
    OP
       Mar 31, 2017
    @tabris17 MVC 功能都有,满足一个常规网站开放了,另外支持跨语言的服务功能正在开放中
    ss098
        16
    ss098  
       Mar 31, 2017
    opcache 对于 Laravel 性能提升是非常大的,之前我在服务器上通过 Laravel 执行一条简单的 SQL 要 200ms ,现在安装以后这个请求只要 20ms 。
    vjnjc
        17
    vjnjc  
       Mar 31, 2017
    @nilai 多谢~ci 还没垫底哈哈哈
    jhdxr
        18
    jhdxr  
       Mar 31, 2017
    @linghutf laravel 惨不忍睹是因为它**默认**启用了 session 支持,但其他框架一般默认是不启用的
    vibbow
        19
    vibbow  
       Mar 31, 2017
    @jhdxr 启用 session 支持也不应该对性能造成如此大的影响啊。
    szopen
        20
    szopen  
    OP
       Mar 31, 2017
    @ss098 估计大部份消耗都是在 autoload 上,我用 xdebug 分析了一下,总共 83 次的 autoload 调用消耗了我经 48%的时间
    ysz1121
        21
    ysz1121  
       Mar 31, 2017
    好低啊
    otakustay
        22
    otakustay  
       Mar 31, 2017
    没看懂,楼主的意思是社区的性能测试结论是在 apache 做 web 服务器的情况下得出的,而你是用 nginx 来做测试并试图与社区的结论进行对比?
    iwege
        23
    iwege  
       Mar 31, 2017
    讨论 laravel 垫底意义不大, laravel 算是全功能框架了,要看理论上应该先看 lumen.
    mingyun
        24
    mingyun  
       Mar 31, 2017
    laravel 垫底
    cxbig
        25
    cxbig  
       Mar 31, 2017
    空框架?有意义么?实际的产品快不快不完全是框架的问题。
    aksoft
        26
    aksoft  
       Apr 1, 2017
    追求速度 脚本 请用 lua
    qqjt
        27
    qqjt  
       Apr 1, 2017
    qqjt
        28
    qqjt  
       Apr 1, 2017
    “ Before beginning, know that all of these frameworks are fast enough to handle any application you are ever likely to build. I hesitated to even write this post because I think PHP ’ s unique obsession with benchmarking on this level is really, really silly. My only goal is to show how to perform a fair comparison between the three.”
    lianxiaoyi
        29
    lianxiaoyi  
       Apr 1, 2017
    yaf 秒杀全场
    we3613040
        30
    we3613040  
       Apr 1, 2017
    我大 ci 就是牛逼
    killerv
        31
    killerv  
       Apr 1, 2017
    框架对比性能的意义不大,就像是对比卡车的速度和超跑的载重一样,如果真的那么追求性能,就不要使用框架,甚至不要使用 php ,另外 Laravel 优化之后性能并没有那么差。
    sagaxu
        32
    sagaxu  
       Apr 1, 2017
    你重新定义了高效
    sampeng
        33
    sampeng  
       Apr 1, 2017
    你就是 c 原生写,一个 sql 堵 2s ,吞吐也不可能上去
    treycheng
        34
    treycheng  
       Apr 1, 2017
    这么多年还在吐槽框架性能。。。。你要性能怎么不去写 C 呢
    szopen
        35
    szopen  
    OP
       Apr 5, 2017
    一个流行框架有性能总比没性能好,否则怎么能进步?
    qwe3364925
        36
    qwe3364925  
       Apr 10, 2017
    建议你看下 yaf 框架
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3036 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 83ms · UTC 12:04 · PVG 20:04 · LAX 05:04 · JFK 08:04
    ♥ Do have faith in what you're doing.