ZF2为高流量而优化 [英] ZF2 Optimize for high traffic

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

问题描述

当同时有3个以上的用户使用我的ZF2应用程序时,它的运行速度似乎非常慢.

My ZF2 application seems to be extremely slow when more than 3 users are using it at the same time.

我使用xdebug和webgrind配置了我的代码,但我的所有功能似乎都很慢 因此它必须是zf2自身中的优化问题.

I profile my code with xdebug and webgrind and non of my functions seems to be slow so it has to be an optimalisation issue within the zf2 it's self.

对于缓存,我使用了EvanDotPro的EdpSuperluminal模块,这似乎可以提高应用程序的性能.

For cache I make use of the EdpSuperluminal module by EvanDotPro, this seems to increase the performance of the application.

我们使用nginx反向代理,但也没有道理.

We make use of nginx reverse proxy but make no sense as well.

我需要一些好的建议来增加高流量的响应.我说 30个以上同时连接的用户.

I need some good advices to increase the response for high traffic. I speak about 30+ connected user at the same time.

推荐答案

有几个非常简单的步骤可以实现更快的应用程序.始终可以考虑三件事.

There's few very simple steps to achieve a faster application. There's three things that can always be considered.

  1. ZF2 Performance QuickTipp#1-ViewModels 始终手动分配完全合格的脚本以进行渲染.这会稍微提高性能.这样做是这样的:

  1. ZF2 Performance QuickTipp #1 - ViewModels Always manually assign the fully qualified script to render. This will increase the performance a little. It's done like this:

public function someAction()
{
    $viewModel = new ViewModel();
    $viewModel->setTemplate('MODULE / CONTROLLER / ACTION.phtml');
    // In this given example: $viewModel->setTemplate('foo/bar/some.phtml');

    // Do some other Controller-logic as used to

    return $viewModel->setVariables(array(
        //key-value-paired view-variables
    ));
}

  • ZF2 Performance QuickTipp#2-Classmap Autoloading 这可能是加快应用程序速度的最重要部分之一.我个人已经看到,LoadingTimes最多增加了40%.实现起来非常简单:

  • ZF2 Performance QuickTipp #2 - Classmap Autoloading This probably is one of the most important parts of speeding up your application. Personally i've seen an increase in LoadingTimes by up to 40%. Implementing this is pretty simple:

    class Module 
    {
        public function getAutoloaderConfig()
        {
            return array(
               'Zend\Loader\ClassMapAutoloader' => array(
                    __DIR__ . '/autoload_classmap.php',
               ),
            );
        }
    }
    

    autoload_classmap.php然后是'FQ-CLASSNAME' => 'FQ-FILEPATH'的简单数组.可以很容易地使用ZF2的classmap_generator-utility

    The autoload_classmap.php then is a simple array of 'FQ-CLASSNAME' => 'FQ-FILEPATH'. This can be automatted pretty easily using the classmap_generator-utility of ZF2

    ZF2 Performance QuickTipp#3-让Module.php保持轻巧! 遗憾的是,这是我还没有写过的帖子. Module.php是在每个单个请求上加载的文件.许多人忘记了这一点,并在其中写了很多工厂.有一次, ZfcUser-Module.php 是以下示例不该做什么.闭包或匿名函数也将在每个请求上执行.如果整个项目中有太多的工作,则需要完成很多工作.更好的方法是简单地编写 Factory-Classes . ZfcUser稍后更新了Module.php 即可使用此策略.

    ZF2 Performance QuickTipp #3 - Keep Module.php light! Sadly this is a post i haven't come around to write yet. The Module.php is a file that is loaded on every single request. Lots of people forget about this and write lots and lots of factories inside them. At one point, ZfcUser-Module.php was an example of what not to do. Closures or anonymous functions are executed on every request, too. This is quite a bit of work to be done if there's too many of them over the whole project. A better approach would be to simply write Factory-Classes. ZfcUser later updated Module.php to use this strategy.

    这几乎是一个人可以做的所有简单的事情(我知道-我不太了解!:D).但是,听起来很有趣的是,开始使用3个用户时,您的应用程序运行缓慢.以我的经验,这与脚本本身无关,而是服务器问题.是从Staging Machine还是本地?

    And that's pretty much all the easy stuff one can do (that i know of - i dont know much! :D). However what sounds interesting is that starting to use 3 users your application runs slow. To my experience this has nothing to do with the scripts itself but is rather an server issue. Is this from a Staging Machine or locally?

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

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