php - High load average zf2 + doctrine on simple page -


i use zendframework2 , doctrine launching project. cpu shows high usage on httpd requests. enabled opcache filecaching, , memcache doctrine.

any idea why might have load average being near 5.0? put die('test1') inside of onbootstrap of zendframework2 1 time, , time put die('test') before.

die('test2') zend\mvc\application::init(require 'config/application.config.php')->run(); 

my apache bench shows when framework loaded without connection database or goes controller it's 5x slower. why zf2 acting , might possible solution normalize it's behavior?

[question update]

i profiled xdebug , webgrind , found out processes on bootstrap take high percentage

( application\module->onbootstrap)

on bootstrap have line of codes

        //...         $eventmanager->attach(mvcevent::event_route, function($e) use ($blacklistfornormaluser, $auth) {         $match = $e->getroutematch();          // no route match, 404         if (!$match instanceof routematch) {              return;         }          // route whitelisted         $name = $match->getmatchedroutename();          if (!in_array($name, $blacklistfornormaluser)  ) {             return;         }          // user authenticated         if ($auth->hasidentity() ) {             return;         }          // redirect user login page, example         $router   = $e->getrouter();          if(in_array($name, $blacklistfornormaluser)){              $url      = $router->assemble(array(), array(                 'name' => 'user/login'             ));          }          $response = $e->getresponse();         $response->getheaders()->addheaderline('location', $url);         $response->setstatuscode(302);          return $response;     }, -100);     //... 

another high point

doctrine\orm\mapping\driver\annotationdriver->loadmetadataforclass

if system works 50 users, not 100. possibly have bottleneck in system. when passes threshold of 50 users may running out of resource causes load rise rapidly.

reading between lines, using lamp stack. useful commands are:

top 

this gives lot of information quickly. @ top rows see in cpu(s) row processors spending time on. high %wa mean waiting on disk io db.

look @ mem: , swap: rows, check swap @ low , high load. if has risen mean system running out of memory. either tune app or add more ram.

look @ tasks running, shows @ top? httpd, maybe mysql or other tool backup running , causing havoc.

try learn read information in system. there many other commands 'free -m' or 'vmstat -n 5' may worth looking up.

if nothing there helps couple of apache tools may mod_status show requests apache handling @ given time. adding %mst commonlog config option in apache make log time taken serve each request , can slow scripts in logs.

after - if still doesn't make sense or all. come question , add more detail system.

....................

thanks adding detail , work webgrind. there many permutations of code causing slow down, may best start basic zf2 tuning useful skill.

by default, it's easy let zf2 lot of work finding files views , classes. slows zf2 down lot has find them on every request. opcache less effective when files not loaded using absolute pathnames same reason.

zf2 has tool in vendor/bin generates lists of classes , file locations. each module in application folder.

php classmap_generator.php -l "..\..\modules\modulename" 

e.g.

php classmap_generator.php -l ../../module/application creating class file map library in '/zend/module/application'... wrote classmap file '/zend/module/application/autoload_classmap.php' 

ensure classmap used adding module.php files:

public function getautoloaderconfig() {     return array(         'zend\loader\classmapautoloader' => array(             __dir__ . '/autoload_classmap.php',         ),         'zend\loader\standardautoloader' => array(             'namespaces' => array(                 __namespace__ => __dir__ . '/src/' . __namespace__,             ),         ),     ); } 

this informs zend how search files include , skips guessing part. should noticeably faster in benchmarks.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -