Your SlideShare is downloading. ×
0
Profiling PHP  Applications    July 2011 - Justin Carmony            #uphpuwifi: C7bluffdale -- c7dcguest
About Me• CTO of Dating DNA• CIO of CEVO LLC• Make Websites & iPhone Apps• Worked on Websites for Dell, nVidia,  DirectTV,...
Experience• Lots of work with “Middle-Scale” websites.• Lucky to Work on Fun Projects• Lots of Web Service Stuff• Learned ...
We’ll Use An Example    and an awesome one at that...
We Have Similar Jobs      Awesome, huh?
MythBusters•   They get a Myth•   Break it down to its    different parts•   They Conduct a Bunch    of Tests•   They Draw...
Developers•   We get Myths    (Hey, this is slow)•   We Break it down to    the different pieces•   We Conduct a Bunch of ...
So Lets Get Started!   php /lets/get/started.php now
First Off, Some  PHP Myths and there are a lot of them!
Common Performance  Claims (Myths)•   echo instead of print()   •   single quotes, not double                             ...
To QuoteDerick Rethans   Author of Xdebug...
“I can only say one thing about this....           Complete & Utter         Bull****”
or in MythBusters Terminology....
I’m Serious, There are a  LOT of these MythsThese Example Came from Google’s Top 10 results for              “php performa...
These “PerformanceTips” Rarely Make a     Difference
Thats Like Debating the Windshield Wipers’s      Effect on this Car’s Performance
Intuition Based Optimizations  i.e. how to not effectively     improve performance      Phrase Coined by Dave Smith   http...
Your Intuitions are    WRONG      90% of the time
Example:Fuel Efficiency Myths
MythBusters Tested• Keeping Your AC Off vs Windows Down• Idling Better than Stop/Start• Magical Aerodynamics• Dirt-Free Fi...
How About   Driving Angry? After Testing, Tory & Grant Used33% More Fule While Driving Angry
Effective Profiling   is based on Actual Results
There are Two Typesof Profiling “Modes”
Normal Profiling   Lets Try this Configuration Changeand Measure the Performance Difference
Emergency ProfilingAaaaaaaaaaaaah the Website is Down!!!!    Why is it so slow??? Fix it!!!!!!
Same Techniques      Apply to Both• Some you’ll want to chose first depending  on your situation.• You’ll want to be carefu...
Understanding the   Full Picture
Browser                        Static Files                                                       Database and/or         ...
Don’t Panic!
Goal: Find Slow Parts  aka Bottlenecks
Profiling & Testing Different Parts
Tools!
Browser                        Static Files                                                       Database and/or         ...
FireBug
FireBug
Google Page Speed
Other Tools• YSlow  http://developer.yahoo.com/yslow/• Pingdom Tools  http://tools.pingdom.com/• WireShark / Fiddler2
Browser                        Static Files                                                       Database and/or         ...
apachetopapachetop -f /var/log/apache/example.com.access.log
Apachetop works   with nginx
Apache’s mod_status   <Location /server-status>   SetHandler server-status   Order Deny,Allow   Deny from all   Allow from...
Apache’s mod_status
siege
siege• Command Line Tool• Run Concurrent HTTP Requests• Runs on Linux & Mac OS• Windows Users: Run a VM• Great Way to Test...
siege• Create txt file with lists of URLs to hit• Run Command:  siege -c 10 -r 10 -f urls.txt• c = concurrent  r = # of req...
siege
siege
Other Tools• nginx stub status (similar to mod_status)  http://wiki.nginx.org/HttpStubStatusModule• Apache Bench & http_lo...
Browser                        Static Files                                                       Database and/or         ...
My Favorite New Tools:  XHProf & XHGui
XHProf• Developed by Facebook• Works well for both Development  & Production* Profiling• pecl extension• Decent UI for view...
XHGui• Improved GUI• Easy to Setup• Built In Sampling• Advanced Configuration• MySQL Backend• I recommend using this!   htt...
More Fun to Show     Demo Time
Xdebug Profiler• Install Xdebug• Enable Xdebug Profiling• Outputs a Cachegrind Log• Use KCachegrind / WinCachegrind /  Webgr...
Enabling Xdebug           Profilingxdebug.profiler_enable=1xdebug.profiler_output_dir=/tmpxdebug.profiler_output_name=cachegri...
Webgrind
Timing Points• Most Frameworks have Built-In Profiling /  Timing Points• Most ORMs have them as well• You can do them yours...
Timing Points$start = microtime(true); // true to get as float/* Do your Crazy Code, i.e. query */$end = microtime(true);$t...
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         ...
Databases• Typically, First Thing to Slow Down• Things to that will Kill the DB:   • Missing Indexes   • Nested Queries   ...
Jet Profiler• MySQL Profiler• Free Version (Okay) & Paid (Awesome)• Not Cheap ($399) • But Worth It• Analytics Over Time
Jet Profiler
MySQL Commands• explain <query>• show processlist• show variables• show status
mtop
Browser                        Static Files                                                       Database and/or         ...
vmstatcommand: vmstat 1
vmstat• swap > 0 means swapping  Memory Issue• cpu sys + us really high  CPU / Code / PHP Problem• cpu wa > 10  Disk IO Pr...
vnstatcommand: vnstat -l -i eth0
top
htop
strace
iotop
Other Tools• netstat• iostat• mpstat• pidstat• (on ubuntu, install via sysstat package)
Other Tools• grep, awk, sed• IPs Connected:  netstat -plan | grep :80 | awk {print $5} |  sed s/::ffff://g | awk -F: {prin...
Monitoring           Muninhttp://munin-monitoring.org/
Monitoring     Wormlyhttp://wormly.com/
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 Rewar...
Emergency Profiling• Start with OS Level Testing Tools (htop,  vmstat, vnstat) to check Server  Performance• Determine whic...
Emergency Profiling• What Changed?   • Increased Traffic?   • New Feature?   • Something Failed/Down?• Don’t Panic & Start W...
Few Final Thoughts
The Better You Understand   The ProblemThe Better You Can     Fix It
Don’tPut Off ProfilingUntil there is anEmergency
You Can Throw  Hardward at theProblem, but Avoid IT
Ask Others for Ideas        akaBrainstorming
Good Luck!
Questions?
Thanks!     Twitter: JustinCarmony         IRC: carmony     #uphpu #phpc #joind.in             Website:http://www.justinca...
Profiling php applications
Profiling php applications
Profiling php applications
Upcoming SlideShare
Loading in...5
×

