Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing takes CPU to 100% #14418

Closed
pfbernardo opened this issue Jul 21, 2016 · 8 comments
Closed

Routing takes CPU to 100% #14418

pfbernardo opened this issue Jul 21, 2016 · 8 comments

Comments

@pfbernardo
Copy link

Hi,

I've setup a ubuntu 14.04 with php 5.5 and apache 2.4.

I installed a fresh laravel 5.2. No database connections in the project.

I then when to app/Http/routes.php and edited to:

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


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

So basically I have 2 routes just showing the welcome view.

I then run:

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

The Cpu never goes over 6% and I get the following results:

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)

I then run:

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

The Cpu immediately goes up to 100% and at the end I get these results:

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)

It seems that if it is not the root route laravel spikes the cpu if there are a lot of connections. This also happend with a fresh install in laravel 4.2.

Can anyone point out why this happens? I really need this solved.

My server has a 8 core Intel(R) Core(TM) i7-4771 CPU @ 3.50GHz with 8GB of RAM.

Thanks.

@pfbernardo
Copy link
Author

Just some more info.

Created a controller with 1 method that return the welcome view. Mapped the 2 routes I had to 'TestController@showWelcome'. Ran php artisan route::cache and php artisan optimize. Got more or less the same results

@it-can
Copy link
Contributor

it-can commented Jul 22, 2016

Which version do you use? and does it also happen on a earlier versions, like 5.2.40 - 5.2.39 - 5.2.38?

Maybe this commit has to do something with it? #14386

@pfbernardo
Copy link
Author

I was using 5.2.41. I downgraded to 5.2.38 and I have the same issue. It also happens in the last version of 4.2.

@it-can
Copy link
Contributor

it-can commented Jul 22, 2016

is there a version where you don't have this issue?

@pfbernardo
Copy link
Author

Didn't try 5 and 5.1, but the ones I tried it always happens.

Didn't anyone had this issue before when stress testing?

@barryvdh
Copy link
Contributor

Do single requests also happen slower, or just the stress testing? Eg. hit both in the browser and check the actual response time.

@pfbernardo
Copy link
Author

No. Single request are fine. In the browser and through ab with -n 1.

@pfbernardo
Copy link
Author

This is really weird. In the machine where I did the tests the apache processes spike the cpu but in a micro instance in amazon the results are basically the same with both routes.

Must be something in my local server. The only thing I can think of is some apache configuration since I did an upgrade from ubuntu 12.04 to ubuntu 14.04 which upgraded from apache 2.2 to 2.4. Probably it left some wrong configuration on it.

It is not a laravel problem since other frameworks like Magento in the same server behave in the same way when testing.

I'm very sorry to have wasted your time on this.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants