Php perfomance problem fast analysys

Posted: 19


In this article I show how to find perfomance problem in couple steps:

When you want to find perfomance problem in your php application, you have to choose tool for that.

There are actually couple of them: xdebug profiler, xhprof (created by Facebook). For analysys xdebug results you have to install some analyze tool like KCachegrind, xdebugtoolkit, WinCacheGrind, or Webgrind.

For xhprof is enoght couple things described in this article.

Prepare env

1. I use php-7 compatible xhprof fork from tideways.io:

Dockerfile.fpm

RUN cd /tmp && git clone https://github.com/tideways/php-profiler-extension.git && \
cd php-profiler-extension && \
phpize && \
./configure && \
make && make install && \
echo "extension=tideways_xhprof.so" >> /usr/local/etc/php/conf.d/ext-xhprof.ini

install tideways toolkit:

export GOPATH="/home/$USER/code/golang"
go get github.com/tideways/toolkit
sudo ln -s /home/$USER/code/golang/bin/toolkit /usr/local/bin/tk

 

Prepare app

index.php

define('XHPROF_PROFILE', true);
if (XHPROF_PROFILE) {
tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_CPU | TIDEWAYS_XHPROF_FLAGS_MEMORY);
}
// ...
// application work here
// ...
if (XHPROF_PROFILE) { $data = tideways_xhprof_disable(); file_put_contents(
"/src/app/Profiling/" . uniqid('app_') . ".app.xhprof",
json_encode($data) ); }

Analyze results:

tk generate-xhprof-graphviz app_5bc5beea5e4e5.app.xhprof
dot -Tpng callgraph.dot > app.png

As we can see the main bottleneck in my case is processing templates. 

The next things is code investiogation why this bottleneck happened. For example,  I have a lot of records on the page that include separate template part which cause perrfomance issues. 

 

If you find the post helpful you can share it


Ваше мнение:

Имя
   other with PHP
drcreazy © 2008-2012 all rights reserved