Top Banner
Effectively Monitoring Client-Side Performance Andrew Rota Guidebook app: NEPHP2016
100

Effectively Monitoring Client-Side Performance: NEPHP2016

Apr 16, 2017

Download

Software

Andrew Rota
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Effectively Monitoring Client-Side Performance: NEPHP2016

Effectively Monitoring Client-Side Performance

Andrew RotaGuidebook app: NEPHP2016

Page 2: Effectively Monitoring Client-Side Performance: NEPHP2016

Effectively Monitoring Client-Side PerformanceNEPHP 2016 | @AndrewRota

Page 3: Effectively Monitoring Client-Side Performance: NEPHP2016

1. Client-Side Performance 2. Collect + Monitor 3. Effectively

Page 4: Effectively Monitoring Client-Side Performance: NEPHP2016

Andrew RotaSoftware Engineer, .

@andrewrota github.com/andrewrota

Boston, MA

Page 5: Effectively Monitoring Client-Side Performance: NEPHP2016

Web Performance

Page 6: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 7: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 8: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 9: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 10: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 11: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 12: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 13: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 14: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 15: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 16: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 17: Effectively Monitoring Client-Side Performance: NEPHP2016

Client-Side Web Performance

Page 18: Effectively Monitoring Client-Side Performance: NEPHP2016

Measuring Performance

Page 19: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation

Render

Additional Resources

Interaction

Page 20: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation

Render

Additional Resources

Interaction

Page 21: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation

Render

Additional Resources

Interaction

Page 22: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation

Render

Additional Resources

Interaction

Page 23: Effectively Monitoring Client-Side Performance: NEPHP2016

There’s no single metric for measuring web

performance

Page 24: Effectively Monitoring Client-Side Performance: NEPHP2016

Performance Metric Sources

1. Observational data 2. Browser devtools 3. Browser reported metrics

Page 25: Effectively Monitoring Client-Side Performance: NEPHP2016

Observational Data

Page 26: Effectively Monitoring Client-Side Performance: NEPHP2016

Performance Metric Sources

1. Observational data 2. Browser devtools 3. Browser reported metrics

Page 27: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser Profiling Metrics

Page 28: Effectively Monitoring Client-Side Performance: NEPHP2016

Performance Metric Sources

1. Observational data 2. Browser devtools 3. Browser reported metrics

Page 29: Effectively Monitoring Client-Side Performance: NEPHP2016

Performance Metric Sources

1. Observational data 2. Browser devtools 3. Browser reported metrics

• Navigation Timing API • Paint metrics • Custom Metrics

Page 30: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation Timing API

Page 31: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation Timing API• navigationStart • unloadEventStart • unloadEventEnd • redirectStart • redirectEnd • fetchStart • domainLookupStart • domainLookupEnd • connectStart • connectEnd

• secureConnectionStart • requestStart • responseStart • responseEnd • domLoading • domInteractive • domContentLoadedEventStart • domContentLoadedEventEnd

• domComplete • loadEventStart • loadEventEnd

Page 32: Effectively Monitoring Client-Side Performance: NEPHP2016

Navigation Timing API• navigationStart - navigation initiated • responseStart - first byte of doc from server • responseEnd - last byte of doc from server • domInteractive - HTML parsed, DOM constructed • domContentLoaded - DOM and CSSOM constructed • domComplete/load - all subresources loaded

Page 33: Effectively Monitoring Client-Side Performance: NEPHP2016

navigationStart

responseStartresponseEnd

domInteractive

domContentLoaded

domComplete

Page 34: Effectively Monitoring Client-Side Performance: NEPHP2016

Paint Metrics

window.performance.timing.msFirstPaint

window.chrome.loadTimes().firstPaintTime

Internet Explorer

Chrome

Page 35: Effectively Monitoring Client-Side Performance: NEPHP2016

firstPaint

Page 36: Effectively Monitoring Client-Side Performance: NEPHP2016

