Profiling php applications

  • 6,039 views
Uploaded on

PHP Profiling Tool

PHP Profiling Tool

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Great full stack of profiling tools
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
6,039
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
59
Comments
1
Likes
9

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

  • 1. Profiling PHP Applications July 2011 - Justin Carmony #uphpuwifi: C7bluffdale -- c7dcguest
  • 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. 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. We’ll Use An Example and an awesome one at that...
  • 5. We Have Similar Jobs Awesome, huh?
  • 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. 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. So Lets Get Started! php /lets/get/started.php now
  • 9. First Off, Some PHP Myths and there are a lot of them!
  • 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. To QuoteDerick Rethans Author of Xdebug...
  • 12. “I can only say one thing about this.... Complete & Utter Bull****”
  • 13. or in MythBusters Terminology....
  • 14. I’m Serious, There are a LOT of these MythsThese Example Came from Google’s Top 10 results for “php performance tips”
  • 15. These “PerformanceTips” Rarely Make a Difference
  • 16. Thats Like Debating the Windshield Wipers’s Effect on this Car’s Performance
  • 17. Intuition Based Optimizations i.e. how to not effectively improve performance Phrase Coined by Dave Smith http://thesmithfam.org/blog/2011/02/
  • 18. Your Intuitions are WRONG 90% of the time
  • 19. Example:Fuel Efficiency Myths
  • 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. How About Driving Angry? After Testing, Tory & Grant Used33% More Fule While Driving Angry
  • 22. Effective Profiling is based on Actual Results
  • 23. There are Two Typesof Profiling “Modes”
  • 24. Normal Profiling Lets Try this Configuration Changeand Measure the Performance Difference
  • 25. Emergency ProfilingAaaaaaaaaaaaah the Website is Down!!!! Why is it so slow??? Fix it!!!!!!
  • 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. Understanding the Full Picture
  • 28. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
  • 29. Don’t Panic!
  • 30. Goal: Find Slow Parts aka Bottlenecks
  • 31. Profiling & Testing Different Parts
  • 32. Tools!
  • 33. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
  • 34. FireBug
  • 35. FireBug
  • 36. Google Page Speed
  • 37. Other Tools• YSlow http://developer.yahoo.com/yslow/• Pingdom Tools http://tools.pingdom.com/• WireShark / Fiddler2
  • 38. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
  • 39. apachetopapachetop -f /var/log/apache/example.com.access.log
  • 40. Apachetop works with nginx
  • 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. Apache’s mod_status
  • 43. siege
  • 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. 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. siege
  • 47. siege
  • 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. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
  • 50. My Favorite New Tools: XHProf & XHGui
  • 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. XHGui• Improved GUI• Easy to Setup• Built In Sampling• Advanced Configuration• MySQL Backend• I recommend using this! https://github.com/preinheimer/xhprof
  • 53. More Fun to Show Demo Time
  • 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. 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. Webgrind
  • 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. 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. Other Tools• Inclued http://php.net/manual/en/book.inclued.php• Memtrack http://php.net/manual/en/ book.memtrack.php
  • 60. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
  • 61. Databases• Typically, First Thing to Slow Down• Things to that will Kill the DB: • Missing Indexes • Nested Queries • Large Joins • Locked Queries
  • 62. Jet Profiler• MySQL Profiler• Free Version (Okay) & Paid (Awesome)• Not Cheap ($399) • But Worth It• Analytics Over Time
  • 63. Jet Profiler
  • 64. MySQL Commands• explain <query>• show processlist• show variables• show status
  • 65. mtop
  • 66. Browser Static Files Database and/or Data Store Web Server PHP App Server OSWeb Services & Resources Hardware Cache
  • 67. vmstatcommand: vmstat 1
  • 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. vnstatcommand: vnstat -l -i eth0
  • 70. top
  • 71. htop
  • 72. strace
  • 73. iotop
  • 74. Other Tools• netstat• iostat• mpstat• pidstat• (on ubuntu, install via sysstat package)
  • 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. Monitoring Muninhttp://munin-monitoring.org/
  • 77. Monitoring Wormlyhttp://wormly.com/
  • 78. Whew, Lots of Tools and a lot more out there not in this talk Find any cool ones, let me know!
  • 79. Normal Profiling• Start with XHProf/XHGui and FireBug• Avoid Premature Optimization • Complicated Change • Little Reward• Use siege, or alternative, to simulate load.
  • 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. Emergency Profiling• What Changed? • Increased Traffic? • New Feature? • Something Failed/Down?• Don’t Panic & Start Wildly Guessing
  • 82. Few Final Thoughts
  • 83. The Better You Understand The ProblemThe Better You Can Fix It
  • 84. Don’tPut Off ProfilingUntil there is anEmergency
  • 85. You Can Throw Hardward at theProblem, but Avoid IT
  • 86. Ask Others for Ideas akaBrainstorming
  • 87. Good Luck!
  • 88. Questions?
  • 89. Thanks! Twitter: JustinCarmony IRC: carmony #uphpu #phpc #joind.in Website:http://www.justincarmony.com/blog Email: justin@justincarmony.com