EIN STALL VOLLER
TRÜFFELSCHWEINE

(PHP)-Profiling-Tools im Überblick


René Bruns - TNG Big Techday
ÜBER MICH

                        René Bruns

               Entwickler seit 2001

               seit 2009 bei Travian Games

               seit 2011 Technical Director




                                               2
UND WER SEID IHR?




                    3
UND WER SEID IHR?

Entwickler?




                    3
UND WER SEID IHR?

Entwickler?




              Systemadministratoren?




                                       3
UND WER SEID IHR?

Entwickler?




              Systemadministratoren?




                                       QA?



                                             3
UND WER SEID IHR?

Entwickler?




              Systemadministratoren?




 C*O?                                  QA?



                                             3
UND WER SEID IHR?

Entwickler?                            Projektmanager?




              Systemadministratoren?




 C*O?                                     QA?



                                                    3
PROFILING?




             4
PROFILING?


Profiler

Es gibt unterschiedliche Problembereiche in der
Softwareentwicklung, die durch ineffiziente Programmierung
ausgelöst werden. Ein Profiler hilft dem Entwickler durch
Analyse und Vergleich von laufenden Programmen die
Problembereiche aufzudecken.
http://de.wikipedia.org/wiki/Profiler_(Programmierung)




                                                             5
AUSGANGSSITUATION


               SLOW!!11!




                           6
PROFILING FRÜHER(?)

class Main
{
    public static function run() {
        $otherClass = new OtherClass();
        $otherClass->doNothingImportant();
        $dummy = new SlowClass();
        $dummy->slowFunction(10);
    }
}

Main::run();




                                             7
PROFILING FRÜHER(?)

class Main
{
    public static function run() {
        $start = microtime(true);
        printf ("Before OC: %f" . PHP_EOL, microtime(true) - $start);
        $otherClass = new OtherClass();
        $otherClass->doNothingImportant();
        printf ("After OC: %f" . PHP_EOL, microtime(true) - $start);
        printf ("Before SC: %f" . PHP_EOL, microtime(true) - $start);
        $dummy = new SlowClass();
        $dummy->slowFunction(10);
        printf ("After SC: %f" . PHP_EOL, microtime(true) - $start);
    }
}

Main::run();




                                                                    8
PROFILING FRÜHER(?)

class Main
{
    public static function run() {
        $start = microtime(true);
        printf ("Before OC: %f" . PHP_EOL, microtime(true) - $start);
        $otherClass = new OtherClass();
        $otherClass->doNothingImportant();
        printf ("After OC: %f" . PHP_EOL, microtime(true) - $start);
        printf ("Before SC: %f" . PHP_EOL, microtime(true) - $start);
        $dummy = new SlowClass();
        $dummy->slowFunction(10);
        printf ("After SC: %f" . PHP_EOL, microtime(true) - $start);
    }
}                               $ php Main.php
                               Before OC: 0.000625
Main::run();
                               After OC: 0.004919
                               Before SC: 0.005099
                               ..........
                               After SC: 10.013932
                                                                    8
PROFILING HEUTE

   Viele verschiedene Fehlerquellen
     Browser
     Frontend
     Backend
     Datenbank
     Services

   Schwachstelle suchen

   Vom Groben in‘s Feine




                                       9
SCHRITT 1: MELDUNG ÜBERPRÜFEN



                      He‘s
                      dead,
                      Jim!
                                10
SCHRITT 2: URSACHE EINKREISEN

                Browser




                                11
SCHRITT 2: URSACHE EINKREISEN

                Browser

                Frontend




                                11
SCHRITT 2: URSACHE EINKREISEN

                Browser

                Frontend

                Backend




                                11
SCHRITT 2: URSACHE EINKREISEN

                Browser

                Frontend

                Backend

                  DB




                                11
BROWSER

   Langsamer JS-Code

   Zu hoher Speicherverbrauch

   Zu viele CSS-Selektoren

   Langsame Ladezeiten
     Zu viele parallele Downloads
     Offen gehaltene Verbindungen
     Netzwerk
     Internet

   Antwort vom Server zu langsam -> Backend



                                               12
GOOGLE CHROME




                13
GOOGLE CHROME




                14
GOOGLE CHROME




                15
GOOGLE CHROME




                16
GOOGLE CHROME




                17
GOOGLE CHROME




                17
GOOGLE CHROME




                18
GOOGLE CHROME




                18
GOOGLE CHROME




                19
GOOGLE CHROME




                19
FRONTEND / BACKEND

   Unnötige Schreib- / Lesezugriffe in Schleifen

   Log-Ausgaben

   Schleifen sind unnötig geschachtelt

   Unnötig langsame Befehle benutzt
     RegExp statt ==

   Externer Service reagiert langsam

   Datenbankabfrage dauert zu lange --> DB




                                                    20
XDEBUG

   PHP Extension by Derick Rethans

   Kann per INI-Direktive aktiviert werden

   breites Einsatzspektrum
     Debugger
     Profiler
     Tracer
     StackTrace-Formatter
     ...

   hoher Memory-/ CPU-/ IO-Footprint

   Niemals(!) dauerhaft im Produktivbetrieb verwenden


                                                         21
XDEBUG




         22
XDEBUG

$ php -d xdebug.profiler_enable=1 -d xdebug.profiler_output_dir=. Main.php
..........




                                                                             22
XDEBUG

$ php -d xdebug.profiler_enable=1 -d xdebug.profiler_output_dir=. Main.php
..........

$ ls -l ca*
-rwxrwxrwx 1 rene staff 4461 11 Jun 13:53 cachegrind.out.69408




                                                                             22
XDEBUG

$ php -d xdebug.profiler_enable=1 -d xdebug.profiler_output_dir=. Main.php
..........

$ ls -l ca*
-rwxrwxrwx 1 rene staff 4461 11 Jun 13:53 cachegrind.out.69408

$ cat cachegrind.out.69408
version: 1
creator: xdebug 2.2.0
cmd: /Volumes/TCDATA/Sourcen/git/ProfilingTalk/Main.php
part: 1
positions: line

events: Time

fl=/Volumes/TCDATA/Sourcen/git/ProfilingTalk/OtherClass.php
fn=require_once::/Volumes/TCDATA/Sourcen/git/ProfilingTalk/OtherClass.php
1 42

fl=/Volumes/TCDATA/Sourcen/git/ProfilingTalk/SlowClass.php
fn=require_once::/Volumes/TCDATA/Sourcen/git/ProfilingTalk/SlowClass.php
10




                                                                             22
XDEBUG
   Cachegrind-Files können via KCachegrind, WinCachegrind, WebGrind oder PhpStorm-IDE
    ausgewertet werden.

   Bsp. PhpStorm:




                                                                                         23
XDEBUG
   Cachegrind-Files können via KCachegrind, WinCachegrind, WebGrind oder PhpStorm-IDE
    ausgewertet werden.

   Bsp. PhpStorm:




                                                                                         24
XDEBUG




         25
XHPROF

   PHP Extension by Facebook

   Kann codeseitig aktiviert werden

   Profiler only

   sehr schlanker Footprint, daher auch im Livebetrieb
    einsetzbar (Monte Carlo-Algorithmus)




                                                          26
XHPROF

header.php:

include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_lib.php';
include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);



footer.php:
include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_lib.php';
include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_runs.php';

$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, 'testrene');
echo "http://localhost/~rene/xhprof_html/index.php?run={$run_id}&source=testrenen";




                                                                                  27
XHPROF
$ php -d auto_append_fileo_prepend_file="header.php" -d auto_append_file="footer.php" Main.php
..........
http://localhost/~rene/xhprof_html/index.php?run=4fd61a7e92aeb&source=testrene




                                                                                             28
XHPROF
$ php -d auto_append_fileo_prepend_file="header.php" -d auto_append_file="footer.php" Main.php
..........
http://localhost/~rene/xhprof_html/index.php?run=4fd61a7e92aeb&source=testrene

$ cat 4fd61a7e92aeb.testrene
a:14:{s:23:"main()==>load::Main.php";a:5:{s:2:"ct";i:1;s:2:"wt";i:459;s:3:"cpu";i:1220;s:
2:"mu";i:10408;s:3:"pmu";i:0;}s:43:"main()==>load::ProfilingTalk/OtherClass.php";a:5:{s:
2:"ct";i:1;s:2:"wt";i:798;s:3:"cpu";i:113;s:2:"mu";i:6880;s:3:"pmu";i:0;}s:
47:"main()==>run_init::ProfilingTalk/OtherClass.php";a:5:{s:2:"ct";i:1;s:2:"wt";i:14;s:3:"cpu";i:
10;s:2:"mu";i:1104;s:3:"pmu";i:0;}s:42:"main()==>load::ProfilingTalk/SlowClass.php";a:5:{s:
2:"ct";i:1;s:2:"wt";i:467;s:3:"cpu";i:87;s:2:"mu";i:9648;s:3:"pmu";i:0;}s:
46:"main()==>run_init::ProfilingTalk/SlowClass.php";a:5:{s:2:"ct";i:1;s:2:"wt";i:9;s:3:"cpu";i:
7;s:2:"mu";i:1104;s:3:"pmu";i:0;}s:36:"OtherClass::doNothingImportant==>pow";a:5:{s:
2:"ct";i:1;s:2:"wt";i:1655;s:3:"cpu";i:926;s:2:"mu";i:1176;s:3:"pmu";i:0;}[...]}




                                                                                                28
XHPROF




         29
XHPROF




         30
XHPROF




         30
DATENBANK

   Unnötige Daten geladen

   Kein/falscher Index benutzt

   Daten werden nach der Abfrage noch sortiert

   Langsame IOs

   Falsche Systemeinstellungen (Buffer Sizes, ...)




                                                      31
DB - EXPLAIN

select LastName, FirstName, sum(UnitPrice * Quantity) from employees e inner join
orders o on e.EmployeeID = o.EmployeeID inner join "Order Details" od on o.OrderID
= od.OrderID group by LastName, FirstName;




                                                                                 32
DB - EXPLAIN

select LastName, FirstName, sum(UnitPrice * Quantity) from employees e inner join
orders o on e.EmployeeID = o.EmployeeID inner join "Order Details" od on o.OrderID
= od.OrderID group by LastName, FirstName;


sqlite> explain query plan [...];

0|0|0|SCAN TABLE employees AS e (~1000000 rows)
0|1|1|SEARCH TABLE orders AS o USING AUTOMATIC COVERING INDEX (EmployeeID=?) (~7 rows)
0|2|2|SEARCH TABLE Order Details AS od USING INDEX sqlite_autoindex_Order Details_1
(OrderID=?) (~10 rows)
0|0|0|USE TEMP B-TREE FOR GROUP BY




                                                                                 32
DB - EXPLAIN

select LastName, FirstName, sum(UnitPrice * Quantity) from employees e inner join
orders o on e.EmployeeID = o.EmployeeID inner join "Order Details" od on o.OrderID
= od.OrderID group by LastName, FirstName;


sqlite> explain query plan [...];

0|0|0|SCAN TABLE employees AS e (~1000000 rows)
0|1|1|SEARCH TABLE orders AS o USING AUTOMATIC COVERING INDEX (EmployeeID=?) (~7 rows)
0|2|2|SEARCH TABLE Order Details AS od USING INDEX sqlite_autoindex_Order Details_1
(OrderID=?) (~10 rows)
0|0|0|USE TEMP B-TREE FOR GROUP BY


sqlite> explain [...];
0|Trace|0|0|0||00|
1|SorterOpen|3|5|0|keyinfo(2,BINARY,BINARY)|00|
2|Integer|0|7|0||00|
3|Integer|0|6|0||00|
4|Null|0|10|11||00|
5|Gosub|9|74|0||00|
6|Goto|0|81|0||00|
7|OpenRead|0|120|0|3|00|



                                                                                 32
SCHRITT 3: ERFOLG PRÜFEN

   Hat die Optimierung etwas gebracht?

   Vorher-Nachher-Check

   Lasttests

   Tools
      Apache Benchmark (AB)
      JMeter




                                          33
APACHE BENCHMARK (AB)
$ ab -n 100 -c 10 http://localhost/~rene/talk/Main.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software:        Apache/2.2.21
Server Hostname:        localhost
Server Port:            80