Profiling php applications

6,405

Published on

PHP Profiling Tool

Published in: Technology
1 Comment
10 Likes
Statistics
Notes
  • Great full stack of profiling tools
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
6,405
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
64
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript of "Profiling php applications"

    1. 1. Profiling PHP Applications July 2011 - Justin Carmony #uphpuwifi: C7bluffdale -- c7dcguest
    2. 2. 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.
    3. 3. 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.
    4. 4. We’ll Use An Example and an awesome one at that...
    5. 5. We Have Similar Jobs Awesome, huh?
    6. 6. 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
    7. 7. 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...
    8. 8. So Lets Get Started! php /lets/get/started.php now
    9. 9. First Off, Some PHP Myths and there are a lot of them!
    10. 10. 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
    11. 11. To QuoteDerick Rethans Author of Xdebug...
    12. 12. “I can only say one thing about this.... Complete & Utter Bull****”
    13. 13. or in MythBusters Terminology....
    14. 14. I’m Serious, There are a LOT of these MythsThese Example Came from Google’s Top 10 results for “php performance tips”
    15. 15. These “PerformanceTips” Rarely Make a Difference
    16. 16. Thats Like Debating the Windshield Wipers’s Effect on this Car’s Performance
    17. 17. Intuition Based Optimizations i.e. how to not effectively improve performance Phrase Coined by Dave Smith http://thesmithfam.org/blog/2011/02/
    18. 18. Your Intuitions are WRONG 90% of the time
    19. 19. Example:Fuel Efficiency Myths
    20. 20. 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
    21. 21. How About Driving Angry? After Testing, Tory & Grant Used33% More Fule While Driving Angry
    22. 22. Effective Profiling is based on Actual Results
    23. 23. There are Two Typesof Profiling “Modes”
    24. 24. Normal Profiling Lets Try this Configuration Changeand Measure the Performance Difference
    25. 25. Emergency ProfilingAaaaaaaaaaaaah the Website is Down!!!! Why is it so slow??? Fix it!!!!!!
    26. 26. 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.
    27. 27. Understanding the Full Picture
    28. 28. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
    29. 29. Don’t Panic!
    30. 30. Goal: Find Slow Parts aka Bottlenecks
    31. 31. Profiling & Testing Different Parts
    32. 32. Tools!
    33. 33. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
    34. 34. FireBug
    35. 35. FireBug
    36. 36. Google Page Speed
    37. 37. Other Tools• YSlow http://developer.yahoo.com/yslow/• Pingdom Tools http://tools.pingdom.com/• WireShark / Fiddler2
    38. 38. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
    39. 39. apachetopapachetop -f /var/log/apache/example.com.access.log
    40. 40. Apachetop works with nginx
    41. 41. 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
    42. 42. Apache’s mod_status
    43. 43. siege
    44. 44. siege• Command Line Tool• Run Concurrent HTTP Requests• Runs on Linux & Mac OS• Windows Users: Run a VM• Great Way to Test End Result
    45. 45. siege• Create txt file with lists of URLs to hit• Run Command: siege -c 10 -r 10 -f urls.txt• c = concurrent r = # of requests f = path to URL file
    46. 46. siege
    47. 47. siege
    48. 48. Other Tools• nginx stub status (similar to mod_status) http://wiki.nginx.org/HttpStubStatusModule• Apache Bench & http_load -- CLI• JMeter -- Java Desktop App
    49. 49. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
    50. 50. My Favorite New Tools: XHProf & XHGui
    51. 51. 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
    52. 52. XHGui• Improved GUI• Easy to Setup• Built In Sampling• Advanced Configuration• MySQL Backend• I recommend using this! https://github.com/preinheimer/xhprof
    53. 53. More Fun to Show Demo Time
    54. 54. Xdebug Profiler• Install Xdebug• Enable Xdebug Profiling• Outputs a Cachegrind Log• Use KCachegrind / WinCachegrind / Webgrind to view• For the Rich, MacCallGrind for $150
    55. 55. Enabling Xdebug Profilingxdebug.profiler_enable=1xdebug.profiler_output_dir=/tmpxdebug.profiler_output_name=cachegrind.out.%p Xdebug Profiling Not for Production (unless you have a 100TB HDD laying around)
    56. 56. Webgrind
    57. 57. 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
    58. 58. 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);
    59. 59. Other Tools• Inclued http://php.net/manual/en/book.inclued.php• Memtrack http://php.net/manual/en/ book.memtrack.php
    60. 60. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
    61. 61. Databases• Typically, First Thing to Slow Down• Things to that will Kill the DB: • Missing Indexes • Nested Queries • Large Joins • Locked Queries
    62. 62. Jet Profiler• MySQL Profiler• Free Version (Okay) & Paid (Awesome)• Not Cheap ($399) • But Worth It• Analytics Over Time
    63. 63. Jet Profiler
    64. 64. MySQL Commands• explain <query>• show processlist• show variables• show status
    65. 65. mtop
    66. 66. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
    67. 67. vmstatcommand: vmstat 1
    68. 68. 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
    69. 69. vnstatcommand: vnstat -l -i eth0
    70. 70. top
    71. 71. htop
    72. 72. strace
    73. 73. iotop
    74. 74. Other Tools• netstat• iostat• mpstat• pidstat• (on ubuntu, install via sysstat package)
    75. 75. Other Tools• grep, awk, sed• IPs Connected: netstat -plan | grep :80 | awk {print $5} | sed s/::ffff://g | awk -F: {print $1} | sort | uniq -c | sort -n
    76. 76. Monitoring Muninhttp://munin-monitoring.org/
    77. 77. Monitoring Wormlyhttp://wormly.com/
    78. 78. Whew, Lots of Tools and a lot more out there not in this talk Find any cool ones, let me know!
    79. 79. Normal Profiling• Start with XHProf/XHGui and FireBug• Avoid Premature Optimization • Complicated Change • Little Reward• Use siege, or alternative, to simulate load.
    80. 80. 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
    81. 81. Emergency Profiling• What Changed? • Increased Traffic? • New Feature? • Something Failed/Down?• Don’t Panic & Start Wildly Guessing
    82. 82. Few Final Thoughts
    83. 83. The Better You Understand The ProblemThe Better You Can Fix It
    84. 84. Don’tPut Off ProfilingUntil there is anEmergency
    85. 85. You Can Throw Hardward at theProblem, but Avoid IT
    86. 86. Ask Others for Ideas akaBrainstorming
    87. 87. Good Luck!
    88. 88. Questions?
    89. 89. Thanks! Twitter: JustinCarmony IRC: carmony #uphpu #phpc #joind.in Website:http://www.justincarmony.com/blog Email: justin@justincarmony.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×