Profiling: a way to measure
where a program spends time.
Slide 3
Slide 3 text
Because performance
matters
• +1 second = -16% satisfaction rate
• 50% visitors will share bad experience
• 64% mobile users expect <4s load time
• +100ms = -1% of sales (for Amazon)
• +500ms = -25% of searches (Google)
Slide 4
Slide 4 text
Latency
• Network
• Web server
• Filesystem
• Application
• Database
• Rendering
Slide 5
Slide 5 text
Latency
• Network
• Web server
• Filesystem
• Application
• Database
• Rendering
PHP
Slide 6
Slide 6 text
Slide 7
Slide 7 text
Slide 8
Slide 8 text
Slide 9
Slide 9 text
Framework Specific
Slide 10
Slide 10 text
New Relic
(web monitoring with advanced features)
Slide 11
Slide 11 text
Features
• Application monitoring
• Integration with languages - PHP, Python, etc.
• Integration with frameworks - Symfony, etc.
• Plugins - varnish, etc.
• Fast
• Has free tear (24h retention)
Configure
In newrelic.ini file:
newrelic.enabled = true
newrelic.licence = “secret-licence”
newrelic.appname = “The next big thing”
Slide 14
Slide 14 text
Enable
• Cannot be enabled/disabled per request
• Is fast - designed for production monitoring
Slide 15
Slide 15 text
Dashboard
Slide 16
Slide 16 text
Transactions
Slide 17
Slide 17 text
Trace
Slide 18
Slide 18 text
XHProf
Slide 19
Slide 19 text
Features
• Free!
• Runs on your machine
• Fast enough (claimed to be OK for production)
• Detailed execution info
• Historical graphs
• Comparison of the runs
Configure 4/4
• Create a host for viewer on your server
OR
php -S 0:8080 -t xhprof_html/
Slide 25
Slide 25 text
Enable
• Always enabled (with this example)
• Configurable in header.php (when used):
if (rand(1, 100) <> 42) {
return;
}
Slide 26
Slide 26 text
Dashboard
Slide 27
Slide 27 text
Trace
Slide 28
Slide 28 text
Function View
Slide 29
Slide 29 text
Call Graph
Slide 30
Slide 30 text
XHGui
more sophisticated alternative web gui for XHProf
Slide 31
Slide 31 text
Xdebug
(not only a debugger)
Slide 32
Slide 32 text
Features
• Well known PHP Debugger
• Free!
• Generates widely used cachegrind files
• Broad choice of viewers
• On demand
• Only for dev (+15~30% execution time)
Enable
• Install“Xdebug helper”browser extension
• Enable Profiling in browser
Slide 36
Slide 36 text
QCacheGrind
also KCacheGrind, WinCacheGrind, WebCacheGrind, etc
Slide 37
Slide 37 text
Install
• QCacheGrind via homebrew on a Mac:
brew install qcachegrind
• WinCacheGrind via sourceforge on Windows:
http://sourceforge.net/projects/wincachegrind/
• Compile it from sources of KCacheGrind:
http://kcachegrind.sourceforge.net/
Slide 38
Slide 38 text
Dashboard
Slide 39
Slide 39 text
Function View
Slide 40
Slide 40 text
Call Graph
Slide 41
Slide 41 text
blackfire.io
low overhead profiler
Slide 42
Slide 42 text
Features
• “Profiling in the cloud”
• Free if you are using 20 slots
• Very quick to setup
• Can handle cachegrind and xhprof output files
• On demand
• fast
Slide 43
Slide 43 text
Install
1. Create a free account at http://blackfire.io
2. Add blackfire repository
curl -s https://packagecloud.io/gpg.key | sudo apt-key add -
echo "deb http://packages.blackfire.io/debian any main”
| sudo tee /etc/apt/sources.list.d/blackfire.list
sudo apt-get update
3. Install package:
sudo apt-get install blackfire-agent
Enable
• Install “Blackfire”browser extension
• Enable profiling in browser
Slide 46
Slide 46 text
Slot View
Slide 47
Slide 47 text
Function View
Slide 48
Slide 48 text
Metrics
Slide 49
Slide 49 text
Comparison
Slide 50
Slide 50 text
Final thoughts
Slide 51
Slide 51 text
Focusing on the
right problem.
Slide 52
Slide 52 text
No micro optimisations
• echo “something” vs echo ‘something’
• file_exists($file) vs is_file($file)
• isset($array[$key]) vs
array_key_exists($key, $array)
Slide 53
Slide 53 text
–Someone at BuildStuff 2014 (approximate)
“Find the biggest bottleneck.
Everything else is not your biggest
bottleneck.”
Slide 54
Slide 54 text
Monitoring first,
profiling later.
Slide 55
Slide 55 text
–Donald Knuth
“Premature optimisation is the root of
all evil.”
Slide 56
Slide 56 text
Monitoring is not
absolutely right.
Sometimes not accurate.
Sometimes reports false positives.
Slide 57
Slide 57 text
Exploit fast wins
• Caching
• CDN (akamai, cloudinary, etc)
• Opcode
• Latest software (PHP 5.6 anyone?)
• Reverse proxies (cloudflare, varnish)
• Moooooore server power!
• Do less?