About Me
• CTO of Dating DNA
• CIO of CEVO LLC
• Make Websites & iPhone Apps
• Worked on Websites for Dell, nVidia,
DirectTV, and other big clients.
Experience
• Lots of work with “Middle-Scale” websites.
• Lucky to Work on Fun Projects
• Lots of Web Service Stuff
• Learned most of this from other really
smart people.
MythBusters
• They get a Myth
• Break it down to its
different parts
• They Conduct a Bunch
of Tests
• They Draw Conclusions
• and have a Fun Time
Developers
• We get Myths
(Hey, this is slow)
• We Break it down to
the different pieces
• We Conduct a Bunch of
Tests.
• We Draw Conclusions
(and normally make
changes)
• and Have a Fun Time...
So Lets Get Started!
php /lets/get/started.php now
Common Performance
Claims (Myths)
• echo instead of print() • single quotes, not double
quotes
• echo commas, not
periods • include instead of
include_once
• don’t use custom
functions/classes • === faster than ==
• pass by reference • for faster than foreach
instead of by value
MythBusters Tested
• Keeping Your AC Off vs Windows Down
• Idling Better than Stop/Start
• Magical Aerodynamics
• Dirt-Free Filters
• Special Fuel Additives to Slow Burn
All Busted! They Didn’t Make a Difference,
Or Worsened Fuel Efficiency
How About
Driving Angry?
After Testing, Tory & Grant Used
33% More Fule While Driving Angry
Same Techniques
Apply to Both
• Some you’ll want to chose first depending
on your situation.
• You’ll want to be careful when profiling in
Production, you can make things worse.
Apache’s mod_status
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 25.131.42.122
</Location>
# ExtendedStatus On
XHProf
• Developed by Facebook
• Works well for both Development
& Production* Profiling
• pecl extension
• Decent UI for viewing Results
* - Use Sampling & Special CPU Flags for Production
http://mirror.facebook.net/facebook/xhprof/doc.html
XHGui
• Improved GUI
• Easy to Setup
• Built In Sampling
• Advanced Configuration
• MySQL Backend
• I recommend using this!
https://github.com/preinheimer/xhprof
Xdebug Profiler
• Install Xdebug
• Enable Xdebug Profiling
• Outputs a Cachegrind Log
• Use KCachegrind / WinCachegrind /
Webgrind to view
• For the Rich, MacCallGrind for $150
Enabling Xdebug
Profiling
xdebug.profiler_enable=1
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=cachegrind.out.%p
Xdebug Profiling Not for Production
(unless you have a 100TB HDD laying around)
Timing Points
• Most Frameworks have Built-In Profiling /
Timing Points
• Most ORMs have them as well
• You can do them yourself
• A must for Database Queries
Timing Points
$start = microtime(true); // true to get as float
/* Do your Crazy Code, i.e. query */
$end = microtime(true);
$time = round($end - $start, 4);
Other Tools
• Inclued
http://php.net/manual/en/book.inclued.php
• Memtrack
http://php.net/manual/en/
book.memtrack.php
Browser Static Files
Database and/or
Data Store
Web Server
PHP App
Server OS
Web Services &
Resources Hardware
Cache
Databases
• Typically, First Thing to Slow Down
• Things to that will Kill the DB:
• Missing Indexes
• Nested Queries
• Large Joins
• Locked Queries
Jet Profiler
• MySQL Profiler
• Free Version (Okay) & Paid (Awesome)
• Not Cheap ($399)
• But Worth It
• Analytics Over Time
vmstat
• swap > 0 means swapping
Memory Issue
• cpu sys + us really high
CPU / Code / PHP Problem
• cpu wa > 10
Disk IO Problem*
* - Technically could be Network IO as well, but typically
one of the last and more rare bottlenecks to hit
Whew, Lots of Tools
and a lot more out there not in this talk
Find any cool ones, let me know!
Normal Profiling
• Start with XHProf/XHGui and FireBug
• Avoid Premature Optimization
• Complicated Change
• Little Reward
• Use siege, or alternative, to simulate load.
Emergency Profiling
• Start with OS Level Testing Tools (htop,
vmstat, vnstat) to check Server
Performance
• Determine which Resource(s) are being
over utilized
• Finding the bottleneck is key