Top Banner
Make Browsers CRY How to make a web app painfully slow Speaker Name, Title @name name
67

Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Jan 17, 2017

Download

Data & Analytics

New Relic
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: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Make Browsers CRYHow to make a web app painfully slow

Speaker Name, Title@name name

Page 2: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

This document and the information herein (including any information that may be incorporated by reference) is provided for informational purposes only and should not be construed as an offer, commitment, promise or obligation on behalf of New Relic, Inc. (“New Relic”) to sell securities or deliver any product, material, code, functionality, or other feature. Any information provided hereby is proprietary to New Relic and may not be replicated or disclosed without New Relic’s express written permission.

Such information may contain forward-looking statements within the meaning of federal securities laws. Any statement that is not a historical fact or refers to expectations, projections, future plans, objectives, estimates, goals, or other characterizations of future events is a forward-looking statement. These forward-looking statements can often be identified as such because the context of the statement will include words such as “believes,” “anticipates,”, “expects” or words of similar import.

Actual results may differ materially from those expressed in these forward-looking statements, which speak only as of the date hereof, and are subject to change at any time without notice. Existing and prospective investors, customers and other third parties transacting business with New Relic are cautioned not to place undue reliance on this forward-looking information. The achievement or success of the matters covered by such forward-looking statements are based on New Relic’s current assumptions, expectations, and beliefs and are subject to substantial risks, uncertainties, assumptions, and changes in circumstances that may cause the actual results, performance, or achievements to differ materially from those expressed or implied in any forward-looking statement. Further information on factors that could affect such forward-looking statements is included in the filings New Relic makes with the SEC from time to time. Copies of these documents may be obtained by visiting New Relic’s Investor Relations website at ir.newrelic.com or the SEC’s website at www.sec.gov.

New Relic assumes no obligation and does not intend to update these forward-looking statements, except as required by law. New Relic makes no warranties, expressed or implied, in this document or otherwise, with respect to the information provided.

Page 3: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

About me…

Making slow pages

since the 1990s

Once designed

a page with >9 AJAX requests

that blocked rendering

Have incorrectly

implemented browser caching

Overused Webfonts

Used the blink tag

GOOD NEWSHave done none of these things at New Relic

Page 4: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

TL;DR THERE IS NO MAGIC WEB PERF SAUCE.

