bash.org:

Следуй за мной:

twiby

Адовый чад кутежа и трэш в комплекте

Php perfomance problem fast analysys

Пришло на ум: 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. 

 

Если мой пост помог вам сэкономить пару часов времени или показался полезным, думаю не лишним будет показать его друзьям через социальные сети или упомянуть в своем блоге.


Ваше мнение:

Имя
   другие статьи с тегом PHP

Случайная мысль:

Время — деньги.
Бенджамин Франклин
drcreazy © 2008-2012 all rights reserved