understanding xhprof: pinpointing why your site is slow and how to fix it - stanford drupal camp...
DESCRIPTION
TRANSCRIPT
![Page 1: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/1.jpg)
Understanding XHProfPinpointing Why Your Site is Slow and How to Fix It
Ezra Gildesgame - Acquia@ezrabg
Stanford Drupal Camp 2014
![Page 2: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/2.jpg)
The Problem: Slow Websites/Web apps
• Unhappy users leave
• Severs can’t sustain load
![Page 3: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/3.jpg)
Every second counts
• http://blog.kissmetrics.com/loading-time/
![Page 4: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/4.jpg)
XHProf provides information about
execution time• Time spent by the server to generate page sent
to the web browser (or API endpoint)
• Also measures memory & CPU usage
![Page 5: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/5.jpg)
XHProf does not measure:
• Time to First Byte (TTFB)
• Page render time (happens in the browser)
• Other aspects of front-end performance
• For page render time, see Chrome Dev tools, YSlow
![Page 6: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/6.jpg)
Our goal: Reduce page execution
time
• Improve user experience
• Improve concurrency and efficient use of server resources.
![Page 7: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/7.jpg)
Avoid speculation:
• “Maybe it’s x”
• Wasted time on fruitless investigation
• Wasted time on inappropriate remediations
• Vague problem descriptions, “Eg, Views is slow”
![Page 8: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/8.jpg)
Misconceptions
![Page 9: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/9.jpg)
Misconceptions
![Page 10: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/10.jpg)
Be smart, m’kay?
• Tools like Views & Panels empower you to do inefficient things but aren’t necessarily bad for performance
• Views render & query, Panels pane caches are great tools to improve performance
![Page 11: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/11.jpg)
Example problem statement
• “Entity loads are slow because when we load entities, we load field X which also loads Y data, which spends Z time in the database. Page A loads 1,000 entities of type X.”
![Page 12: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/12.jpg)
Use XHProf to
• Pinpoint the root cause of performance problems
• Develop a surgical remediation plan
![Page 13: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/13.jpg)
Key UI Elements
• # of function calls
• Wall time (Inclusive/exclusive)
• Memory usage
• CPU time
![Page 14: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/14.jpg)
Exclusive/Inclusive
• Exclusive: This function only
• Inclusive: This function and all child functions
![Page 15: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/15.jpg)
CPU Time vs Wall Time
• CPU Time: Time spent by the CPU
• Wall time: Time including disk I/O
• CPU time != Wall time? Likely waiting for disk
![Page 16: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/16.jpg)
We may find:
• Function called many times unnecessarily
• Consider a static cache
![Page 17: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/17.jpg)
We may find:
• Slow queries
• Execute page again with Devel query log, use built-in explain feature
![Page 18: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/18.jpg)
We may find:
• Many fast queries that stack up
![Page 19: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/19.jpg)
We may find
![Page 20: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/20.jpg)
We may find
• Queries that are quick to execute but slow to assemble
![Page 21: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/21.jpg)
We may find:
• Excessive entity loads
• Excessive calls to memcache set/get
![Page 22: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/22.jpg)
What is “excessive”
• It depends! Know your app.
• Maybe you need that data on that request: Make it less expensive to compute
• Maybe you don’t need that data: Don’t compute it
![Page 23: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/23.jpg)
We may find:
• Page-blocking calls (eg, 3rd-party API requests)
• Queue these
![Page 24: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/24.jpg)
We may find:
• Excessive calls to watchdog()
• Notices can slow down your site.
• Fix those notices!
![Page 25: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/25.jpg)
We may find:
• Views/Panels render time - Dig deeper!
![Page 26: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/26.jpg)
We may find:
![Page 27: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/27.jpg)
Getting started
• Brew install xhprof
• Install: http://drupal.org/project/xhprof
• Alternative: https://github.com/msonnabaum/xhprof-single-file
![Page 28: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/28.jpg)
Avoid dirty runs.
• Eliminate menu rebuilds
• Disable Devel query log
• Disable XDebug - Really.
• Test as a non-admin (access control is expensive. We want to observe that.)
![Page 29: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/29.jpg)
Know which caches are in place
• Views caches (Disable Views caches: https://gist.github.com/msonnabaum/9671947)
• Panels Caches
• Other caches
![Page 30: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/30.jpg)
Other caches
![Page 31: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/31.jpg)
“ZOMG! The site is slow!”
• ORLY
• Develop a plan to measure and set goals
![Page 32: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/32.jpg)
“Slow” Define success with specific
performance goals
• Execution time on specific page logged in as specific user under specific conditions
• Quantify improvements on a per-page basis
![Page 33: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/33.jpg)
Example template
![Page 34: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/34.jpg)
Case examples
![Page 35: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/35.jpg)
Example 1
![Page 36: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/36.jpg)
Example: Static Caching in CToolshttps://drupal.org/node/2049087
• Eliminated ~128,000 calls to t()
• Reduced memory footprint
• Reduced page execution time by 2 seconds
• Simple fix
![Page 37: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/37.jpg)
Example: Static caching of node access grants
https://drupal.org/comment/8495029
• node_access_grants() never changes within a request
• Why compute it multiple times within a request?
![Page 38: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/38.jpg)
Example: Avoid unnecessary entity loads
https://drupal.org/node/2169099
![Page 39: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/39.jpg)
Optimize node access query building
https://drupal.org/comment/8516319
![Page 40: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014](https://reader033.vdocuments.us/reader033/viewer/2022042714/54bed6984a79590c798b482a/html5/thumbnails/40.jpg)
Questions?