Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Profiling PHP With XHProf

Profiling PHP With XHProf

Measuring and improving the performance of your PHP application is critical to giving your customers a great experience. To get a realistic view of where the time spent in PHP is actually going, you need to profile your code. XHProf is an open source, low overhead, robust profiling tool for PHP. This talk will explain how to install it, leverage its most important features, and solve the kinds of problems that XHProf can help identify. XHProf has a browser based UI, which makes it extremely easy to use and to share code profiles with coworkers. I will be demoing various traces, talking about PHP micro-optimizations, and showing you how to quickly drill down and find the slowest parts of your site. By using XHProf to identify the big wins, you can spend less time optimizing and more time building new features. You will come away from this talk with a working knowledge of XHProf, and the ability to get it up and running in your environment in minutes.

72f8175ac13e367bb500dd4da1f1aa32?s=128

Jonathan Klein

February 07, 2014
Tweet

Transcript

  1. Profiling PHP with XHProf SunshinePHP 2014 Jonathan Klein @jonathanklein Friday,

    February 7, 14
  2. Slides, Links: jkle.in/xhprof Friday, February 7, 14

  3. Who Am I? • Performance Engineer at Etsy • Boston

    Web Perf Meetup Organizer Friday, February 7, 14
  4. Friday, February 7, 14

  5. Friday, February 7, 14

  6. Etsy Stats Friday, February 7, 14

  7. Friday, February 7, 14

  8. Friday, February 7, 14

  9. Friday, February 7, 14

  10. Agenda Friday, February 7, 14

  11. Agenda • Why do you care? Friday, February 7, 14

  12. Agenda • Why do you care? • Installing XHProf/XHGui Friday,

    February 7, 14
  13. Agenda • Why do you care? • Installing XHProf/XHGui •

    Analyzing the data Friday, February 7, 14
  14. Agenda • Why do you care? • Installing XHProf/XHGui •

    Analyzing the data • Takeaways Friday, February 7, 14
  15. Part 1: Why do you care? Friday, February 7, 14

  16. Friday, February 7, 14

  17. Real World Examples http://www.phpied.com/the-performance-business-pitch/ Friday, February 7, 14

  18. Real World Examples • Shopzilla: -5 seconds = 7-12% increase

    in revenue http://www.phpied.com/the-performance-business-pitch/ Friday, February 7, 14
  19. Real World Examples • Shopzilla: -5 seconds = 7-12% increase

    in revenue • Firefox: -2.2 seconds = 15.4% more downloads http://www.phpied.com/the-performance-business-pitch/ Friday, February 7, 14
  20. Real World Examples • Shopzilla: -5 seconds = 7-12% increase

    in revenue • Firefox: -2.2 seconds = 15.4% more downloads • Google: +400ms = 0.76% fewer searches http://www.phpied.com/the-performance-business-pitch/ Friday, February 7, 14
  21. Real World Examples • Shopzilla: -5 seconds = 7-12% increase

    in revenue • Firefox: -2.2 seconds = 15.4% more downloads • Google: +400ms = 0.76% fewer searches • Amazon: +100ms = -1% revenue http://www.phpied.com/the-performance-business-pitch/ Friday, February 7, 14
  22. ~80% of page load time takes place on the client

    Friday, February 7, 14
  23. ...if your backend is fast Friday, February 7, 14

  24. A fast page load is 1 second This means you

    have 200ms to get that HTML to the client Friday, February 7, 14
  25. But network time could be ~100ms This means you have

    200ms 100ms to build the page Friday, February 7, 14
  26. < 100ms feels instant < 1 sec feels responsive <

    10 sec to keep user’s attention http://www.nngroup.com/articles/response-times-3-important-limits/ Friday, February 7, 14
  27. < 100ms feels instant < 1 sec feels responsive <

    10 sec to keep user’s attention Full Page Load – 1 Second http://www.nngroup.com/articles/response-times-3-important-limits/ Friday, February 7, 14
  28. < 100ms feels instant < 1 sec feels responsive <

    10 sec to keep user’s attention Full Page Load – 1 Second Base HTML – 200ms http://www.nngroup.com/articles/response-times-3-important-limits/ Friday, February 7, 14
  29. < 100ms feels instant < 1 sec feels responsive <

    10 sec to keep user’s attention Full Page Load – 1 Second Base HTML – 200ms Server Generation Time – 100ms http://www.nngroup.com/articles/response-times-3-important-limits/ Friday, February 7, 14
  30. #perfmatters Friday, February 7, 14

  31. Part 2: Installing XHProf/XHGui Friday, February 7, 14

  32. Steps Friday, February 7, 14

  33. Steps • Install MongoDB Friday, February 7, 14

  34. Steps • Install MongoDB • Install XHProf Friday, February 7,

    14
  35. Steps • Install MongoDB • Install XHProf • Install XHGui

    Friday, February 7, 14
  36. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  37. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  38. Friday, February 7, 14

  39. service mongod start Friday, February 7, 14

  40. pecl install mongo Friday, February 7, 14

  41. echo "extension=mongo.so" \ > /etc/php.d/mongo.ini Friday, February 7, 14

  42. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  43. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  44. pecl install xhprof-beta Friday, February 7, 14

  45. echo "extension=xhprof.so" \ > /etc/php.d/xhprof.ini Friday, February 7, 14

  46. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  47. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  48. Friday, February 7, 14

  49. cd path/to/xhgui php install.php Friday, February 7, 14

  50. Friday, February 7, 14

  51. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  52. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  53. 1% Sample Rate Friday, February 7, 14

  54. ab -n 500 -c 10 www.foo.com Friday, February 7, 14

  55. Friday, February 7, 14

  56. Steps • Install MongoDB • Install XHProf • Install XHGui

    • Generate some data Friday, February 7, 14
  57. Vagrant Friday, February 7, 14

  58. XHGui + Vagrant Friday, February 7, 14

  59. XHGui + Vagrant • Install VirtualBox Friday, February 7, 14

  60. XHGui + Vagrant • Install VirtualBox • Install Vagrant Friday,

    February 7, 14
  61. XHGui + Vagrant • Install VirtualBox • Install Vagrant •

    http://goo.gl/GS837H Friday, February 7, 14
  62. XHGui + Vagrant • Install VirtualBox • Install Vagrant •

    http://goo.gl/GS837H • vagrant up Friday, February 7, 14
  63. XHGui + Vagrant • Install VirtualBox • Install Vagrant •

    http://goo.gl/GS837H • vagrant up • http://localhost:8080 Friday, February 7, 14
  64. Friday, February 7, 14

  65. 1100MB File Friday, February 7, 14

  66. Friday, February 7, 14

  67. xhprof.jkle.in Friday, February 7, 14

  68. Part 3: Analyzing Results Friday, February 7, 14

  69. PrestaShop Friday, February 7, 14

  70. Friday, February 7, 14

  71. ab -n 500 -c 10 www.foo.com Friday, February 7, 14

  72. Friday, February 7, 14

  73. Friday, February 7, 14

  74. Friday, February 7, 14

  75. Friday, February 7, 14

  76. Friday, February 7, 14

  77. Friday, February 7, 14

  78. Friday, February 7, 14

  79. Disclaimer: This might break stuff Friday, February 7, 14

  80. Friday, February 7, 14

  81. Wordpress Friday, February 7, 14

  82. Friday, February 7, 14

  83. Friday, February 7, 14

  84. Friday, February 7, 14

  85. Friday, February 7, 14

  86. Friday, February 7, 14

  87. Friday, February 7, 14

  88. Friday, February 7, 14

  89. Friday, February 7, 14

  90. Friday, February 7, 14

  91. Friday, February 7, 14

  92. Find Problem Areas Friday, February 7, 14

  93. Frequent Issues Friday, February 7, 14

  94. Frequent Issues • Translation Friday, February 7, 14

  95. Frequent Issues • Translation • Tight loops Friday, February 7,

    14
  96. Frequent Issues • Translation • Tight loops • Configuration Friday,

    February 7, 14
  97. Frequent Issues • Translation • Tight loops • Configuration •

    Networked resources Friday, February 7, 14
  98. It’s Always the Database Friday, February 7, 14

  99. Workflow Friday, February 7, 14

  100. Workflow • Run XHProf Friday, February 7, 14

  101. Workflow • Run XHProf • Find expensive functions Friday, February

    7, 14
  102. Workflow • Run XHProf • Find expensive functions • Instrument

    with StatsD (optional) Friday, February 7, 14
  103. Workflow • Run XHProf • Find expensive functions • Instrument

    with StatsD (optional) • See performance in prod (optional) Friday, February 7, 14
  104. Workflow • Run XHProf • Find expensive functions • Instrument

    with StatsD (optional) • See performance in prod (optional) • Optimize Friday, February 7, 14
  105. Interlude: Pro Tips Friday, February 7, 14

  106. Pro Tip #1: Sort by # of calls Friday, February

    7, 14
  107. Friday, February 7, 14

  108. 40 Listings Friday, February 7, 14

  109. Friday, February 7, 14

  110. Look for multiples of 40 Friday, February 7, 14

  111. Pro Tip #2: Turn off CPU Measurement Friday, February 7,

    14
  112. Friday, February 7, 14

  113. Friday, February 7, 14

  114. Friday, February 7, 14

  115. Friday, February 7, 14

  116. Friday, February 7, 14

  117. Pro Tip #3: Call Graphs Friday, February 7, 14

  118. Friday, February 7, 14

  119. Friday, February 7, 14

  120. Pro Tip #4: Enable Via Query String Param Friday, February

    7, 14
  121. Friday, February 7, 14

  122. Pro Tip #5: Comparing Runs Friday, February 7, 14

  123. Friday, February 7, 14

  124. Friday, February 7, 14

  125. Friday, February 7, 14

  126. Friday, February 7, 14

  127. Friday, February 7, 14

  128. Aside: xdebug vs. XHProf Friday, February 7, 14

  129. Advantages of XHProf Friday, February 7, 14

  130. Advantages of XHProf • Nicer UI Friday, February 7, 14

  131. Advantages of XHProf • Nicer UI • Share-ability Friday, February

    7, 14
  132. Advantages of XHProf • Nicer UI • Share-ability • Ease

    of setup/configuration Friday, February 7, 14
  133. Advantages of XHProf • Nicer UI • Share-ability • Ease

    of setup/configuration • Hackability Friday, February 7, 14
  134. Part 4: Takeaways Friday, February 7, 14

  135. Profiling is Easy Friday, February 7, 14

  136. You Get What You Measure Friday, February 7, 14

  137. “Tools Not Rules” Friday, February 7, 14

  138. Get in Touch http://web-performance.meetup.com/ www.etsy.com/careers jonathan@etsy.com @jonathanklein Friday, February 7,

    14