6

According to New Relic transaction tracer, sometimes Composer\Autoload\includeFile takes around 318 ms to load my project.

I have dumped a classmap from composer, but still no difference it made.

composer.json requires the following:

"require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.4.*",
        "zendframework/zendservice-amazon": "2.*",
        "wisembly/elephant.io": "~3.0",
        "knplabs/github-api": "~1.2"
    }

I only have one module in my ZF2 application.

How can my ZF2 autoloading perform faster?

zed
  • 3,180
  • 3
  • 27
  • 38

2 Answers2

6

We had the exact same issue while debugging in New Relic. Finally, we traced it to the filesystem, it turned out we weren't using opcode cache, which can be painful under high load.

Check your opcode caching and try to tweak it's memory settings. That's how we managed to solve it.

  • May you share how beneficial was adding opcache in terms of response time, used CPU and load average? – zed Jun 30 '15 at 06:44
  • 1
    It was most beneficial to our NFS storage, we eliminated cca 1000 NFS req/sec. We raised opcode caching memory from 64 to 256MB, but you can tweak that to fit the optimal number of files in cache according to ZF2 (we're using Symfony 2). On the other hand, we haven't seen significant changes in CPU/load average on the webservers. – Небојша Камбер Jul 01 '15 at 10:29
  • I installed it yesterday. This was the biggest performance trick that I have ever seen in my life. Response time was cut by 3 times. The CPU usage decreased by 6-9 times. I did not change its configuration. The load average also decreased by 5 times. Thank you! – zed Jul 02 '15 at 07:02
  • 1
    Don't forget to set `opcache.validate_timestamps=0` otherwise opcache will not give you anything. – Dmitriy Lezhnev Aug 24 '15 at 17:14
  • This post has some useful settings opcache settings that will apply to most frameworks: https://medium.com/appstract/make-your-laravel-app-fly-with-php-opcache-9948db2a5f93 – filitchp Feb 15 '18 at 22:55
1

Note that "optimizing" the autoloading is not necessarily resulting in the best load times in every case. It's a race between getting faster by eliminating file system access versus getting slower by loading more unused stuff into memory.

Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?

Community
  • 1
  • 1
Sven
  • 69,403
  • 10
  • 107
  • 109