(but sometimes it's good to know what not to do)

Page 5: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

The CLIENT / SERVERmodel

HTTP(S)

Page 6: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

The CLIENT / SERVERmodel

HTTP(S)

CACHE

CDN

Page 7: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Pages make requests to an average of

DOMAINS20As of October 2016Source: httparchive.org/trends.php

Page 8: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

The average number of requests is now

PER PAGE107As of October 2016Source: httparchive.org/trends.php

Page 9: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Average total transfer size is INCREASING

Source: httparchive.org

1,904.58KB

2,218.65KB

2,540.33KB

Sept 2014

Sept 2015

Sept 2016

Page 10: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

requests312

secs render

and it takes

15.4

in the ALEXA TOP 10one site makes…

Page 11: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

A MODELFOR FRONTEND DEVS

Infrastructure

My precious code

backend system(s)

"the network"

Page 12: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

THE FOCUSFOR FRONTEND DEVS

My precious code

Infrastructure

"the network"

backend system(s)

Page 13: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

IGNORE THISAT YOUR OWN PERIL

My precious code

Infrastructure

"the network"

backend system(s)

Page 14: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

HOW CAN WE MAKE A PAGE AS SLOW AS POSSIBLE?

Page 15: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

1. __________

3. __________

4. __________

2. __________

BROWSER

APP

INFRASTRUCTURE

Page 16: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

BROWSER

APP

INFRASTRUCTURE

1. Confuse this

3. Don’t optimize

4. Make bad choices here

2. Ignore this

Page 17: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Introducing:The METER OF BROKEN CUSTOMER EXPERIENCE*

Bad C/X

Good C/X

Page 18: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

FROM SCIENCE!

https://www.nngroup.com/articles/powers-of-10-time-scales-in-ux/

I'm going for tacos.

That was fast!

Where should I eat lunch?

10000ms

100ms

1000ms

Page 19: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

What technical choices can we make to INCREASE BAD C/X?

Page 20: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Web Performance Lab

Page 21: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

What we're testing with.

▪Simple web page: some images, JS, HTML, and CSS

▪Running on AWS EC2 (us-west-2) m2-large instance

▪Powered (and monitored) using Go

1400 ms

Page 22: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

LET'S MAKE INFRADECISIONS

Page 23: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   23

Infrastructure: What's the cheapest?

▪ The cheapest EC2 instance money can buy

– t2.nano

– 512 mb memory

– 1 vCPU

t2.nano

INFRASTRUCTURE

Page 24: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   24

1445 ms

What a deal!

"The t2.nano offers the full performance of a high frequency Intel CPU core if your workload

utilizes less than 5% of the core on average over 24 hours."

Source: https://aws.amazon.com/blogs/aws/ec2-update-t2-nano-instances-now-available/

INFRASTRUCTURE

Page 25: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

I WENT TO LUNCH.

INFRASTRUCTURE

Page 26: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   26

But came back to this... INFRASTRUCTURE

Page 27: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   27

Page load time went way, way up INFRASTRUCTURE

Page 28: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   28

LESSON: T2 INSTANCE CPU PERFORMANCE IS VARIABLE.

INFRASTRUCTURE

Page 29: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

LET'S WRITE SOME SLOW GO CODE

Page 30: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   30

EACH PIXEL IS RANDOMLY GENERATEDimg := image.NewRGBA(image.Rect(0, 0, width, height))

for x := 0; x < width; x++ {for y := 0; y < height; y++ { c := color.RGBA{uint8(rand.Intn(255)), uint8(rand.Intn(255)), uint8(rand.Intn(255)), 255}

img.Set(x, y, c) }}

Page 31: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   31

Doing this is slow (understandably) APP

Page 32: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   32

But not slow enough... APP

Page 33: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Go sleep

if os.Getenv("SLOW_IMAGE") != "" {time.Sleep(1000 * time.Millisecond)

}

APP

Page 34: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

And Go runtime tweaking...

$ GOGC=10 <app>

APP

Page 35: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   35

5300ms

And then the browser tears up APP

Page 36: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

LET'S UNOPTIMIZE THE NETWORK

Page 37: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Some recent data regarding NETWORK LATENCY

https://aws.amazon.com/blogs/aws/now-open-aws-us-east-ohio-region/

us-west-1

us-west-2

us-east-2

68ms

52ms

Page 38: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

A very fast TCP primer

▪Opening a new TCP connection is slow, especially over long distances

▪ Different hosts: different connections

▪ Browsers are good at reusing existing connections

▪ SSL adds additional RTs

Server Browser

roundtrip1

2

3

SYN

SYN/ACK

ACK

Data

NETWORK

Page 39: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   39

Forcing as many open TCP connections

▪Connection: close HTTP header

▪ For every connection, force the browser to re-establish the connection

▪Host OS also needs to open a new socket. Expect slightly more packets

NETWORK

Page 40: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   40

Increase the bandwidth!

▪Disable all gzip compression

▪Don't minify

▪Set HTTP headers to prevent any caching at any intermediate CDNs, proxies, or the browser

HTTP(S)

CACHE

NETWORK

Page 41: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   41

TCP Connection Close: Infrastructure View

The number of received packets suddenly spikes...

NETWORK

Page 42: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   42

TCP Connection Close: App View

Not much to see here

NETWORK

Page 43: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   43

% of 0ms connection openings

Connection time measured in Insights from New Relic Synthetics

NETWORK

Page 44: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   44

Results: Opening all the connections

2040ms

NETWORK

Page 45: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Let's increase network latency the easy way

Make the distance between these really far.

NETWORK

Page 46: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Let's increase network latency the easy way

8,561 miles

San FranciscoAWS in Mumbai

NETWORK

Page 47: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Page load gets (slightly) faster in Japan

ap-south-1

NETWORK

Page 48: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

And in Singapore, too NETWORK

Page 49: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   49

Where the bits come from is really important

2460ms

NETWORK

Page 50: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

LET'S CONFUSE THE BROWSER

Page 51: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   51

Delay getting CSS to the client

▪CSS blocks rendering, delay it for more pain.

▪Put it in the <body>

▪Add @imports for good measure.

▪Make CSS extra-complex, uncachable, and far away from the user.

BROWSER

Page 52: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   52

Block with JavaScript as much as possible

▪Put a lot of libraries in the <head> tag

▪Make that JavaScript do a lot of unnecessary work

▪Avoid the async script attribute

BROWSER

Page 53: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

5DIFFERENT FONTS... FROM CHINA

LETS USE

Why not? BROWSER

Page 54: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Why not?

ALLTHE JAVASCRIPT FRAMEWORKS!

LETS USE

BROWSER

Page 55: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   55

BROWSER

Page 56: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

BROWSER

Page 57: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

+3400 ms

+500 ms

+19000 ms

+1000 ms

BROWSER

APP

INFRASTRUCTURE

Page 58: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

All these decisions can happen in real life for

good reasons.

Page 59: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Confidential ©2008-16 New Relic, Inc. All rights reserved.   59

∞ ms 800 ms

AggressivelyUnoptimized

AggressivelyOptimized

Page 60: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Fixing it: solutions

Use a Content Delivery Network

Multiple availability

zones, DNS-based routing

Caching correctly

implemented

JS, HTML, and CSS

optimized for not-blocking

Page 61: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Creating a fast app is more than using ______________.

BROWSER

APP

INFRASTRUCTURE

Page 62: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Creating a fast app is more than using ______________.

BROWSER

APP

INFRASTRUCTURE

fast ec2 hosts

Page 63: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Creating a fast app is more than using ______________.

BROWSER

APP

INFRASTRUCTURE

Go

Page 64: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Creating a fast app is more than using ______________.

BROWSER

APP

INFRASTRUCTURE

HTTP/2

Page 65: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Creating a fast app is more than using ______________.

BROWSER

APP

INFRASTRUCTURE

React

Page 66: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

BROWSER

NETWORK

APP

INFRASTRUCTURE

Page 67: Make Browsers Cry: How to Make a Modern Web App Painfully Slow [FutureStack16]

Clay SmithDeveloper Advocate

Thank you.