Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

performance - ZF2 Optimize for high traffic

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

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.

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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
        ));
    }
    
  2. 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(
               'ZendLoaderClassMapAutoloader' => array(
                    __DIR__ . '/autoload_classmap.php',
               ),
            );
        }
    }
    

    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

  3. 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.

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...