7

I'm using Laravel 4.2, when I navigate through the pages the PHP-FPM spikes to 10-20%.

I checked it on 2 environments:
A:
Nginx Balancer - 2 CPU, 2GB.
PHP-FPM server - 1 CPU, 1GB.
MySQL server - 2 CPU, 2GB.

B:
Simple VPS on linode of 1 CPU, 1GB.
*SSD on all servers.

Now, I started investigating it more deeply using JMeter:
JMeter settings:

Number of Threads(users) - 100.
Ramp-Up Period(in seconds) -  1.
Loop Count - 5.
  1. Laravel 4.2, sent the requests to:

    Route::get('/test', function() { echo "Test"; });

Results: about 40 seconds of CPU on 100%.

  1. Laravel 5.2(clean installation), sent the requests to the welcome page.
    Results: CPU usage on 100% for 20 seconds.

  2. Phalcon(clean installation): sent the requests to Hello world page.
    Results: CPU usage on 50% for 2 seconds.

  3. Codeiginiter(rest api server, same config): sent the requests to a page that loads data from the DB(returning JSON).
    Results: CPU usage on 55%-60% for 3 seconds.

    • Same results on both environments.
    • Disabled debug mode, database connection, changed the configs and so on.
      PHP-fpm config:
      pm.max_children = 9
      pm.start_servers = 3
      pm.min_spare_servers = 2
      pm.max_spare_servers = 4

I understand that Laravel should be slower but I doubt the difference should be that big? I googled for hours, I encountered a few posts that have the same issue as mine but without any solution:

http://laravel.io/forum/09-25-2014-what-steps-should-i-take-to-reduce-laravels-high-cpu-load
http://laravel.io/forum/08-12-2014-cpu-load-general-performance-question

What am I missing here?
Thanks in advance.

6
  • So you optimized laravel php artisan optimize and composer composer dump-autoload --optimize? Commented Mar 27, 2016 at 0:30
  • Are you provisioning with Forge? Commented Mar 27, 2016 at 2:29
  • I have also getting the cpu usage 100% issue with simple 'hello world' app. Got any solution? Commented Aug 10, 2018 at 10:24
  • @CP-Soni No I've stopped using Laravel for big projects and basically developed my own framework which is based on slimframework with my own needs. However, try what Kurucu suggested, maybe it will come in handy for you. Commented Aug 19, 2018 at 15:19
  • Have you checked whether Laravel runs in dev or prod environment? Commented Jan 28, 2020 at 10:00

1 Answer 1

2

That might sound obvious and off topic, but make sure your PHP installation includes OPCache extension php-opcache. That helped me a lot.

OPCache gradually increases PHP performance by storing precompiled script bytecode in shared memory, sot does not repeatedly load/parse scripts for each request.

You can get more information from PHP OPCache Documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.