Custom Metricswindow.performance.now()

Page 37: Effectively Monitoring Client-Side Performance: NEPHP2016

Custom Metricswindow.performance.mark(‘mainImageLoaded’)

window.performance .getEntriesByName(‘mainImageLoaded’)[0] .startTime

Page 38: Effectively Monitoring Client-Side Performance: NEPHP2016

mainImageLoaded

tableSorted

Page 39: Effectively Monitoring Client-Side Performance: NEPHP2016

Making Metrics Meaningful

Page 40: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 41: Effectively Monitoring Client-Side Performance: NEPHP2016

Traditional Site Visit Lifecycle

Page 42: Effectively Monitoring Client-Side Performance: NEPHP2016

Page 1

Page 2

Page 3

Page 4

Page 43: Effectively Monitoring Client-Side Performance: NEPHP2016

But what about single page applications (SPAs)?

Page 44: Effectively Monitoring Client-Side Performance: NEPHP2016

Page 1

Page 2

Page 3

Page 4

Page 45: Effectively Monitoring Client-Side Performance: NEPHP2016

SPAs can improve performance, but complicate

performance metrics

Page 46: Effectively Monitoring Client-Side Performance: NEPHP2016

With SPAs, 1) write scripts for actions, and 2) double down on custom metrics.

Page 47: Effectively Monitoring Client-Side Performance: NEPHP2016

Determine meaningful abstract metrics on top of low-level browser/app metrics

Page 48: Effectively Monitoring Client-Side Performance: NEPHP2016

Can we automate, collect, and monitor these metrics?

Page 49: Effectively Monitoring Client-Side Performance: NEPHP2016

1. Client-Side Performance 2. Collect + Monitor 3. Effectively

Page 50: Effectively Monitoring Client-Side Performance: NEPHP2016

1. Real User Monitoring (RUM)

2. Synthetic

Collecting Performance Metrics

Page 51: Effectively Monitoring Client-Side Performance: NEPHP2016

RUM Performance Metrics

Users Collect Metrics

Page 52: Effectively Monitoring Client-Side Performance: NEPHP2016

Sources for RUM Metrics1. Observational data 2. Browser devtools 3. Browser reported metrics

• Navigation Timing API • Paint metrics • Custom Metrics

Page 53: Effectively Monitoring Client-Side Performance: NEPHP2016

Tools for RUM Metrics

Page 54: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser reported metrics Collect Metrics

Send Metrics (XHR)

Page 55: Effectively Monitoring Client-Side Performance: NEPHP2016

Tools for RUM Metrics

• Custom JavaScript • Open source JS libraries

• github.com/lognormal/boomerang

Page 56: Effectively Monitoring Client-Side Performance: NEPHP2016

Synthetic Performance Metrics

Automated Test Collect Metrics

Page 57: Effectively Monitoring Client-Side Performance: NEPHP2016

Sources for Synthetic Metrics

1. Observational data 2. Browser devtools 3. Browser reported metrics

• Navigation Timing API • Paint metrics • Custom Metrics

Page 58: Effectively Monitoring Client-Side Performance: NEPHP2016

Tools for Synthetic Performance Metrics

Scheduler “Browser” + Test Runner

Page 59: Effectively Monitoring Client-Side Performance: NEPHP2016

Schedulers

• Cron

> 0 * * * * /path/to/script.sh

Page 60: Effectively Monitoring Client-Side Performance: NEPHP2016

Schedulers

• Cron

• Continuous integration server • Jenkins

> 0 * * * * /path/to/script.sh

Page 61: Effectively Monitoring Client-Side Performance: NEPHP2016

Synthetic test runners• Phantomas • Browser-Perf • WebPagetest • Lighthouse

Page 62: Effectively Monitoring Client-Side Performance: NEPHP2016

Phantomas

Headless Browsers

Page 63: Effectively Monitoring Client-Side Performance: NEPHP2016

Phantomas> phantomas http://reddit.com

