skip to Main Content

I work on a Vagrant+Puppet LAMP (2x cores, 2.5GB) stack where I develop my Laravel ver.8 based API.
There is a default setup, JWT middleware and almost bare minimum (also try with a bare fresh install with same behaviour). After the first call, the response time is about 6 seconds. If I call the same API endpoint, the response time is 200ms. Each further call within 3 seconds interval is quick. If I pause the calls for > 3s and then call again, the response time is again slow at about 6s.

Attempts I made to solve this:

php artisan cache:clear
composer dump-autoload -a --apcu
php artisan config:cache
php artisan session:table
php artisan migrate

.env:
APP_DEBUG=false
SESSION_DRIVER=database
SESSION_LIFETIME=120
CACHE_DRIVER=memcached
MEMCACHED_HOST=127.0.0.1
MEMCACHED_PORT=11217

BTW, the api call returns only: return response()->json([‘tst’]); When I output phpinfo(); from index.php, the response time is each time (pausing to) about 70ms.

Also try to debug the calls with CacheGrind via Xdebug: XDEBUG_PROFILE=1. Here are the profiling results: https://filebin.net/izs3qm0gm3gt8jq6

I just mentioned that the autoloader takes longer but could not compare the results. Is there any way to figure out the issue?

Thank you in advance.

2

Answers


  1. Chosen as BEST ANSWER

    The reason was the long DNS Lookup on the Vagrant box - not Laravel or any other part of it.


  2. Setup clockwork so you can analyze all the activity when you try to hit some end-point

    just simply run

    composer require itsgoingd/clockwork

    you’ll get an interface like this to check all the data

    enter image description here

    Another option is to use laravel telescope https://laravel.com/docs/8.x/telescope
    But this requires database setup and record all logs on the database, and I personally like clockwork,

    but both should tell you whats wrong with your setup

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search