laravel核心Laravel

laravel 5.1 性能优化对比 - 框架提供的方法

2015-09-03  本文已影响4864人  多厘

写了一个项目发现性能不如人意. 于是便测试下, 看下性能瓶颈在什么地方. 使用 ab -n 20 http://www.lartest.com/

软件环境:

OS : windows 8.1
CPU: i3 2.4G
disk: 7200 st 500G
Server : Apache/2.4.9
PHP : PHP 7.0.0RC1
框架: Laravel 5.1
路由数量 : 273

测试 1 : 未开启优化

app_debug : true
php artisan route:cache : false
php artisan optimize –-force : false

Concurrency Level:      1
Time taken for tests:   8.561 seconds
Complete requests:      20
Failed requests:        0
Total transferred:      94976 bytes
HTML transferred:       73080 bytes
Requests per second:    2.34 [#/sec] (mean)
Time per request:       428.033 [ms] (mean)
Time per request:       428.033 [ms] (mean, across all concurrent requests)
Transfer rate:          10.83 [Kbytes/sec] received

测试 2 : 开启性能优化, 未优化 Laravel 内置方法

app_debug : false
php artisan route:cache : false
php artisan optimize –-force : false

Concurrency Level:      1
Time taken for tests:   7.048 seconds
Complete requests:      20
Failed requests:        0
Total transferred:      93576 bytes
HTML transferred:       73080 bytes
Requests per second:    2.84 [#/sec] (mean)
Time per request:       352.383 [ms] (mean)
Time per request:       352.383 [ms] (mean, across all concurrent requests)
Transfer rate:          12.97 [Kbytes/sec] received

测试3: 优化完毕

app_debug : false
php artisan route:cache : true
php artisan optimize : true

Concurrency Level:      1
Time taken for tests:   5.822 seconds
Complete requests:      20
Failed requests:        0
Total transferred:      93562 bytes
HTML transferred:       73080 bytes
Requests per second:    3.44 [#/sec] (mean)
Time per request:       291.092 [ms] (mean)
Time per request:       291.092 [ms] (mean, across all concurrent requests)
Transfer rate:          15.69 [Kbytes/sec] received

看起来性能还没有达到我的标准, 还是慢

2015年9月4日:
找了一台服务器: CentOS 7, 4核, 8G, 4M , apache 2.4, php5.6 经过优化过后性能如下

Concurrency Level:      1
Time taken for tests:   0.844 seconds
Complete requests:      20
Failed requests:        0
Total transferred:      93422 bytes
HTML transferred:       73420 bytes
Requests per second:    23.71 [#/sec] (mean)
Time per request:       42.179 [ms] (mean)
Time per request:       42.179 [ms] (mean, across all concurrent requests)
Transfer rate:          108.15 [Kbytes/sec] received

让自己机器慢的可能是自己, 而不是别人.

参考文章 :

上一篇下一篇

猜你喜欢

热点阅读