laravel-fpm、laravel-octane、webman性能对比

性能讨论

我之前认为 laravel-octane 性能和 webman 应该在同一个数量级,没想到差距这么大
大家怎么看呢

说明

  • 配置: 12核8G

  • 运行环境: Docker

  • 测试方式: 请求直接返回Json

  • PHP版本: 8.2 (未开启opcache)

  • Laravel版本: 10.42.0 (未做任何优化)

  • 测试方法: 请求直接返回 hello world

laravel-fpm

附上php-fpm的配置

pm = dynamic
pm.max_children = 200
pm.start_servers = 50
pm.min_spare_servers = 20
pm.max_spare_servers = 200

ab -n 10000 -c 1000 测试结果如下

ab -n 10000 -c 1000 http://localhost:80/hello
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
^@Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.25.3
Server Hostname:        localhost
Server Port:            80

Document Path:          /hello
Document Length:        33 bytes

Concurrency Level:      1000
Time taken for tests:   80.732 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      12210000 bytes
HTML transferred:       330000 bytes
Requests per second:    123.87 [#/sec] (mean)
Time per request:       8073.239 [ms] (mean)
Time per request:       8.073 [ms] (mean, across all concurrent requests)
Transfer rate:          147.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   6.4      0      28
Processing:    84 7735 1590.4   7859   17599
Waiting:       56 7735 1590.4   7859   17599
Total:         84 7737 1586.4   7859   17599

Percentage of the requests served within a certain time (ms)
  50%   7859
  66%   8002
  75%   8107
  80%   8182
  90%   8419
  95%   8709
  98%   9222
  99%  15093
 100%  17599 (longest request)

laravel-octane

ab -n 10000 -c 1000 测试结果如下

ab -n 10000 -c 1000 http://localhost:8000/hello
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        33 bytes

Concurrency Level:      1000
Time taken for tests:   26.674 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      10540000 bytes
HTML transferred:       330000 bytes
Requests per second:    374.90 [#/sec] (mean)
Time per request:       2667.369 [ms] (mean)
Time per request:       2.667 [ms] (mean, across all concurrent requests)
Transfer rate:          385.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   6.3      0      28
Processing:    12 2519 610.6   2651    3657
Waiting:        3 2517 609.7   2651    3657
Total:         31 2521 604.6   2651    3657

Percentage of the requests served within a certain time (ms)
  50%   2651
  66%   2657
  75%   2661
  80%   2665
  90%   3082
  95%   3119
  98%   3134
  99%   3140
 100%   3657 (longest request)

webman

ab -n 10000 -c 1000 测试结果如下

ab -n 10000 -c 1000 http://localhost:8001/hello
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        workerman
Server Hostname:        localhost
Server Port:            8001

Document Path:          /hello
Document Length:        33 bytes

Concurrency Level:      1000
Time taken for tests:   0.625 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1470000 bytes
HTML transferred:       330000 bytes
Requests per second:    16009.27 [#/sec] (mean)
Time per request:       62.464 [ms] (mean)
Time per request:       0.062 [ms] (mean, across all concurrent requests)
Transfer rate:          2298.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   24   7.1     25      39
Processing:     7   35  23.0     29     140
Waiting:        1   27  23.6     20     126
Total:         29   59  18.9     55     155

Percentage of the requests served within a certain time (ms)
  50%     55
  66%     56
  75%     57
  80%     58
  90%    101
  95%    113
  98%    118
  99%    124
 100%    155 (longest request)
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 22
JaguarJack

这是干嘛的 这么低?octane

3个月前 评论
skarner (楼主) 3个月前
skarner (楼主) 3个月前
GDDD

webman用的人都说真香,你还在这压测对比

3个月前 评论
skarner (楼主) 3个月前
fatrbaby

webman核心的代码质量如果能达到Laravel的水准,甚至达到Symfony的水准,我立马跪下来叫爸爸

3个月前 评论
JaguarJack 3个月前
mengmeng_phper 3个月前
skarner (楼主) 3个月前

咋感觉不太相信,你octane用的哪个,swoole还是

3个月前 评论
skarner (楼主) 3个月前

那么,该怎么选!

3个月前 评论
skarner (楼主) 3个月前
不负岁月 (作者) 3个月前
skarner (楼主) 3个月前

webman 和 laravel octane 进程数分别多少

3个月前 评论
skarner (楼主) 3个月前

第一: ab测我感觉不准

第二:fpm模式配置可以改成static

第三:opcache 以及laravel优化都要开,毕竟除了fpm其他都是内存型的

第四:可以考虑io阻塞问题

3个月前 评论
skarner (楼主) 3个月前

可以再试试hyperf

3个月前 评论

这个测试没意义,要考虑框架初始化时候都干了什么,只输出 hello world 那就需要做优化

2个月前 评论

webman的确快,不过最终差距没有这么大,最大的优点是webman占用负载情况远完小于fpm fpm压测负载就100了,webman 50%左右, 另外我现在的同一套代码同时运行在webman与laravel. 在webman引用了laravel的orm,cache,auth,在laravel下面建个目录放webman,webman读取laravel的env配置,并运行laravel的业务部分代码,以实现只须要在laravel下面写代码,同时可在webman中运行,对须要高并发的就通过ngixn把业务转发到webman下面,

2个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!