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)
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 22
JaguarJack

这是干嘛的 这么低?octane

1年前 评论
skarner (楼主) 1年前
skarner (楼主) 1年前
GDDD

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

1年前 评论
skarner (楼主) 1年前
fatrbaby

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

1年前 评论
JaguarJack 1年前
mengmeng_phper 1年前
skarner (楼主) 1年前

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

1年前 评论
skarner (楼主) 1年前

那么,该怎么选!

1年前 评论
skarner (楼主) 1年前
不负岁月 (作者) 1年前
skarner (楼主) 1年前

webman 和 laravel octane 进程数分别多少

1年前 评论
skarner (楼主) 1年前

第一: ab 测我感觉不准

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

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

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

1年前 评论
skarner (楼主) 1年前

可以再试试 hyperf

1年前 评论

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

1年前 评论

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

1年前 评论