laravel迁移服务器_关于PHP7.0与PHP5.6下Laravel博客应用性能对比分析详解

目前我安装的 Homestead 虚拟机版本是 2.1.8:

a7b8db1b244e6cd3d40d58510bf4cafb.png

该版本 Homestead 上预装的 PHP 版本是 5.6.15:

44a754408773d45bd9e8b80f2c315fdf.png

我们使用 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 版本信息是否正确:

ed7b6f987e31ce1d2ea57ccad440973a.png

此时在浏览器中访问 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%,这是一个很显著的性能提升,当然环境不同数据会有所出入,而且还有更大的提升空间。

更多学习内容请访问:

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

以上内容希望帮助到大家,很多PHPer在进阶的时候总会遇到一些问题和瓶颈,业务代码写多了没有方向感,不知道该从那里入手去提升,对此我整理了一些资料,包括但不限于:分布式架构、高可扩展、高性能、高并发、服务器性能调优、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql优化、shell脚本、Docker、微服务、Nginx等多个知识点高级进阶干货需要的可以免费分享给大家,需要的可以加入我的官方群点击此处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值