{ "metrics": { "requests": 73, "bodySize": 580491, "contentLength": 629382, "timeToFirstByte": 94, "timeToLastByte": 105, "DOMqueries": 247, "firstPaint": 0, "domInteractive": 215, "domContentLoaded": 213, "domContentLoadedEnd": 355, "domComplete": 792, "httpsRequests": [ "https://www.reddit.com/", "https://www.redditstatic.com/reddit-init.en.qq9nT0inXvw.js", "https://www.redditstatic.com/reddit.en.xlHlxcJziiU.js", "https://www.redditstatic.com/reddit.ooBJpEoO9vY.css", "https://www.google-analytics.com/analytics.js" ] // … and more! } }

Page 64: Effectively Monitoring Client-Side Performance: NEPHP2016

Phantomas> phantomas http://reddit.com

{ "metrics": { "requests": 73, "bodySize": 580491, "contentLength": 629382, "timeToFirstByte": 94, "timeToLastByte": 105, "DOMqueries": 247, "firstPaint": 0, "domInteractive": 215, "domContentLoaded": 213, "domContentLoadedEnd": 355, "domComplete": 792, "httpsRequests": [ "https://www.reddit.com/", "https://www.redditstatic.com/reddit-init.en.qq9nT0inXvw.js", "https://www.redditstatic.com/reddit.en.xlHlxcJziiU.js", "https://www.redditstatic.com/reddit.ooBJpEoO9vY.css", "https://www.google-analytics.com/analytics.js" ] // … and more! } }

Page 65: Effectively Monitoring Client-Side Performance: NEPHP2016

Phantomas> phantomas http://reddit.com

{ "metrics": { "requests": 73, "bodySize": 580491, "contentLength": 629382, "timeToFirstByte": 94, "timeToLastByte": 105, "DOMqueries": 247, "firstPaint": 0, "domInteractive": 215, "domContentLoaded": 213, "domContentLoadedEnd": 355, "domComplete": 792, "httpsRequests": [ "https://www.reddit.com/", "https://www.redditstatic.com/reddit-init.en.qq9nT0inXvw.js", "https://www.redditstatic.com/reddit.en.xlHlxcJziiU.js", "https://www.redditstatic.com/reddit.ooBJpEoO9vY.css", "https://www.google-analytics.com/analytics.js" ] // … and more! } }

Page 66: Effectively Monitoring Client-Side Performance: NEPHP2016

Phantomas> phantomas http://reddit.com

{ "metrics": { "requests": 73, "bodySize": 580491, "contentLength": 629382, "timeToFirstByte": 94, "timeToLastByte": 105, "DOMqueries": 247, "firstPaint": 0, "domInteractive": 215, "domContentLoaded": 213, "domContentLoadedEnd": 355, "domComplete": 792, "httpsRequests": [ "https://www.reddit.com/", "https://www.redditstatic.com/reddit-init.en.qq9nT0inXvw.js", "https://www.redditstatic.com/reddit.en.xlHlxcJziiU.js", "https://www.redditstatic.com/reddit.ooBJpEoO9vY.css", "https://www.google-analytics.com/analytics.js" ] // … and more! } }

Page 67: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser-Perf

Page 68: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser-Perf> browser-perf http://reddit.com --selenium=selenium.example.com

Page 69: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser-Perf> browser-perf http://reddit.com --selenium=selenium.example.com

Page 70: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser-Perf> browser-perf http://reddit.com --selenium=selenium.example.com

Page 71: Effectively Monitoring Client-Side Performance: NEPHP2016

Browser-Perf> browser-perf http://reddit.com --selenium=selenium.example.com

Page 72: Effectively Monitoring Client-Side Performance: NEPHP2016

WebPagetesthttp://www.webpagetest.org/

Page 73: Effectively Monitoring Client-Side Performance: NEPHP2016

WebPagetesthttp://www.webpagetest.org/

Page 74: Effectively Monitoring Client-Side Performance: NEPHP2016

WebPagetest

Page 75: Effectively Monitoring Client-Side Performance: NEPHP2016

WPT: Speed IndexPaint Time of “Above the Fold” Content

( )

Source: WebPagetest

Page 76: Effectively Monitoring Client-Side Performance: NEPHP2016

Calculating Speed Index

1. Take the duration until the page is visually complete

2. Separate it into 100ms intervals 3. For each interval, assign it a “percent

visually complete” 4. Invert that percentage so it’s “percent

incomplete” or “percent remaining” 5. Multiply that by the interval length (100ms) 6. Sum all of the intervals. Speed Index!

Page 77: Effectively Monitoring Client-Side Performance: NEPHP2016

Lighthouse

Page 78: Effectively Monitoring Client-Side Performance: NEPHP2016
Page 79: Effectively Monitoring Client-Side Performance: NEPHP2016

Lighthouse

Page 80: Effectively Monitoring Client-Side Performance: NEPHP2016

Storage and Monitoring

Page 81: Effectively Monitoring Client-Side Performance: NEPHP2016

• Aggregation • Data storage + queries • Visualization • Alerts + Notification

Storing and Monitoring

Page 82: Effectively Monitoring Client-Side Performance: NEPHP2016

Aggregation via StatsD

Page 83: Effectively Monitoring Client-Side Performance: NEPHP2016

Aggregation via StatsD

Page 84: Effectively Monitoring Client-Side Performance: NEPHP2016

Storage + Queries with Graphite

mySite.homepage.phantomas.domComplete

Page 85: Effectively Monitoring Client-Side Performance: NEPHP2016

Visualization with Grafana

Page 86: Effectively Monitoring Client-Side Performance: NEPHP2016

Visualization with Grafana

Source: play.grafana.org/

Page 87: Effectively Monitoring Client-Side Performance: NEPHP2016

Alerts and Notifications

Page 88: Effectively Monitoring Client-Side Performance: NEPHP2016

1. Client-Side Performance 2. Collect + Monitor 3. Effectively

Page 89: Effectively Monitoring Client-Side Performance: NEPHP2016

Effective Monitoring

• Reduce noise • Beware skewed data • Make data actionable • Utilize data

Page 90: Effectively Monitoring Client-Side Performance: NEPHP2016

Reduce Noise

• Isolate third party scripts and external services

• Control conditional code paths (A/B tests, etc.)

Page 91: Effectively Monitoring Client-Side Performance: NEPHP2016

Beware Skewed Data

• Observer effect

• Noisy neighbors

Page 92: Effectively Monitoring Client-Side Performance: NEPHP2016

Make Data Actionable

Know what changes will affect each of your metrics

Page 93: Effectively Monitoring Client-Side Performance: NEPHP2016

How do you improve…

DOM Complete?

Page 94: Effectively Monitoring Client-Side Performance: NEPHP2016

How do you improve…

Frame rate during scroll?

Page 95: Effectively Monitoring Client-Side Performance: NEPHP2016

How do you improve…

Speed Index?

Page 96: Effectively Monitoring Client-Side Performance: NEPHP2016

Do something with this data!

Page 97: Effectively Monitoring Client-Side Performance: NEPHP2016

Utilize Data

• Agree on performance metrics • Agree on performance goals • Allocate time and resources

to achieving these goals

Page 98: Effectively Monitoring Client-Side Performance: NEPHP2016

Performance is a means to an end:

Remember

Page 99: Effectively Monitoring Client-Side Performance: NEPHP2016

Performance is a means to an end:

user experience

Remember

Page 100: Effectively Monitoring Client-Side Performance: NEPHP2016

Andrew Rota, .

@AndrewRota .

Thanks!Recommend Resources

• bit.ly/google_rails • bit.ly/webpagetest_docs • bit.ly/browser_perf • bit.ly/statsdcc • bit.ly/phantomas_js • graphite.readthedocs.io