understanding xhprof: pinpointing why your site is slow and how to fix it - stanford drupal camp...

40
Understanding XHProf Pinpointing Why Your Site is Slow and How to Fix It Ezra Gildesgame - Acquia @ezrabg Stanford Drupal Camp 2014

Upload: ezra-gildesgame

Post on 21-Jan-2015

230 views

Category:

Software


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

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

The Problem: Slow Websites/Web apps

• Unhappy users leave

• Severs can’t sustain load

Page 4: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

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

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

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

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

Misconceptions

Page 9: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

Misconceptions

Page 10: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

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

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

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

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

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

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

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

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

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

We may find

Page 20: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

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

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

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

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

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

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

We may find:

Page 28: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

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

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

Other caches

Page 31: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

“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

“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

Example template

Page 34: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

Case examples

Page 35: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

Example 1

Page 36: Understanding XHProf: Pinpointing Why Your Site is Slow and How to Fix it - Stanford Drupal Camp 2014

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

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

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

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

Questions?