优化我的表现 [英] Optimize my performance

查看:85
本文介绍了优化我的表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Zend Framework 1.11,Doctrine 2,一些Symfony 2组件以及其他工具和工具来开发一个项目.库.

我正在尝试使用Xdebug& amp;优化性能. Webgrind.

我已经发现一些瓶颈,例如解析Ini config等.并将其缓存.

现在,我才意识到自动加载是我应用程序中最昂贵的部分:

    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

如您所见,我没有使用默认的Zend_Loader_Autoloader,而是使用了 Opl (据我所知,它比它快),我正在将classMapLoader与APC缓存一起使用,但与其他应用程序相比,它仍然有点慢.

我该如何优化呢?

我已经加载了大约250个类,看起来只有〜40个很慢,其他的显示为0,00作为总调用成本",但是其他的在require调用中则从0,08增加到0,57. /p>

顺便说一句,由于使用的是Opl自动加载器,因此在我的生产环境中,APC似乎只对手动需要"的文件进行操作码缓存,而不是由自动加载器调用的文件.

解决方案

如果无法重构代码(删除Zend Framework,Drop Doctrine,Drop ...),我首先会在购买更好的硬件方面进行优化.这将自动优化您的代码,因为代码的上下文只是移动了(这并不是完全优化代码,因为代码不会更改).

如果不是这样,请考虑创建一个可以对您的代码库进行预处理的构建系统,并为其创建非开发版本以减少加载过程.这需要分析始终需要哪些文件,然后将它们全部编译为针对加载程序优化的格式,该格式可以是单个文件和/或静态类加载程序映射.

但是,众所周知,Zend总是需要将很多东西加载到内存中.甚至使用APC之类的PHP缓存也可能已经为您带来了一些好处(考虑使用前面提到的构建脚本进行预编译并优化您的指标突出显示的部分).

如果您的应用程序结构允许,那么还有另一种可能性:将整个应用程序在两次请求之间保留在内存中.可以使用PHP网络服务器来完成.这样,仅在服务器启动后就需要加载代码,而不再需要再次加载.如果它支持多个请求,则仅适用于您自己的应用程序.为此,可以很容易地采用良好的封装应用程序,尤其是带有请求逻辑的应用程序.现有的解决方案是 appserver-in-php .与您已经从APC获得的收益相比,您会惊讶地发现速度提高了多少.

也许这很有帮助.很难提出任何其他更具体的建议,因为不可能看到实际的代码,也无法获得详细的指标.您刚刚传递了有关幕后情况的片段,因此很难更具体地告诉您.

I'm working on a project with Zend Framework 1.11, Doctrine 2, some Symfony 2 componenents and others tools & libraries.

I'm trying to optimize performance using Xdebug & Webgrind.

I've already found some bottlenecks like parsing Ini config, etc.. and cached that.

Now, I just realize that the autoloading is the most costly 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'm not using the default Zend_Loader_Autoloader, I'm using Opl which is, as far I know, quicker than it, I'm using the classMapLoader with an APC cache but it still a bit slows compared to rest of the application.

How could I optimize that?

I've around 250 classes loaded, and it looks that only ~40 are slow, others show 0,00 as "Total call cost" but others are increasing from 0,08 to 0,57 on the require call.

By the way, since using the Opl autoloader, it looks that on my production environnement APC only opcode cache the file which are "manually required" not the ones which are called by the autoloader.

解决方案

If refactoring your code is not an option (drop Zend Framework, Drop Doctrine, Drop ...) I would first optimize in buying better hardware. That will automatically optimize your code, because the context of the code is just shifted (this is not exactly optimizing the code, as the code won't change).

If that is not an option consider to create yourself a build system that can pre-process your codebase and create a non-development version of it to cut the loading process. This requires the analysis which files are needed always and you compile them all into a loader-optimized format which could be single file and/or static class loader maps.

However it's known that Zend needs to load a lot into memory always. Even using a PHP cache like APC might already bring you something (consider to pre-compile with the earlier noted build script and optimize the parts highlighted by your metrics).

If your application structure allows it, there is another possibility, too: Keep your whole application in memory between requests. That can be done with a PHP webserver. That done, the code only needs to get loaded once the server starts and will never needed to load again. This only works with your own application if it supports multiple requests. A good encapsulated application especially with the request logic can be adopted quite easily for that. An existing solution is appserver-in-php. You will be amazed how much the speed increases compared to the benefits you already gained from APC.

Maybe this was helpful. Any additional, more concrete suggestions are hard to make as it's not possible to see your code in action nor to have detailed metrics on it. You've just passed a fragment on what's going behind the scenes so it's hard to tell you more concretely.

这篇关于优化我的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