欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解

程序员文章站 2022-03-08 12:31:20
目前我安装的 Homestead 虚拟机版本是 2.1.8: 该版本 Homestead 上预装的 PHP 版本是 5.6.15: 我们使用 ab 命令(Apache 提供的性能测试工具)在该版本中测试 Laravel 应用(以目前正在讲的使用Laravel开发的博客应用为例)性能,我们模拟 100 ......
目前我安装的 homestead 虚拟机版本是 2.1.8:
关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解
该版本 homestead 上预装的 php 版本是 5.6.15:
关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解
我们使用 ab 命令(apache 提供的性能测试工具)在该版本中测试 laravel 应用(以目前正在讲的使用laravel开发的博客应用为例)性能,我们模拟 10000 次请求,100 个并发进行压力测试:
ab -n 10000 -c 100 http://blog.app/

  

 
运行结果如下:
this is apachebench, version 2.3 

copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/

licensed to the apache software foundation, http://www.apache.org/

 

benchmarking blog.app (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.8.0

server hostname: blog.app

server port: 80

 

document path: /

document length: 324 bytes

 

concurrency level: 100

time taken for tests: 69.354 seconds

complete requests: 10000

failed requests: 0

total transferred: 19851388 bytes

html transferred: 10230000 bytes

requests per second: 144.19 [#/sec] (mean)

time per request: 693.545 [ms] (mean)

time per request: 6.935 [ms] (mean, across all concurrent requests)

transfer rate: 279.52 [kbytes/sec] received

 

connection times (ms)

                  min  mean[+/-sd]  median  max

connect:       0       0     0.2                 0      3

processing: 17    684   319.1           588   2720

waiting:      17     684   319.1           588   2720

total:          20     684   319.1           588   2720

 

percentage of the requests served within a certain time (ms)

 50%      588

 66%      695

 75%      842

 80%      933

 90%    1155

 95%    1321

 98%    1545

 99%    1813

 100%  2720 (longest request)

  

 
这里我们要关注的是红色加粗的文字,即每秒处理请求数,这是衡量系统性能的关键指标。根据系统及硬件配置的差异,数据会有些出入。
现在我们按照“laravel homestead 支持 php 7 ”这一节所述将 homestead 中的 php 升级到 7.0 版本。
使用 vagrant ssh 登录到新添加的 homestead-7 虚拟机,查看 php 版本信息是否正确:
关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解
此时在浏览器中访问 http://blog.app 会报错,因为新安装的 homestead 数据库数据为空,需要登录到虚拟机运行如下命令运行迁移并填充数据:
php artisan migrate 

php artisan db:seed

  

 
再次访问就ok了,好了我们继续使用同样的 ab 命令进行压力测试:
ab -n 10000 -c 100 http://blog.app/ 

  

 
运行结果如下:
this is apachebench, version 2.3 
copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/
licensed to the apache software foundation, http://www.apache.org/
 
benchmarking blog.app (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.8.0
server hostname: blog.app
server port: 80
 
document path: /
document length: 324 bytes
 
concurrency level: 100
time taken for tests: 45.032 seconds
complete requests: 10000
failed requests: 0
total transferred: 20101202 bytes
html transferred: 10230000 bytes
requests per second: 222.06 [#/sec] (mean)
time per request: 450.319 [ms] (mean)
time per request: 4.503 [ms] (mean, across all concurrent requests)
transfer rate: 435.91 [kbytes/sec] received
 
connection times (ms)
 min  mean[+/-sd]  median   max
connect:       0       0     0.2                 0       4
processing: 11    443   252.8           379   1978
waiting:      11     443   252.8           379   1978
total:          15     443   252.8           379   1978
 
percentage of the requests served within a certain time (ms)
 50%      379
 66%      517
 75%      590
 80%      631
 90%      795
 95%      938
 98%    1060
 99%    1229
 100%  1978 (longest request)

  

经过对比,同一个 laravel 应用在 php 7.0 下的性能比 php 5.6 提高了54%,这是一个很显著的性能提升,当然环境不同数据会有所出入,而且还有更大的提升空间。