Laravel on kubernetes - slow composer vendor autoload (production)

9/6/2018

We have set up a kubernetes cluster for our laravel application on google cloud platform. Containers:

  • application code + php-fpm
  • apache2
  • others not related to the issue

(We run under nginx-ingress-controller but this seems unrelated to the issue)

We run a jmeter stress tests on a simple laravel route that returns "ok" and we noticed terrible response times.

enter image description here

Afterwards we run the same test on an index2.php (inside public dir το slide over the framework) which just returns 'ok'.

And we got this result(!): enter image description here

After digging we found out that the composer's autoloading stuff cause this slowness.

Any advice on how this could be resolved will be highly appreciated.

Thanks

-- Tania Petsouka
autoload
composer-php
kubernetes
laravel
vendor

1 Answer

9/6/2018

Ok. We found out that we had no opcache enabled. As documented about composer optimize-autoloader:

On PHP 5.6+, the class map is also cached in opcache which improves the initialization time greatly. If you make sure opcache is enabled, then the class map should load almost instantly and then class loading is fast.

-- Tania Petsouka
Source: StackOverflow