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

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

概述目前我安装的 Homestead 虚拟机版本是 2.1.8: 该版本 Homestead 上预装的 PHP 版本是 5.6.15: 我们使用 ab 命令(Apache 提供的性能测试工具)在该版本中测 目前我安装的 Homestead 虚拟机版本是 2.1.8:该版本 Homestead 上预装的 PHP 版本是 5.6.15:我们使用 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 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software: Nginx/1.8.0Server Hostname: blog.appServer Port: 80 document Path: /document Length: 324 bytes Concurrency Level: 100Time taken for tests: 69.354 secondsComplete requests: 10000Failed requests: 0Total transferred: 19851388 bytesHTML transferred: 10230000 bytesRequests 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  maxConnect:       0       0     0.2                 0      3Processing: 17    684   319.1           588   2720Waiting:      17     684   319.1           588   2720Total:          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 版本信息是否正确:此时在浏览器中访问 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,http://www.zeustech.net/licensed to The Apache Software Foundation,http://www.apache.org/ Benchmarking blog.app (be patIEnt)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software: Nginx/1.8.0Server Hostname: blog.appServer Port: 80 document Path: /document Length: 324 bytes Concurrency Level: 100Time taken for tests: 45.032 secondsComplete requests: 10000Failed requests: 0Total transferred: 20101202 bytesHTML transferred: 10230000 bytesRequests 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   maxConnect:       0       0     0.2                 0       4Processing: 11    443   252.8           379   1978Waiting:      11     443   252.8           379   1978Total:          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%,这是一个很显著的性能提升,当然环境不同数据会有所出入,而且还有更大的提升空间。

 

更多学习内容请访问:

腾讯T3-T4标准精品PHP架构师教程目录大全,只要你看完保证薪资上升一个台阶(持续更新)​ 



总结

以上是内存溢出为你收集整理的关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解全部内容,希望文章能够帮你解决关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1240549.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存