Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
PROFILING PHP SEBASTIAN GRODZICKI
Slide 2
Slide 2 text
WHO USES PHP?
Slide 3
Slide 3 text
WHO USES PHP 7?
Slide 4
Slide 4 text
WHO USES PHP 7.1?
Slide 5
Slide 5 text
WHO USES PHPUNIT?
Slide 6
Slide 6 text
WHO USES XDEBUG?
Slide 7
Slide 7 text
WHO USES BLACKFIRE?
Slide 8
Slide 8 text
SEBASTIAN GRODZICKI CTO @ SHOWROOM
Slide 9
Slide 9 text
40% OF USERS ABANDON A WEBSITE THAT TAKES MORE THAN 3 SECONDS TO LOAD Akamai STATISTICS
Slide 10
Slide 10 text
500 MS DELAY CAUSED 20% TRAFFIC DECREASE Google STATISTICS
Slide 11
Slide 11 text
100 MS DELAY CAUSED 1% DROP IN REVENUE Amazon STATISTICS
Slide 12
Slide 12 text
PROFILING IS A WAY TO MEASURE WHERE A PROGRAM SPENDS TIME MathWorks DEFINITION
Slide 13
Slide 13 text
PROFILING IS ABOUT GATHERING DATA Fabien Potencier DEFINITION
Slide 14
Slide 14 text
MICROTIME
Slide 15
Slide 15 text
Slide 16
Slide 16 text
Slide 17
Slide 17 text
log_format foobar '$upstream_response_time'; access_log /var/log/nginx/access.log foobar;
Slide 18
Slide 18 text
MEMORY_GET_USAGE
Slide 19
Slide 19 text
Slide 20
Slide 20 text
PROS & CONS MICROTIME & MEMORY_GET_USAGE ▸ built in PHP ▸ no training required ▸ data without context ▸ require code change
Slide 21
Slide 21 text
Xdebug
Slide 22
Slide 22 text
xdebug.profiler_enable_trigger = 1 http://url?XDEBUG_PROFILE=1
Slide 23
Slide 23 text
KCACHEGRIND
Slide 24
Slide 24 text
WEBGRIND
Slide 25
Slide 25 text
PROS & CONS XDEBUG PROFILER ▸ zero code change ▸ cachegrind compatible file format ▸ extension required ▸ huge overhead ▸ unsuitable for production
Slide 26
Slide 26 text
XHProf
Slide 27
Slide 27 text
Slide 28
Slide 28 text
# jns/xhprof-bundle jns_xhprof: location_web: http://xhprof.localhost enabled: true
Slide 29
Slide 29 text
XHPROF
Slide 30
Slide 30 text
PROS & CONS XHPROF ▸ suitable for production ▸ diff reports ▸ no longer maintained ▸ missing PHP 7 support
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
No content
Slide 33
Slide 33 text
PROFILING PHP TIME Wall time I/O CPU Disk I/O Network = = + +
Slide 34
Slide 34 text
PROFILING PHP INCLUSIVE VS EXCLUSIVE TIME function foo() { $str = bar(); return $str; } function foo() { $str = bar(); return $str; }
Slide 35
Slide 35 text
BLACKFIRE CONTINUOUS PERFORMANCE TESTING
Slide 36
Slide 36 text
BLACKFIRE CALLGRAPHS
Slide 37
Slide 37 text
BLACKFIRE HOT PATHS
Slide 38
Slide 38 text
DEMO CHROME COMPANION
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
public function getVersion() { $process = new Process($this->getPath() . ' --version'); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } $version = substr($process->getOutput(), 12); return trim($version); }
Slide 42
Slide 42 text
public function getVersion() { static $version; if (null !== $version) { return trim($version); } $process = new Process($this->getPath() . ' --version'); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } $version = substr($process->getOutput(), 12); return trim($version); }
Slide 43
Slide 43 text
No content
Slide 44
Slide 44 text
DEMO BLACKFIRE CURL
Slide 45
Slide 45 text
No content
Slide 46
Slide 46 text
No content
Slide 47
Slide 47 text
DEMO BLACKFIRE RUN
Slide 48
Slide 48 text
No content
Slide 49
Slide 49 text
No content
Slide 50
Slide 50 text
ASSERTIONS
Slide 51
Slide 51 text
PROFILING PHP ASSERTIONS tests: "Application should never hit the DB": path: "/.*" assertions: - "metrics.sql.queries.count == 0"
Slide 52
Slide 52 text
PROFILING PHP ASSERTIONS tests: "Homepage should never call the API": path: "/" assertions: - "metrics.http.requests.count == 0"
Slide 53
Slide 53 text
PROFILING PHP ASSERTIONS tests: "Pages should be fast enough": path: "/.*" assertions: - "main.wall_time < 100ms"
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
BUILDS
Slide 56
Slide 56 text
No content
Slide 57
Slide 57 text
No content
Slide 58
Slide 58 text
No content
Slide 59
Slide 59 text
PHP SDK
Slide 60
Slide 60 text
BLACKFIRE PHP SDK ▸ composer require blackfire/php-sdk ▸ $blackfire = new \Blackfire\Client(); ▸ $probe = $blackfire->createProbe(); ▸ $profile = $blackfire->endProbe($probe);
Slide 61
Slide 61 text
PHPUNIT
Slide 62
Slide 62 text
assert('metrics.sql.queries.count < 5', 'SQL queries') ->assert('metrics.twig.render.count < 3', 'Rendered Twig templates') ->assert('metrics.twig.compile.count == 0', 'Twig compilation') ; } }
Slide 63
Slide 63 text
medium.com/@sgrodzicki
Slide 64
Slide 64 text
blackfire.io/docs/24-days
Slide 65
Slide 65 text
NEW RELIC
Slide 66
Slide 66 text
NEW RELIC
Slide 67
Slide 67 text
TIDEWAYS
Slide 68
Slide 68 text
TIDEWAYS
Slide 69
Slide 69 text
QUESTIONS?
Slide 70
Slide 70 text
THANK YOU! https://speakerdeck.com/sgrodzicki https://twitter.com/sebgrodzicki