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

前端之家收集整理的这篇文章主要介绍了关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前我安装的 Homestead 虚拟机版本是 2.1.8:
该版本 Homestead 上预装的 PHP 版本是 5.6.15:
我们使用 ab 命令(Apache 提供的性能测试工具)在该版本中测试 Laravel 应用(以目前正在讲的使用Laravel开发的博客应用为例)性能,我们模拟 10000 次请求,100 个并发进行压力测试:
  1. ab -n 10000 -c 100 http://blog.app/

  @H_404_22@

  1.  
运行结果如下:
  1. This is ApacheBench,Version 2.3
  2.  
  3. Copyright 1996 Adam Twiss,Zeus Technology Ltd,http://www.zeustech.net/
  4.  
  5. Licensed to The Apache Software Foundation,http://www.apache.org/
  6.  
  7.  
  8. Benchmarking blog.app (be patient)
  9.  
  10. Completed 1000 requests
  11.  
  12. Completed 2000 requests
  13.  
  14. Completed 3000 requests
  15.  
  16. Completed 4000 requests
  17.  
  18. Completed 5000 requests
  19.  
  20. Completed 6000 requests
  21.  
  22. Completed 7000 requests
  23.  
  24. Completed 8000 requests
  25.  
  26. Completed 9000 requests
  27.  
  28. Completed 10000 requests
  29.  
  30. Finished 10000 requests
  31.  
  32. Server Software: Nginx/1.8.0
  33.  
  34. Server Hostname: blog.app
  35.  
  36. Server Port: 80
  37.  
  38.  
  39. Document Path: /
  40.  
  41. Document Length: 324 bytes
  42.  
  43.  
  44. Concurrency Level: 100
  45.  
  46. Time taken for tests: 69.354 seconds
  47.  
  48. Complete requests: 10000
  49.  
  50. Failed requests: 0
  51.  
  52. Total transferred: 19851388 bytes
  53.  
  54. HTML transferred: 10230000 bytes
  55.  
  56. Requests per second: 144.19 [#/sec] (mean)
  57.  
  58. Time per request: 693.545 [ms] (mean)
  59.  
  60. Time per request: 6.935 [ms] (mean,across all concurrent requests)
  61.  
  62. Transfer rate: 279.52 [Kbytes/sec] received
  63.  
  64.  
  65. Connection Times (ms)
  66.  
  67. min mean[+/-sd] median max
  68.  
  69. Connect: 0 0 0.2 0 3
  70.  
  71. Processing: 17 684 319.1 588 2720
  72.  
  73. Waiting: 17 684 319.1 588 2720
  74.  
  75. Total: 20 684 319.1 588 2720
  76.  
  77.  
  78. Percentage of the requests served within a certain time (ms)
  79.  
  80. 50% 588
  81.  
  82. 66% 695
  83.  
  84. 75% 842
  85.  
  86. 80% 933
  87.  
  88. 90% 1155
  89.  
  90. 95% 1321
  91.  
  92. 98% 1545
  93.  
  94. 99% 1813
  95.  
  96. 100% 2720 (longest request)

  @H_404_22@

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

  @H_404_22@

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

  @H_404_22@

  1.  
运行结果如下:
  1. This is ApacheBench,Version 2.3
  2. Copyright 1996 Adam Twiss,http://www.zeustech.net/
  3. Licensed to The Apache Software Foundation,http://www.apache.org/
  4. Benchmarking blog.app (be patient)
  5. Completed 1000 requests
  6. Completed 2000 requests
  7. Completed 3000 requests
  8. Completed 4000 requests
  9. Completed 5000 requests
  10. Completed 6000 requests
  11. Completed 7000 requests
  12. Completed 8000 requests
  13. Completed 9000 requests
  14. Completed 10000 requests
  15. Finished 10000 requests
  16. Server Software: Nginx/1.8.0
  17. Server Hostname: blog.app
  18. Server Port: 80
  19. Document Path: /
  20. Document Length: 324 bytes
  21. Concurrency Level: 100
  22. Time taken for tests: 45.032 seconds
  23. Complete requests: 10000
  24. Failed requests: 0
  25. Total transferred: 20101202 bytes
  26. HTML transferred: 10230000 bytes
  27. Requests per second: 222.06 [#/sec] (mean)
  28. Time per request: 450.319 [ms] (mean)
  29. Time per request: 4.503 [ms] (mean,across all concurrent requests)
  30. Transfer rate: 435.91 [Kbytes/sec] received
  31. Connection Times (ms)
  32. min mean[+/-sd] median max
  33. Connect: 0 0 0.2 0 4
  34. Processing: 11 443 252.8 379 1978
  35. Waiting: 11 443 252.8 379 1978
  36. Total: 15 443 252.8 379 1978
  37. Percentage of the requests served within a certain time (ms)
  38. 50% 379
  39. 66% 517
  40. 75% 590
  41. 80% 631
  42. 90% 795
  43. 95% 938
  44. 98% 1060
  45. 99% 1229
  46. 100% 1978 (longest request)

  @H_404_22@

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

 @H_404_22@



@H_404_22@

猜你在找的Laravel相关文章