Optimize Your Performance

I am working on a project with Zend Framework 1.11, Doctrine 2, some Symfony 2 components, and other tools and libraries.

I am trying to optimize performance using Xdebug and Webgrind.

I already found some bottlenecks like Ini config parsing etc. and cached this.

Now I just understand that startup is the most expensive part of my application:

Opl\Autoloader\ApcLoader->loadClass 274 31.36 43.86 Zend_Loader_PluginLoader->load 150 4.80 12.29 Zend_Loader_Autoloader->getClassAutoloaders 278 1.42 1.91 Zend_Controller_Router_Route_Regex->_getMappedValues 291 1.29 1.35 Doctrine\ORM\UnitOfWork->createEntity 85 1.24 3.18 

As you can see, I do not use default Zend_Loader_Autoloader , I use Opl , which, as far as I know, is faster than me, I use classMapLoader with APC cache, but it still slows down a bit compared to the rest of the application.

How can I optimize this?

I have about 250 classes loaded, and it looks like only ~ 40 is slow, others show 0.00 as the "Total Call Cost", but others increase from 0.08 to 0.57 on demand.

By the way, using Opl autoloader, it seems that on my production environment APC only caches the operation code that is “manually required”, and not the one that is called by the autoloader.

+6
source share
4 answers

If refactoring your code is not an option (drop Zend Framework, Drop Doctrine, Drop ...), I would first optimize the purchase of the best equipment. This automatically optimizes your code, because the context of the code is simply shifted (this does not optimize the code exactly, since the code will not change).

If this is not an option, consider creating a build system for yourself that can pre-process your code base and create a non-working version to shorten the boot process. This requires analysis, which files are always necessary, and you compile them all in a format optimized for the loader, which can be a single file and / or static class loader card.

However, it is known that Zend needs to be loaded a lot into memory. Even using a PHP cache, such as APC, may already bring you something (think about pre-compiling with the previously noted build script and optimize the details highlighted by your metrics).

If your application structure allows this, there is another possibility: Store the entire application in memory between requests. This can be done using the PHP web server. This is done, the code needs to be downloaded only after the server starts and will no longer be needed to download. This only works with your own application if it supports multiple requests. A good encapsulated application, especially with request logic, can be easily adopted for this. The existing solution is appserver-in-php . You will be surprised how much speed is increasing compared to the benefits that you have already received from APC.

Perhaps this was helpful. Any additional, more specific proposals are difficult to make, since it is impossible to see your code in action or not have detailed indicators on it. You just conveyed a fragment about what is happening behind the scenes, so it’s hard for you to say more specifically.

+4
source

I am trying to optimize performance using Xdebug and Webgrind

Well, since you are in a position to seriously need better performance, you may be open to a less popular but clearly effective way to do this.

It works with any language if there is a debugger that can be paused, such as Xdebug.

It is described in a nutshell . It demonstrates its effectiveness. I can tie you many more.

You may find this a bit intellectually agonizing. As in

  • You discover bottlenecks as the time associated with routines. The most valuable acceleration options often do not appear that way. These are actions that you can easily describe when you see them, but they are scattered. They do not concentrate significant time in any particular procedure or line of code, therefore, profilers do not see them.

  • The biggest acceleration options are probably not easy to fix. They may need to rethink how the program is organized. If you find something that you can easily fix, that's great. Go ahead and do it. If it’s not so easy to fix, but it still saves a lot of time, if you need to save this time, then you have to do it, like it or not.

Good luck.

+3
source

I don't like what hakre offers. First of all, I would see if I can remove the web server. If it is a good alternative, it is nginx or lighttpd. Compared to Apache, they are from this century, and the configuration is much simpler. I really don’t know about startup, but if the class files are really big, did you try to install a disk drive or use a php compressor? In my experience, a PHP compressor can significantly reduce runtime (i.e., parsing time).

+1
source

I don’t have much experience, but as soon as I had such a problem. I checked my included paths and applied them in the order of the most used library paths. and I have almost 30% growth. I think that you already know this, but laid out some way ....... :)

0
source

Source: https://habr.com/ru/post/904067/


All Articles