Document Path:          /~rene/talk/Main.php
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   56.692 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      22300 bytes
HTML transferred:       1100 bytes
Requests per second:    1.76 [#/sec] (mean)
Time per request:       5669.198 [ms] (mean)
Time per request:       566.920 [ms] (mean, across all concurrent requests)
Transfer rate:          0.38 [Kbytes/sec] received

Connection Times (ms)
              min mean[+/-sd] median     max
Connect:        0 3660 2329.9  5022      6356
Processing:     0 1758 3060.0     0     11378
Waiting:        0 1757 3059.9     0     11377
Total:       5010 5417 1403.8  5030     11378

Percentage of the requests served within a certain time (ms)
  50%   5030
  66%   5040
  75%   5052
  80%   5063
  90%   6316
  95% 11378        vorher
  98% 11378
  99% 11378
 100% 11378 (longest request)




                                                                              34
APACHE BENCHMARK (AB)
$ ab -n 100 -c 10 http://localhost/~rene/talk/Main.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
                                             $ ab -n 100 -c 10 http://localhost/~rene/talk/Main.php
Benchmarking localhost (be patient).....done This is ApacheBench, Version 2.3 <$Revision: 655654 $>
                                             Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
                                             Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software:        Apache/2.2.21
Server Hostname:        localhost            Benchmarking localhost (be patient).....done
Server Port:            80

Document Path:           /~rene/talk/Main.php Server Software:        Apache/2.2.21
Document Length:         11 bytes             Server Hostname:        localhost
                                              Server Port:            80
Concurrency Level:       10
Time taken for tests:    56.692 seconds       Document Path:          /~rene/talk/Main.php
Complete requests:       100                  Document Length:        11 bytes
Failed requests:         0
Write errors:            0                    Concurrency Level:      10
Total transferred:       22300 bytes          Time taken for tests:   5.395 seconds
HTML transferred:        1100 bytes           Complete requests:      100
Requests per second:     1.76 [#/sec] (mean) Failed requests:         0
Time per request:        5669.198 [ms] (mean) Write errors:           0
Time per request:        566.920 [ms] (mean, across transferred:
                                              Total all concurrent requests)
                                                                      22300 bytes
Transfer rate:           0.38 [Kbytes/sec] received
                                              HTML transferred:       1100 bytes
                                              Requests per second:    18.54 [#/sec] (mean)
Connection Times (ms)                         Time per request:       539.458 [ms] (mean)
               min mean[+/-sd] median    max Time per request:        53.946 [ms] (mean, across all concurrent requests)
Connect:         0 3660 2329.9    5022   6356 Transfer rate:          4.04 [Kbytes/sec] received
Processing:      0 1758 3060.0       0  11378
Waiting:         0 1757 3059.9       0  11377 Connection Times (ms)
Total:        5010 5417 1403.8    5030  11378                min mean[+/-sd] median   max
                                              Connect:         0 395 217.3     531    577
Percentage of the requests served within a certain time (ms) 0 142 214.4
                                              Processing:                        1    559
  50%    5030                                 Waiting:         0 142 214.6       0    559
  66%    5040                                 Total:         512 538 14.9      535    577
  75%    5052
  80%    5063
                   vorher
                                              Percentage of the requests served within a certain time (ms)
  90%    6316                                   50%    535
  95% 11378                                     66%    541
  98% 11378                                     75%    553

                                                                             nachher
  99% 11378                                     80%    555
 100% 11378 (longest request)                   90%    559
                                                95%    559
                                                98%    566
                                                99%    577
                                               100%    577 (longest request)

                                                                                                                           34
APACHE JMETER

   verteilte Lasttests

   Java-Programm

   Client-Server-Architektur

   Testen von
      HTTP/S
      SOAP
      DB‘s via JDBC
      SMTP, POP3, IMAP
      ...




                                35
JMETER - TESTPLAN ERSTELLEN

   Manuell oder per HTTP Proxy Server




                                         36
JMETER - TESTPLAN ERSTELLEN

   Manuell oder per HTTP Proxy Server




                                         37
JMETER - TESTPLAN ERSTELLEN

   Manuell oder per HTTP Proxy Server




                                         37
JMETER - TESTPLAN ERSTELLEN

   Manuell oder per HTTP Proxy Server




                                         37
JMETER - USER EINLOGGEN




                          38
JMETER - USER EINLOGGEN




                          39
JMETER - USER EINLOGGEN




                          39
JMETER - USER EINLOGGEN




                          39
JMETER - USER EINLOGGEN




                          39
JMETER - PARALLELE ZUGRIFFE




                              40
JMETER - PARALLELE ZUGRIFFE




                              41
JMETER - BERICHTE




                    42
LINKLISTE

  Google Chrome: https://www.google.com/chrome
  Chrome DevTools: https://developers.google.com/chrome-
   developer-tools/?hl=de

    Xdebug: http://xdebug.org/
    PHPStorm: http://www.jetbrains.com/phpstorm/
    KCachegrind: http://kcachegrind.sourceforge.net
    WinCacheGrind: http://sourceforge.net/projects/wincachegrind/
    Webgrind: http://code.google.com/p/webgrind/

  XHProf: http://php.net/xhprof

  AB: http://httpd.apache.org/docs/2.0/programs/ab.html

  Jmeter: http://jmeter.apache.org/




                                                                     43
FRAGEN?
GERNE AUCH SPÄTER:
MAIL: R.BRUNS@TRAVIANGAMES.COM
TWITTER: @RENEBRUNS

More Related Content

PDF
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
PDF
Commencer avec le TDD
PDF
How to reverse engineer Android applications
ODP
Is your code ready for PHP 7 ?
ODP
The why and how of moving to php 5.4
PPTX
Writing php extensions in golang
PDF
How to deploy node to production
PDF
Guarding Your Code Against Bugs with Continuous Testing
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Commencer avec le TDD
How to reverse engineer Android applications
Is your code ready for PHP 7 ?
The why and how of moving to php 5.4
Writing php extensions in golang
How to deploy node to production
Guarding Your Code Against Bugs with Continuous Testing

What's hot (20)

PDF
An introduction to PHP 5.4
PDF
Understand study
PDF
Introduction to Node.JS
PDF
WAF protections and bypass resources
PPTX
PHP 5.6 New and Deprecated Features
PDF
Ninja Build: Simple Guide for Beginners
PDF
Php programming file
PDF
Google app engine python
PPT
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
PPT
Happy porting x86 application to android
PDF
Uazaa uma-farsa-parte 2
PDF
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
PDF
Laravel 4 package development
ODP
Android Nâng cao-Bài 9-Debug in Android Application Development
PDF
Laura Garcia - Shodan API and Coding Skills [rooted2019]
PDF
Learning Dtrace
PDF
Introduction To Embedding The PH7 PHP Engine in a C/C++ Host Application.
PDF
Php version 7
PDF
49368010 projectreportontraininganddevelopment(1)
PDF
DotDotPwn Fuzzer - Black Hat 2011 (Arsenal)
An introduction to PHP 5.4
Understand study
Introduction to Node.JS
WAF protections and bypass resources
PHP 5.6 New and Deprecated Features
Ninja Build: Simple Guide for Beginners
Php programming file
Google app engine python
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
Happy porting x86 application to android
Uazaa uma-farsa-parte 2
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
Laravel 4 package development
Android Nâng cao-Bài 9-Debug in Android Application Development
Laura Garcia - Shodan API and Coding Skills [rooted2019]
Learning Dtrace
Introduction To Embedding The PH7 PHP Engine in a C/C++ Host Application.
Php version 7
49368010 projectreportontraininganddevelopment(1)
DotDotPwn Fuzzer - Black Hat 2011 (Arsenal)
Ad

Viewers also liked (18)

PPT
Destitute Evaluation
PDF
Undang undang-republik-indonesia-nomor-5-tahun-2014
PDF
Uu no 36_2014
PDF
Uu0122012 full 2 pendidikan tinggi
PDF
Uu no 36_2014 full
PPT
Education issues
PDF
[Tony buzan] speed_memory(book_fi.org)
PPT
Destitute Evaluation
PPT
First Class Idea
PDF
Digitale Postkamer voor Gemeenten
PPT
Introduction To Scrum
PDF
Surat edaran tubel 2015(1)
PDF
Uu no. 38 th 2014 ttg keperawatan
PDF
Einblicke in die Fussangeln der weltweiten Browserspieleentwicklung - GameCam...
PPT
Errorcorrection1
PPTX
Speaking Online APAC 2013
PPT
Gemeente Midden-Drenthe gaat zaaksgewijs digitaal, door Jan Schrotenboer
PPT
Agile for managers
Destitute Evaluation
Undang undang-republik-indonesia-nomor-5-tahun-2014
Uu no 36_2014
Uu0122012 full 2 pendidikan tinggi
Uu no 36_2014 full
Education issues
[Tony buzan] speed_memory(book_fi.org)
Destitute Evaluation
First Class Idea
Digitale Postkamer voor Gemeenten
Introduction To Scrum
Surat edaran tubel 2015(1)
Uu no. 38 th 2014 ttg keperawatan
Einblicke in die Fussangeln der weltweiten Browserspieleentwicklung - GameCam...
Errorcorrection1
Speaking Online APAC 2013
Gemeente Midden-Drenthe gaat zaaksgewijs digitaal, door Jan Schrotenboer
Agile for managers
Ad

Similar to Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick (20)

PPTX
2012 coscup - Build your PHP application on Heroku
PDF
Why we choose Symfony2
PDF
More about PHP
PDF
Chicago Docker Meetup Presentation - Mediafly
PPTX
drupal ci cd concept cornel univercity.pptx
PDF
PHP Development Tools
PDF
PHP QA Tools
PDF
Php through the eyes of a hoster
PPTX
The power of linux advanced tracer [POUG18]
PDF
Convert Your Dev Environment to a Docker Stack - PHP Tek 2025.pdf
PDF
Php through the eyes of a hoster phpbnl11
PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PDF
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
PDF
Lean Php Presentation
PDF
AFUP Lorraine - Symfony Webpack Encore
PPTX
Kubernetes Navigation Stories – DevOpsStage 2019, Kyiv
PDF
The why and how of moving to php 8
PDF
Expressive Microservice Framework Blastoff
PDF
Make your application expressive
PDF
You're Off the Hook: Blinding Security Software
2012 coscup - Build your PHP application on Heroku
Why we choose Symfony2
More about PHP
Chicago Docker Meetup Presentation - Mediafly
drupal ci cd concept cornel univercity.pptx
PHP Development Tools
PHP QA Tools
Php through the eyes of a hoster
The power of linux advanced tracer [POUG18]
Convert Your Dev Environment to a Docker Stack - PHP Tek 2025.pdf
Php through the eyes of a hoster phpbnl11
Dependencies Managers in C/C++. Using stdcpp 2014
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Lean Php Presentation
AFUP Lorraine - Symfony Webpack Encore
Kubernetes Navigation Stories – DevOpsStage 2019, Kyiv
The why and how of moving to php 8
Expressive Microservice Framework Blastoff
Make your application expressive
You're Off the Hook: Blinding Security Software

Recently uploaded (20)

PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PPTX
Internet of Everything -Basic concepts details
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
EIS-Webinar-Regulated-Industries-2025-08.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
SaaS reusability assessment using machine learning techniques
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
Auditboard EB SOX Playbook 2023 edition.
Data Virtualization in Action: Scaling APIs and Apps with FME
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Internet of Everything -Basic concepts details
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
EIS-Webinar-Regulated-Industries-2025-08.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
giants, standing on the shoulders of - by Daniel Stenberg
Early detection and classification of bone marrow changes in lumbar vertebrae...
Co-training pseudo-labeling for text classification with support vector machi...
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
SaaS reusability assessment using machine learning techniques
Lung cancer patients survival prediction using outlier detection and optimize...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Module 1 Introduction to Web Programming .pptx
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...

Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick

  • 1. EIN STALL VOLLER TRÜFFELSCHWEINE (PHP)-Profiling-Tools im Überblick René Bruns - TNG Big Techday
  • 2. ÜBER MICH René Bruns  Entwickler seit 2001  seit 2009 bei Travian Games  seit 2011 Technical Director 2
  • 3. UND WER SEID IHR? 3
  • 4. UND WER SEID IHR? Entwickler? 3
  • 5. UND WER SEID IHR? Entwickler? Systemadministratoren? 3
  • 6. UND WER SEID IHR? Entwickler? Systemadministratoren? QA? 3
  • 7. UND WER SEID IHR? Entwickler? Systemadministratoren? C*O? QA? 3
  • 8. UND WER SEID IHR? Entwickler? Projektmanager? Systemadministratoren? C*O? QA? 3
  • 10. PROFILING? Profiler Es gibt unterschiedliche Problembereiche in der Softwareentwicklung, die durch ineffiziente Programmierung ausgelöst werden. Ein Profiler hilft dem Entwickler durch Analyse und Vergleich von laufenden Programmen die Problembereiche aufzudecken. http://de.wikipedia.org/wiki/Profiler_(Programmierung) 5
  • 11. AUSGANGSSITUATION SLOW!!11! 6
  • 12. PROFILING FRÜHER(?) class Main { public static function run() { $otherClass = new OtherClass(); $otherClass->doNothingImportant(); $dummy = new SlowClass(); $dummy->slowFunction(10); } } Main::run(); 7
  • 13. PROFILING FRÜHER(?) class Main { public static function run() { $start = microtime(true); printf ("Before OC: %f" . PHP_EOL, microtime(true) - $start); $otherClass = new OtherClass(); $otherClass->doNothingImportant(); printf ("After OC: %f" . PHP_EOL, microtime(true) - $start); printf ("Before SC: %f" . PHP_EOL, microtime(true) - $start); $dummy = new SlowClass(); $dummy->slowFunction(10); printf ("After SC: %f" . PHP_EOL, microtime(true) - $start); } } Main::run(); 8
  • 14. PROFILING FRÜHER(?) class Main { public static function run() { $start = microtime(true); printf ("Before OC: %f" . PHP_EOL, microtime(true) - $start); $otherClass = new OtherClass(); $otherClass->doNothingImportant(); printf ("After OC: %f" . PHP_EOL, microtime(true) - $start); printf ("Before SC: %f" . PHP_EOL, microtime(true) - $start); $dummy = new SlowClass(); $dummy->slowFunction(10); printf ("After SC: %f" . PHP_EOL, microtime(true) - $start); } } $ php Main.php Before OC: 0.000625 Main::run(); After OC: 0.004919 Before SC: 0.005099 .......... After SC: 10.013932 8
  • 15. PROFILING HEUTE  Viele verschiedene Fehlerquellen  Browser  Frontend  Backend  Datenbank  Services  Schwachstelle suchen  Vom Groben in‘s Feine 9
  • 16. SCHRITT 1: MELDUNG ÜBERPRÜFEN He‘s dead, Jim! 10
  • 17. SCHRITT 2: URSACHE EINKREISEN Browser 11
  • 18. SCHRITT 2: URSACHE EINKREISEN Browser Frontend 11
  • 19. SCHRITT 2: URSACHE EINKREISEN Browser Frontend Backend 11
  • 20. SCHRITT 2: URSACHE EINKREISEN Browser Frontend Backend DB 11
  • 21. BROWSER  Langsamer JS-Code  Zu hoher Speicherverbrauch  Zu viele CSS-Selektoren  Langsame Ladezeiten  Zu viele parallele Downloads  Offen gehaltene Verbindungen  Netzwerk  Internet  Antwort vom Server zu langsam -> Backend 12
  • 32. FRONTEND / BACKEND  Unnötige Schreib- / Lesezugriffe in Schleifen  Log-Ausgaben  Schleifen sind unnötig geschachtelt  Unnötig langsame Befehle benutzt  RegExp statt ==  Externer Service reagiert langsam  Datenbankabfrage dauert zu lange --> DB 20
  • 33. XDEBUG  PHP Extension by Derick Rethans  Kann per INI-Direktive aktiviert werden  breites Einsatzspektrum  Debugger  Profiler  Tracer  StackTrace-Formatter  ...  hoher Memory-/ CPU-/ IO-Footprint  Niemals(!) dauerhaft im Produktivbetrieb verwenden 21
  • 34. XDEBUG 22
  • 35. XDEBUG $ php -d xdebug.profiler_enable=1 -d xdebug.profiler_output_dir=. Main.php .......... 22
  • 36. XDEBUG $ php -d xdebug.profiler_enable=1 -d xdebug.profiler_output_dir=. Main.php .......... $ ls -l ca* -rwxrwxrwx 1 rene staff 4461 11 Jun 13:53 cachegrind.out.69408 22
  • 37. XDEBUG $ php -d xdebug.profiler_enable=1 -d xdebug.profiler_output_dir=. Main.php .......... $ ls -l ca* -rwxrwxrwx 1 rene staff 4461 11 Jun 13:53 cachegrind.out.69408 $ cat cachegrind.out.69408 version: 1 creator: xdebug 2.2.0 cmd: /Volumes/TCDATA/Sourcen/git/ProfilingTalk/Main.php part: 1 positions: line events: Time fl=/Volumes/TCDATA/Sourcen/git/ProfilingTalk/OtherClass.php fn=require_once::/Volumes/TCDATA/Sourcen/git/ProfilingTalk/OtherClass.php 1 42 fl=/Volumes/TCDATA/Sourcen/git/ProfilingTalk/SlowClass.php fn=require_once::/Volumes/TCDATA/Sourcen/git/ProfilingTalk/SlowClass.php 10 22
  • 38. XDEBUG  Cachegrind-Files können via KCachegrind, WinCachegrind, WebGrind oder PhpStorm-IDE ausgewertet werden.  Bsp. PhpStorm: 23
  • 39. XDEBUG  Cachegrind-Files können via KCachegrind, WinCachegrind, WebGrind oder PhpStorm-IDE ausgewertet werden.  Bsp. PhpStorm: 24
  • 40. XDEBUG 25
  • 41. XHPROF  PHP Extension by Facebook  Kann codeseitig aktiviert werden  Profiler only  sehr schlanker Footprint, daher auch im Livebetrieb einsetzbar (Monte Carlo-Algorithmus) 26
  • 42. XHPROF header.php: include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_lib.php'; include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); footer.php: include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_lib.php'; include_once '/usr/lib/php/pear/xhprof_lib/utils/xhprof_runs.php'; $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, 'testrene'); echo "http://localhost/~rene/xhprof_html/index.php?run={$run_id}&source=testrenen"; 27
  • 43. XHPROF $ php -d auto_append_fileo_prepend_file="header.php" -d auto_append_file="footer.php" Main.php .......... http://localhost/~rene/xhprof_html/index.php?run=4fd61a7e92aeb&source=testrene 28
  • 44. XHPROF $ php -d auto_append_fileo_prepend_file="header.php" -d auto_append_file="footer.php" Main.php .......... http://localhost/~rene/xhprof_html/index.php?run=4fd61a7e92aeb&source=testrene $ cat 4fd61a7e92aeb.testrene a:14:{s:23:"main()==>load::Main.php";a:5:{s:2:"ct";i:1;s:2:"wt";i:459;s:3:"cpu";i:1220;s: 2:"mu";i:10408;s:3:"pmu";i:0;}s:43:"main()==>load::ProfilingTalk/OtherClass.php";a:5:{s: 2:"ct";i:1;s:2:"wt";i:798;s:3:"cpu";i:113;s:2:"mu";i:6880;s:3:"pmu";i:0;}s: 47:"main()==>run_init::ProfilingTalk/OtherClass.php";a:5:{s:2:"ct";i:1;s:2:"wt";i:14;s:3:"cpu";i: 10;s:2:"mu";i:1104;s:3:"pmu";i:0;}s:42:"main()==>load::ProfilingTalk/SlowClass.php";a:5:{s: 2:"ct";i:1;s:2:"wt";i:467;s:3:"cpu";i:87;s:2:"mu";i:9648;s:3:"pmu";i:0;}s: 46:"main()==>run_init::ProfilingTalk/SlowClass.php";a:5:{s:2:"ct";i:1;s:2:"wt";i:9;s:3:"cpu";i: 7;s:2:"mu";i:1104;s:3:"pmu";i:0;}s:36:"OtherClass::doNothingImportant==>pow";a:5:{s: 2:"ct";i:1;s:2:"wt";i:1655;s:3:"cpu";i:926;s:2:"mu";i:1176;s:3:"pmu";i:0;}[...]} 28
  • 45. XHPROF 29
  • 46. XHPROF 30
  • 47. XHPROF 30
  • 48. DATENBANK  Unnötige Daten geladen  Kein/falscher Index benutzt  Daten werden nach der Abfrage noch sortiert  Langsame IOs  Falsche Systemeinstellungen (Buffer Sizes, ...) 31
  • 49. DB - EXPLAIN select LastName, FirstName, sum(UnitPrice * Quantity) from employees e inner join orders o on e.EmployeeID = o.EmployeeID inner join "Order Details" od on o.OrderID = od.OrderID group by LastName, FirstName; 32
  • 50. DB - EXPLAIN select LastName, FirstName, sum(UnitPrice * Quantity) from employees e inner join orders o on e.EmployeeID = o.EmployeeID inner join "Order Details" od on o.OrderID = od.OrderID group by LastName, FirstName; sqlite> explain query plan [...]; 0|0|0|SCAN TABLE employees AS e (~1000000 rows) 0|1|1|SEARCH TABLE orders AS o USING AUTOMATIC COVERING INDEX (EmployeeID=?) (~7 rows) 0|2|2|SEARCH TABLE Order Details AS od USING INDEX sqlite_autoindex_Order Details_1 (OrderID=?) (~10 rows) 0|0|0|USE TEMP B-TREE FOR GROUP BY 32
  • 51. DB - EXPLAIN select LastName, FirstName, sum(UnitPrice * Quantity) from employees e inner join orders o on e.EmployeeID = o.EmployeeID inner join "Order Details" od on o.OrderID = od.OrderID group by LastName, FirstName; sqlite> explain query plan [...]; 0|0|0|SCAN TABLE employees AS e (~1000000 rows) 0|1|1|SEARCH TABLE orders AS o USING AUTOMATIC COVERING INDEX (EmployeeID=?) (~7 rows) 0|2|2|SEARCH TABLE Order Details AS od USING INDEX sqlite_autoindex_Order Details_1 (OrderID=?) (~10 rows) 0|0|0|USE TEMP B-TREE FOR GROUP BY sqlite> explain [...]; 0|Trace|0|0|0||00| 1|SorterOpen|3|5|0|keyinfo(2,BINARY,BINARY)|00| 2|Integer|0|7|0||00| 3|Integer|0|6|0||00| 4|Null|0|10|11||00| 5|Gosub|9|74|0||00| 6|Goto|0|81|0||00| 7|OpenRead|0|120|0|3|00| 32
  • 52. SCHRITT 3: ERFOLG PRÜFEN  Hat die Optimierung etwas gebracht?  Vorher-Nachher-Check  Lasttests  Tools  Apache Benchmark (AB)  JMeter 33
  • 53. APACHE BENCHMARK (AB) $ ab -n 100 -c 10 http://localhost/~rene/talk/Main.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/2.2.21 Server Hostname: localhost Server Port: 80 Document Path: /~rene/talk/Main.php Document Length: 11 bytes Concurrency Level: 10 Time taken for tests: 56.692 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 22300 bytes HTML transferred: 1100 bytes Requests per second: 1.76 [#/sec] (mean) Time per request: 5669.198 [ms] (mean) Time per request: 566.920 [ms] (mean, across all concurrent requests) Transfer rate: 0.38 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 3660 2329.9 5022 6356 Processing: 0 1758 3060.0 0 11378 Waiting: 0 1757 3059.9 0 11377 Total: 5010 5417 1403.8 5030 11378 Percentage of the requests served within a certain time (ms) 50% 5030 66% 5040 75% 5052 80% 5063 90% 6316 95% 11378 vorher 98% 11378 99% 11378 100% 11378 (longest request) 34
  • 54. APACHE BENCHMARK (AB) $ ab -n 100 -c 10 http://localhost/~rene/talk/Main.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ $ ab -n 100 -c 10 http://localhost/~rene/talk/Main.php Benchmarking localhost (be patient).....done This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Server Software: Apache/2.2.21 Server Hostname: localhost Benchmarking localhost (be patient).....done Server Port: 80 Document Path: /~rene/talk/Main.php Server Software: Apache/2.2.21 Document Length: 11 bytes Server Hostname: localhost Server Port: 80 Concurrency Level: 10 Time taken for tests: 56.692 seconds Document Path: /~rene/talk/Main.php Complete requests: 100 Document Length: 11 bytes Failed requests: 0 Write errors: 0 Concurrency Level: 10 Total transferred: 22300 bytes Time taken for tests: 5.395 seconds HTML transferred: 1100 bytes Complete requests: 100 Requests per second: 1.76 [#/sec] (mean) Failed requests: 0 Time per request: 5669.198 [ms] (mean) Write errors: 0 Time per request: 566.920 [ms] (mean, across transferred: Total all concurrent requests) 22300 bytes Transfer rate: 0.38 [Kbytes/sec] received HTML transferred: 1100 bytes Requests per second: 18.54 [#/sec] (mean) Connection Times (ms) Time per request: 539.458 [ms] (mean) min mean[+/-sd] median max Time per request: 53.946 [ms] (mean, across all concurrent requests) Connect: 0 3660 2329.9 5022 6356 Transfer rate: 4.04 [Kbytes/sec] received Processing: 0 1758 3060.0 0 11378 Waiting: 0 1757 3059.9 0 11377 Connection Times (ms) Total: 5010 5417 1403.8 5030 11378 min mean[+/-sd] median max Connect: 0 395 217.3 531 577 Percentage of the requests served within a certain time (ms) 0 142 214.4 Processing: 1 559 50% 5030 Waiting: 0 142 214.6 0 559 66% 5040 Total: 512 538 14.9 535 577 75% 5052 80% 5063 vorher Percentage of the requests served within a certain time (ms) 90% 6316 50% 535 95% 11378 66% 541 98% 11378 75% 553 nachher 99% 11378 80% 555 100% 11378 (longest request) 90% 559 95% 559 98% 566 99% 577 100% 577 (longest request) 34
  • 55. APACHE JMETER  verteilte Lasttests  Java-Programm  Client-Server-Architektur  Testen von  HTTP/S  SOAP  DB‘s via JDBC  SMTP, POP3, IMAP  ... 35
  • 56. JMETER - TESTPLAN ERSTELLEN  Manuell oder per HTTP Proxy Server 36
  • 57. JMETER - TESTPLAN ERSTELLEN  Manuell oder per HTTP Proxy Server 37
  • 58. JMETER - TESTPLAN ERSTELLEN  Manuell oder per HTTP Proxy Server 37
  • 59. JMETER - TESTPLAN ERSTELLEN  Manuell oder per HTTP Proxy Server 37
  • 60. JMETER - USER EINLOGGEN 38
  • 61. JMETER - USER EINLOGGEN 39
  • 62. JMETER - USER EINLOGGEN 39
  • 63. JMETER - USER EINLOGGEN 39
  • 64. JMETER - USER EINLOGGEN 39
  • 65. JMETER - PARALLELE ZUGRIFFE 40
  • 66. JMETER - PARALLELE ZUGRIFFE 41
  • 68. LINKLISTE  Google Chrome: https://www.google.com/chrome  Chrome DevTools: https://developers.google.com/chrome- developer-tools/?hl=de  Xdebug: http://xdebug.org/  PHPStorm: http://www.jetbrains.com/phpstorm/  KCachegrind: http://kcachegrind.sourceforge.net  WinCacheGrind: http://sourceforge.net/projects/wincachegrind/  Webgrind: http://code.google.com/p/webgrind/  XHProf: http://php.net/xhprof  AB: http://httpd.apache.org/docs/2.0/programs/ab.html  Jmeter: http://jmeter.apache.org/ 43

Editor's Notes