2016-07-21 66 views
3

我已经安装了一个Ubuntu的14.04与PHP 5.5和Apache 2.4。Laravel 5.2高CPU与长路由

我安装了一个新鲜的laravel 5.2。项目中没有数据库连接。

我然后当到APP/HTTP/routes.php文件和编辑,以:

Route::get('/', function() { 
    return view('welcome'); 
}); 


Route::get('/test/direct', function() { 
    return view('welcome'); 
}); 

所以基本上我有2个路由只是表示欢迎视图。

我然后运行:

ab -n 9999999 -t 300 -c 30 http://xxxxx/laravel52/public 

CPU的永远不会超过6%,我得到下面的结果:立即

ab -n 9999999 -t 300 -c 30 http://xxxxx/laravel52/public/test/direct 

的CPU:

Server Software:  Apache/2.4.7 
Server Hostname:  xxxxx 
Server Port:   80 

Document Path:   /laravel52/public 
Document Length:  328 bytes 

Concurrency Level:  30 
Time taken for tests: 146.271 seconds 
Complete requests:  50000 
Failed requests:  0 
Non-2xx responses:  50000 
Total transferred:  28550000 bytes 
HTML transferred:  16400000 bytes 
Requests per second: 341.83 [#/sec] (mean) 
Time per request:  87.763 [ms] (mean) 
Time per request:  2.925 [ms] (mean, across all concurrent requests) 
Transfer rate:   190.61 [Kbytes/sec] received 

Connection Times (ms) 
       min mean[+/-sd] median max 
Connect:  15 47 77.0  40 3157 
Processing: 17 41 28.1  37 2140 
Waiting:  17 40 26.9  37 2140 
Total:   40 87 84.3  78 3208 

Percentage of the requests served within a certain time (ms) 
    50%  78 
    66%  83 
    75%  86 
    80%  89 
    90% 100 
    95% 120 
    98% 162 
    99% 228 
100% 3208 (longest request) 

我然后运行上升到100%,最后我得到这些结果:

Server Software:  Apache/2.4.7 
Server Hostname:  xxxxx 
Server Port:   80 

Document Path:   /laravel52/public/test/direct 
Document Length:  1023 bytes 

Concurrency Level:  30 
Time taken for tests: 300.001 seconds 
Complete requests:  11888 
Failed requests:  0 
Total transferred:  24585740 bytes 
HTML transferred:  12161424 bytes 
Requests per second: 39.63 [#/sec] (mean) 
Time per request:  757.070 [ms] (mean) 
Time per request:  25.236 [ms] (mean, across all concurrent requests) 
Transfer rate:   80.03 [Kbytes/sec] received 

Connection Times (ms) 
       min mean[+/-sd] median max 
Connect:  4 12 29.4  8 1020 
Processing: 75 740 790.0 609 14045 
Waiting:  74 738 789.9 608 14043 
Total:   88 752 789.4 622 14050 

Percentage of the requests served within a certain time (ms) 
    50% 622 
    66% 835 
    75% 952 
    80% 1020 
    90% 1237 
    95% 1536 
    98% 2178 
    99% 2901 
100% 14050 (longest request) 

看来,如果不是根路径laravel尖峰的CPU,如果有很多连接。这也发生在laravel 4.2中的全新安装。

任何人都可以指出为什么会发生这种情况?我真的需要解决这个问题。

我的服务器有8核英特尔(R)酷睿TM i7-4771 CPU @ 3.50GHz与8GB内存。

谢谢。

回答

0

您可以缓存路由以加快路由解析速度,但route caching不适用于基于Closure的路由。要使用路由缓存,您必须将任何Closure路由转换为使用控制器类。

要缓存您的路线执行php artisan route:cache并清除缓存php artisan route:clear

您还应该考虑php artisan optimize在单个文件中编译通用类,从而减少每个请求中包含的数量,并且将所有配置文件合并到单个文件中以加快加载速度。

+0

嗨@Malta,它没有解决问题。它仍然存在。用1个返回欢迎视图的方法创建一个控制器。映射了我必须'TestController @ showWelcome'的2条路线。 Ran'php artisan route :: cache'和'php artisan optimize'。得到或多或少相同的结果。 –

0

忘记这一个。这不是Laravel问题。这是该机器特有的问题。一段时间后,我将Ubuntu 12.04升级到14.04。在这样做时,它将apache 2.2升级到2.4,但保留了部分配置。这个问题应该存在,因为像Magento这样的其他框架的行为方式相同。