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?

2 Answers 2

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.

5
  • May you share how beneficial was adding opcache in terms of response time, used CPU and load average?
    – zed
    Commented Jun 30, 2015 at 6: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. Commented Jul 1, 2015 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
    Commented Jul 2, 2015 at 7:02
  • 1
    Don't forget to set opcache.validate_timestamps=0 otherwise opcache will not give you anything. Commented Aug 24, 2015 at 17:14
  • This post has some useful settings opcache settings that will apply to most frameworks: medium.com/appstract/…
    – filitchp
    Commented Feb 15, 2018 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?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.