PHP7.3+Swoole4.4 / Go1.13 / MixPHP2.2 / Beego1.12 性能对比 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
onanying
V2EX    PHP

PHP7.3+Swoole4.4 / Go1.13 / MixPHP2.2 / Beego1.12 性能对比

  •  2
     
  •   onanying 2020-07-25 10:07:35 +08:00 6239 次点击
    这是一个创建于 1907 天前的主题,其中的信息可能已经有所发展或是发生改变。

    好几年没有做过性能对比了,因为越来越觉得性能并没有那么的重要(相对于生态),今天有时间简单测试一下,因为 Mix v2.1 开始就全部切换为单进程协程模式,因此本次主要测试的是 Co\Http\Server ,测试结果在最后面。

    环境

    • CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    • CPU(s): 12
    • Mem: 15G
    • Linux version 3.10.0-957.10.1.el7.x86_64

    PHP 7.3.12 + Swoole 4.4.14

    代码中使用的单进程 Co\Http\Server ,因此需要利用端口复用 (需要 Linux >= 3.10),开启 12 个进程

    • 代码
    <?php \Swoole\Process::daemon(); $scheduler = new \Swoole\Coroutine\Scheduler; $scheduler->set([ 'hook_flags' => SWOOLE_HOOK_ALL, ]); $scheduler->add(function () { $server = new \Swoole\Coroutine\Http\Server('0.0.0.0', 8888, false, true); $server->handle('/', function($request, $response){ $response->end('hello, world!'); }); $server->start(); }); $scheduler->start(); 
    • 开启的进程
    [nobody@tmp]$ ps -ef | grep test.php nobody 1917 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 1923 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 1929 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 1934 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2154 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2166 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2173 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2181 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2187 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2194 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2200 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php nobody 2205 1 0 20:22 ? 00:00:02 /usr/local/php-7.3.12/bin/php test.php 
    • 测试:多跑几次,基本稳定在 127441.95 左右。
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8888/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: swoole-http-server Server Hostname: 127.0.0.1 Server Port: 8888 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.785 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 16600000 bytes HTML transferred: 1300000 bytes Requests per second: 127441.95 [#/sec] (mean) Time per request: 7.847 [ms] (mean) Time per request: 0.008 [ms] (mean, across all concurrent requests) Transfer rate: 20659.53 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.4 0 47 Processing: 2 7 0.5 7 47 Waiting: 0 7 0.4 7 14 Total: 2 8 2.6 7 58 Percentage of the requests served within a certain time (ms) 

    Go 1.13.4

    Golang 默认使用全部 CPU 线程,因此只需开启一个进程即可。

    • 代码
    package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { writer.Write([]byte("hello, world!")) }) err := http.ListenAndServe(":9999", nil) if err != nil{ fmt.Println(err) } } 
    • 开启的进程
    [nobody@~]$ ps -ef | grep gotest nobody 4409 1859 0 20:25 pts/31 00:00:06 ./gotest_linux 
    • 测试:多跑几次,基本稳定在 121575.23 左右,比 Swoole 稍微差点,但非常接近,PHP 是动态语言借助 Swoole 做到这个性能确实是非常夸张了。
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9999/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: Server Hostname: 127.0.0.1 Server Port: 9999 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.823 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 15400000 bytes HTML transferred: 1300000 bytes Requests per second: 121575.23 [#/sec] (mean) Time per request: 8.225 [ms] (mean) Time per request: 0.008 [ms] (mean, across all concurrent requests) Transfer rate: 18283.77 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.4 0 46 Processing: 2 8 1.1 7 46 Waiting: 0 8 1.1 7 30 Total: 2 8 2.7 7 56 Percentage of the requests served within a certain time (ms) 

    MixPHP V2.2

    接下来我们看一下跑在 PHP7.3 + Swoole4.4 下的 Mix V2.2 能跑多少。

    • 开启的进程
    [nobody@tmp]$ ps -ef | grep mix.php nobody 24783 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24801 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24821 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24839 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24856 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24873 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24891 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24908 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24927 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24946 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24963 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24981 1 0 20:51 ? 00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d 
    • 测试:多跑几次,基本稳定在 110050.47 左右,比原生 Swoole 降低了 13.6%,整个框架的代码只降低了这个比例,还是蛮可以的。
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9501/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: swoole-http-server Server Hostname: 127.0.0.1 Server Port: 9501 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.909 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 18100000 bytes HTML transferred: 1300000 bytes Requests per second: 110050.47 [#/sec] (mean) Time per request: 9.087 [ms] (mean) Time per request: 0.009 [ms] (mean, across all concurrent requests) Transfer rate: 19452.28 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.5 0 45 Processing: 2 9 1.6 9 46 Waiting: 0 9 1.6 9 25 Total: 2 9 3.2 9 58 Percentage of the requests served within a certain time (ms) 

    我尝试减少进程测试:

    • 当减少到 5 个进程时达到最高性能
    [nobody@tmp]$ ps -ef | grep mix.php nobody 24946 1 0 20:51 ? 00:00:15 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24963 1 0 20:51 ? 00:00:15 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 24981 1 0 20:51 ? 00:00:15 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 27471 1 22 21:35 ? 00:00:05 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 27522 1 18 21:35 ? 00:00:03 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d 
    • 测试:多跑几次,基本稳定在 114070.87 左右,比 12 个进程的时候还高一点,证明再多开进程已经无法提升性能了,12 线程的 CPU 为何会这样呢?
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9501/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: swoole-http-server Server Hostname: 127.0.0.1 Server Port: 9501 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.877 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 18100000 bytes HTML transferred: 1300000 bytes Requests per second: 114070.87 [#/sec] (mean) Time per request: 8.766 [ms] (mean) Time per request: 0.009 [ms] (mean, across all concurrent requests) Transfer rate: 20162.92 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.0 0 33 Processing: 0 8 3.0 8 33 Waiting: 0 8 3.0 8 24 Total: 0 9 3.7 8 43 Percentage of the requests served within a certain time (ms) 

    Beego V1.12.1

    • 代码:
    package main import ( "fmt" "net/http" "runtime" ) func main() { http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { writer.Write([]byte("hello, world!")) }) err := http.ListenAndServe(":9999", nil) if err != nil{ fmt.Println(err) } } 
    • 测试:多跑几次,基本稳定在 107428.35 左右,与 Mix 非常接近。
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8989/index This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: beegoServer:1.12.1 Server Hostname: 127.0.0.1 Server Port: 8989 Document Path: /index Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.931 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 18200000 bytes HTML transferred: 1300000 bytes Requests per second: 107428.35 [#/sec] (mean) Time per request: 9.309 [ms] (mean) Time per request: 0.009 [ms] (mean, across all concurrent requests) Transfer rate: 19093.71 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.4 0 45 Processing: 0 9 2.4 9 52 Waiting: 0 9 2.4 9 52 Total: 0 9 3.4 9 57 Percentage of the requests served within a certain time (ms) 

    PHP 7.3.12 + Swoole 4.4.14 二次测试

    上面减少到 5 个进程依然可以达到 12 进程的性能,我猜测可能是 ab -c 1000 只能达到 12w 左右的并发,也就是说没有打满,需要降低使用的线程数来测试,我们采用 2 个线程重新测试一下。

    • 先把测试进程减少到 2 个
    [nobody@tmp]$ ps -ef | grep test.php nobody 2200 1 0 7 月 22 ? 00:00:16 /usr/local/php-7.3.12/bin/php test.php nobody 9600 1 0 10:30 ? 00:00:00 /usr/local/php-7.3.12/bin/php test.php 
    • 测试:多跑几次,基本稳定在 136426.58 左右
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8888/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: swoole-http-server Server Hostname: 127.0.0.1 Server Port: 8888 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.733 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 16600000 bytes HTML transferred: 1300000 bytes Requests per second: 136426.58 [#/sec] (mean) Time per request: 7.330 [ms] (mean) Time per request: 0.007 [ms] (mean, across all concurrent requests) Transfer rate: 22116.03 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.2 0 43 Processing: 2 7 1.7 6 43 Waiting: 0 7 1.7 6 19 Total: 2 7 2.9 6 53 Percentage of the requests served within a certain time (ms) 

    Go 1.13.4 二次测试

    • 代码:修改为 2 个线程
    package main import ( "fmt" "net/http" "runtime" ) func main() { runtime.GOMAXPROCS(2) // 限制使用线程数 http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { writer.Write([]byte("hello, world!")) }) err := http.ListenAndServe(":9999", nil) if err != nil{ fmt.Println(err) } } 

    测试:多跑几次,基本稳定在 106834.75 左右,比 Swoole 性能低了 21.7%,证明 Swoole 确实性能是高于 Go 的 net 库。

    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9999/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: Server Hostname: 127.0.0.1 Server Port: 9999 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 0.936 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 15400000 bytes HTML transferred: 1300000 bytes Requests per second: 106834.75 [#/sec] (mean) Time per request: 9.360 [ms] (mean) Time per request: 0.009 [ms] (mean, across all concurrent requests) Transfer rate: 16066.95 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.5 0 21 Processing: 0 9 1.9 9 21 Waiting: 0 9 1.9 9 17 Total: 0 9 2.3 9 30 Percentage of the requests served within a certain time (ms) 

    MixPHP V2.2 二次测试

    • 先把测试进程减少到 2 个
    [nobody@tmp]$ ps -ef | grep mix.php nobody 7482 1 2 10:27 ? 00:00:05 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d nobody 27522 1 0 7 月 22 ? 00:00:35 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d 
    • 测试:多跑几次,基本稳定在 53856.21 左右,果然,按这个数据分析,之前 12 进程测试的数据不合理,因为 ab -c 1000 没有将 CPU 性能打满。
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9501/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: swoole-http-server Server Hostname: 127.0.0.1 Server Port: 9501 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 1.857 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 18100000 bytes HTML transferred: 1300000 bytes Requests per second: 53856.21 [#/sec] (mean) Time per request: 18.568 [ms] (mean) Time per request: 0.019 [ms] (mean, across all concurrent requests) Transfer rate: 9519.51 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.3 0 45 Processing: 0 18 5.5 17 46 Waiting: 0 18 5.5 17 38 Total: 0 18 5.6 17 55 Percentage of the requests served within a certain time (ms) 

    Beego V1.12.1

    • 代码:同样我们限制使用 2 个线程
    package main import ( "github.com/astaxie/beego" _ "hello/routers" "runtime" ) type IndexController struct { beego.Controller } func (c *IndexController) Index() { c.Ctx.Output.Body([]byte("hello, world!")) } func main() { runtime.GOMAXPROCS(2) // 限制使用线程数 beego.Router("/index", &IndexController{},"*:Index") beego.Run() } 
    • 测试:多跑几次,基本稳定在 54547.49 左右,与 Mix 非常接近。
    [nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8989/index This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Server Software: beegoServer:1.12.1 Server Hostname: 127.0.0.1 Server Port: 8989 Document Path: /index Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 1.833 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 18200000 bytes HTML transferred: 1300000 bytes Requests per second: 54547.49 [#/sec] (mean) Time per request: 18.333 [ms] (mean) Time per request: 0.018 [ms] (mean, across all concurrent requests) Transfer rate: 9694.96 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.9 0 31 Processing: 0 18 6.3 19 40 Waiting: 0 18 6.3 19 40 Total: 0 18 6.3 19 41 Percentage of the requests served within a certain time (ms) 

    总结一下

    • 第一次测试:由于 ab -c 1000 测试的性能没有把 CPU 打满,导致测试结果不公正,应该很多人会忽略这个问题,认为自己的框架性能很高,其实是没有打满。

    | 语言 /框架 | 进 /线程数 |数值 |
    | PHP 7.3.12 + Swoole 4.4.14 | 12 | 127441.95 |
    | Go 1.13.4 | 1 <12 线程> | 121575.23 |
    | PHP 7.3.12 + Swoole 4.4.14 + MixPHP 2.2 | 12 | 110050.47 |
    | Go 1.13.4 + Beego 1.12.1 | 12 | 107428.35 |

    • 第二次测试:采用 2 线程测试比较公正,能打满 CPU,这样出来的结果才是真实结果,Swoole 比 Go 性能高 21.7% (毕竟是 C 写的),Mix 比 Swoole 原生降低了 60.5% 的性能,而 Mix 大概是 Go 原生一半的性能,与 Beego 性能齐平。

    | 语言 /框架 | 进 /线程数 |数值 |
    | PHP 7.3.12 + Swoole 4.4.14 | 2 | 136426.58 |
    | Go 1.13.4 | 1 <2 线程> | 106834.75 |
    | PHP 7.3.12 + Swoole 4.4.14 + MixPHP 2.2 | 2 | 53856.21 |
    | Go 1.13.4 + Beego 1.12.1 | 2 | 54547.49 |

    第 1 条附言    2020-07-25 19:42:39 +08:00
    53 条回复    2020-07-28 15:23:28 +08:00
    onanying
        1
    onanying  
    OP
       2020-07-25 10:08:22 +08:00
    v2ex 只能发送 20000 个字符,也是醉了,只能删除一些内容
    bazingaterry
        2
    bazingaterry  
       2020-07-25 10:11:19 +08:00
    loading
        3
    loading  
       2020-07-25 10:15:48 +08:00
    一个结论:beego 性能差,doge.
    onanying
        4
    onanying  
    OP
       2020-07-25 10:16:07 +08:00
    @bazingaterry fasthttp 肯定更强,但是这里的表达的观点的是 PHP 没那么弱 (在 IO 方面)
    blless
        5
    blless  
       2020-07-25 10:25:01 +08:00 via Android   1
    helloworld 有啥用,整点正常玩意啊,来个最简单的 curd 也成啊,然后就知道所谓的动态语言跑 benchmark 都什么德性了
    onanying
        6
    onanying  
    OP
       2020-07-25 10:29:18 +08:00
    @blless 不要轻易下结论,如果性能趋同如何?我打赌 10 块,Mix 一样拥有连接池,协程特性,既然你提了,我费力今天写一个 db 查询的。
    alexkkaa
        7
    alexkkaa  
       2020-07-25 10:31:00 +08:00 via Android   1
    这种测试完全就是搞笑,就跟一个 hello world 说明一个语言好坏一样。go 是完全异步的,swoole 之类的只是这个库本身异步,巨量的第三方库甚至 php 自带的标准库很多都废了。类似 python 的 gevent 来个 monkey patch 这种手段也只是治标不治本 谁知道什么地方会有坑等着你。go 第三方库就就不存在这个问题因为人家是语言级的异步。第三方库就不存在这个问题。 要不然为什么 c#用了 async 后标准库里要整那么多 async 开头的方法
    virusdefender
        8
    virusdefender  
       2020-07-25 10:32:51 +08:00
    ab 和 server 同一台机器可能影响结果,建议分开,另外现在一般都用 wrk 了吧
    onanying
        9
    onanying  
    OP
       2020-07-25 10:35:52 +08:00
    @alexkkaa 你这种喷生态的,还算是喷的有点道理,喷查询性能的那是真外行
    onanying
        10
    onanying  
    OP
       2020-07-25 10:38:21 +08:00
    @alexkkaa 我开发了 20 几个库处理这些问题,常用的 mysql + redis 么有问题,基于 guzzle 开发的库也没有问题,只能说常用第三方的生态都被改造支持异步了,冷门一些的就确实支持不太好。
    alexkkaa
        11
    alexkkaa  
       2020-07-25 10:41:04 +08:00 via Android
    @onanying 这个得标准库支持才有意义,像.net 标准库里增加了很多异步方法,相应的社区第三方库也会使用这些自带的方法。 标准库不支持生态就起不来
    onanying
        12
    onanying  
    OP
       2020-07-25 10:41:31 +08:00
    @alexkkaa 还有一点和 py c# 不同的是 php composer 的包都还能用(但是不支持异步了,在调用的那一段时间,但是执行结果完全不受影响,只是影响整体并发性能),这与 py3 和 c# 的生态不兼容的问题完全不同。
    onanying
        13
    onanying  
    OP
       2020-07-25 10:44:02 +08:00
    @alexkkaa 所以说这个并不会适合普罗大众,但是有能力的团队都能 hold 住。当然方案有很多种比如我正在开发的 mix-go
    alexkkaa
        14
    alexkkaa  
       2020-07-25 10:45:40 +08:00 via Android
    @onanying 但是有能力的团队为什么不直接上 go 呢,这不是隔靴搔痒吗
    alexkkaa
        15
    alexkkaa  
       2020-07-25 10:46:33 +08:00 via Android
    我不是抬杠只是被这类坑过 发发感慨 哈
    onanying
        16
    onanying  
    OP
       2020-07-25 10:46:38 +08:00
    @virusdefender 同样的环境,即便你说的有道理,影响的结果不会很大,这个是多次测试的均值。并且每次执行数值差异非常小。这台测试机器也没有做其他用途。
    onanying
        17
    onanying  
    OP
       2020-07-25 10:50:30 +08:00
    @alexkkaa 20000+ rmb 的 php (同时会 go) 30000+ rmb 的 go (php 很烂) 你自己算吧,有了框架 15000+ 的 php 都能写。 同时 mix-go 和 mix-php 用法与设计架构完全一样,15000+ 的 php 同时还能写 go 。你自己算算这个账单吧。
    dvaknheo
        18
    dvaknheo  
       2020-07-25 11:06:43 +08:00
    @onanying 所以,看见没,去学 go 啊,同学们,学 PHP 没钱途啊!
    blless
        19
    blless  
       2020-07-25 11:07:57 +08:00   2
    @onanying 6# 你写呗 ,到时候贴个付款码就行 我跟了。很多人还是一厢情愿认为 IO 密集跟计算能力关系不大,我之前在公司内部也写过框架。除了网络 IO 以外,消耗大的还有数据序列化跟反序列化这一步,数据量越大越明显,甚至很有可能大量 CPU 都消耗在这个步骤。就光加一个序列化我估计 php,python 之流的 benchmark 就直接掉一个档次。
    guanhui07
        20
    guanhui07  
       2020-07-25 11:09:51 +08:00
    @blless 后端业务常用的就 mysql redis 还有 curl 文件操作等 ,swoole4 已经完美支持了 同步写法,异步执行,swoole 也有了协程 ,常驻内存+协程,确实性能可以媲美 golang 了
    agui2200
        21
    agui2200  
       2020-07-25 11:15:03 +08:00
    @blless 别说这个了,直接上个 RSA,php 就得贴地板,以前测试过,这块运算效率大概 java 是 php 的 X 倍吧...现在低一点,但还是快 X*50%倍吧最少?
    agui2200
        22
    agui2200  
       2020-07-25 11:17:49 +08:00
    再补一刀,有个事情就想不明了,swoole 都学会了,go 学不会?
    dvaknheo
        23
    dvaknheo  
       2020-07-25 11:19:37 +08:00
    @guanhui07
    假设有这么个第三方库的方法。Good Luck.

    public function getConfigsCached()
    {
    static $configs;
    if (!isset($configs)) {
    $cOnfigs= $this->getConfigsByDatabase();
    }
    return $configs;
    }

    复杂一点是 getUserCached($id); 我就不写了。
    也就是 @alexkkaa 说的巨量的第三方库甚至 php 自带的标准库很多都废了
    mitu9527
        24
    mitu9527  
       2020-07-25 11:28:43 +08:00
    整天搞语言之争、性能之争,你们累不累?是有多自卑,还是虚荣心这么强?

    也难怪国外程序员嘲笑国内程序员菜,总想站在巨人的肩膀上,然后天天换肩膀,不菜就怪了。

    13 年到 18 年国内互联网行业大跃进,浮夸之风盛行,各种对比(语言、性能等等)和名头(大数据、高并发、架构师等等)就都来了。19 年开始经济形势下滑了,而且未来几年也大概率继续下滑,你们还没冷静下来么?

    风口过了,留下了一群惊慌失措的人在争吵。
    alexkkaa
        25
    alexkkaa  
       2020-07-25 11:38:27 +08:00 via Android   2
    @mitu9527 要是没有争辩没有不满意技术怎么进步? 新技术的出现不就是因为不满意旧技术吗? 至于你说的那些个 ppt 对比这个大多是 kpi 或者说任务导向的。 没有对 java 的不满,哪来的它的那些亲儿子? 没有对 dotnet 的不满哪来的 dotnet core ?没有对 c++的不满哪来的 rust? 没有对跨平台的不满哪来的 flutter?
    技术的进步不仅提高了生产效率还缩减了生产成本。我们的项目原先需要十多台高配服务器,换了技术只需要三台就够了。每个月节省上万块,不香吗? 而且开发部署更高效流畅
    hronro
        26
    hronro  
       2020-07-25 11:44:40 +08:00 via iPhone
    直接在 Tech Empower 上看测试结果就好了,没必要自己费力写测试
    https://www.techempower.com/benchmarks/
    dvaknheo
        27
    dvaknheo  
       2020-07-25 11:49:55 +08:00
    @mitu9527 三哥程序员不一定比中国程序员强哦。只是中国程序员不会和外国程序员沟通而已。 基于 swoole 的 php 框架。 哪个老外可以和 mixphp 叫板的?
    mitu9527
        28
    mitu9527  
       2020-07-25 11:53:03 +08:00
    @alexkkaa 你看看你的回复,涵盖了多少种争论了,你是有多关注这些争论的话题啊?你好好争,我不拦你。
    sagaxu
        29
    sagaxu  
       2020-07-25 11:59:08 +08:00 via Android   1
    go 框架是 go 写的,swoole 是 C 写的,整个测试中大部分逻辑是框架完成的,本质是 Go vs C 。这类 micro benchmark,说是框架加配置文件也不为过,并不能体现真实应用的性能。

    随着业务逻辑代码的膨胀,语言本身的性能劣势慢慢凸显,这才真正开始考验性能。

    对于一般公司,比性能更重要的是生态,Swoole 生态一直没法跟 Go 相提并论。不过随着大家集中到 hyperf 之后,这方面差距也在慢慢缩小。
    fengyj
        30
    fengyj  
       2020-07-25 12:18:21 +08:00
    着重现实,现在 php 的岗位越来越少了,go 倒是变多,很多公司 php 开始往 go 重构了。
    即使 php 比 go 性能高那么一丢丢,也不是选 php 的关键吧,那么在意性能,rust 框架不更好?
    roundgis
        31
    roundgis  
       2020-07-25 12:23:14 +08:00   1
    言如果在框架跑分上 go

    通常是因些框架是用 c 的

    最後演 c vs go

    Go 都有宣快 C
    Varobjs
        32
    Varobjs  
       2020-07-25 12:42:32 +08:00 via Android
    @sagaxu 确实啊
    很多项目,优化优化里面的慢查询带来的提升远大于语言的性能提升
    paoqi2048
        33
    paoqi2048  
       2020-07-25 14:06:01 +08:00
    楼上太孝顺了
    C603H6r18Q1mSP9N
        34
    C603H6r18Q1mSP9N  
       2020-07-25 14:36:41 +08:00
    php 本身性能不差,楼主可以测试一个数据库 select,这个是瓶颈
    ajaxfunction
        35
    ajaxfunction  
       2020-07-25 16:38:27 +08:00   2
    你没测的时候,说性能不行,你测了又说生态不行,之后还会说查询 db 不行,接着还会说序列化不行, 到最后又说扩展是 C 写的是 C 厉害, 总之动态语言就是不行
    ben1024
        36
    ben1024  
       2020-07-25 17:46:30 +08:00
    带上有色眼镜看啥都不行,PHP 的后力薄弱,前期使用很舒服。
    swoole 说是要进行阉割并入 PHP,这个到是期待
    dbskcnc
        37
    dbskcnc  
       2020-07-25 18:00:26 +08:00
    最终还是业务,满足了业务谁管你什么语言,动态语言谈性能显然不太合适,不过一般情况下其实也都能凑合就是了,绝大部分的系统的 qps 就那点,用哪个好像差别也还没有那么大,但是上限是不同的
    barbery
        38
    barbery  
       2020-07-25 18:29:21 +08:00
    之前做了一款游戏,后端用的也是 swoole 的框架,不得不说,swoole 的高性能生态还有待完善,很多第三方包都是基于 fpm 的,但是整体高性能趋势是向好的,坚定看好 swoole 这个方向
        39
    feelinglucky  
       2020-07-25 18:48:47 +08:00
    @onanying “这里的表达的观点的是 PHP 没那么弱”,感觉已经预设立场的测试中立性存疑
    luozic
        40
    luozic  
       2020-07-25 19:45:06 +08:00 via iPhone
    跑这种为啥不去试试几个典型的 benchmark 库? 可以和 c# Java kotlin 比较比较,反正这个从来没说比 c 快
    onanying
        41
    onanying  
    OP
       2020-07-25 19:45:18 +08:00
    @blless 我写了新的测试,是数据库+序列化,测试结果确实是 beego 性能更好,愿赌服输,你给一下付款码吧,测试链接: t/693083
    chenqh
        42
    chenqh  
       2020-07-25 19:50:57 +08:00
    @barbery 你这话说的,我都想学 php 了,哎
    wangbenjun5
        43
    wangbenjun5  
       2020-07-25 21:42:59 +08:00
    一句话,用 swoole 还不如直接用 go,不解释
    lowe
        44
    lowe  
       2020-07-25 21:48:46 +08:00
    go 的鲁棒性不是 swoole 能比的
    drackzy
        45
    drackzy  
       2020-07-25 22:05:32 +08:00
    go 国内大厂基本都用 gin
    meshell
        46
    meshell  
       2020-07-25 23:20:45 +08:00
    @drackzy 我发现 fiber 也很好用。性能方面还比 gin 好。
    p1gd0g
        47
    p1gd0g  
       2020-07-25 23:46:52 +08:00
    俺们公司的实际情况就是 php 重构到 go,省了十多台服务器。
    但是欣赏 lz 的研究精神,多一些这种帖子肯定是件好事。
    blless
        48
    blless  
       2020-07-25 23:47:03 +08:00 via Android
    @onanying #41 付款码就不必啦,楼主还肯花时间写挺不容易的。
    lxml
        49
    lxml  
       2020-07-25 23:53:03 +08:00 via Android
    直觉上 PHP 无论怎么优化都干不过 Go,动态语言这方面确实不行,这个跟 PHP 优劣没关系,是开发效率运行效率编译效率权衡后的取舍,go 异步独步武林,这方面真没必要硬刚。
    onanying
        50
    onanying  
    OP
       2020-07-26 00:02:03 +08:00
    @lxml 硬刚下来结果也还可以了,但是比我预想的要差一些,我预想是和 beego 差不多的,测试结果 mix 比 beego 数据库查询+序列化的综合性能要低 38.3%,附言那里有链接。
    www5070504
        51
    www5070504  
       2020-07-26 09:41:00 +08:00
    这种方法能测出啥实质吗
    barbery
        52
    barbery  
       2020-07-26 17:50:40 +08:00
    @chenqh 哈哈,语言只是工具,适合自己就好
    phpnote
        53
    phpnote  
       2020-07-28 15:23:28 +08:00
    这难道不是 Golang vs C 么?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2972 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 37ms UTC 00:21 PVG 08:21 LAX 17:21 JFK 20:21
    Do have faith in what you're doing.
    ubao 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