site speed fundamentals

107
Site Speed Fundamentals

Upload: martin-breest

Post on 12-Apr-2017

117 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Site Speed Fundamentals

Site Speed Fundamentals

Page 2: Site Speed Fundamentals

What is Site Speed?

Page 3: Site Speed Fundamentals

Site Speed -> Page Speed

Page 4: Site Speed Fundamentals
Page 5: Site Speed Fundamentals
Page 6: Site Speed Fundamentals

Time until page gets fully loaded.

Page 7: Site Speed Fundamentals

Time until user can start interacting with page.

Page 8: Site Speed Fundamentals

Why is Site Speed important?

Page 9: Site Speed Fundamentals

Need for speed is proven

Page 10: Site Speed Fundamentals

http://www.nngroup.com/articles/response-times-3-important-limits/Jakob Nielsen on response time limits

0.1 seconds make user feel that the system is reacting instantaneously

Page 11: Site Speed Fundamentals

http://www.nngroup.com/articles/response-times-3-important-limits/Jakob Nielsen on response time limits

0.1 seconds make user feel that the system is reacting instantaneously

1 second is the limit for the user's flow of thought to stay uninterrupted

Page 12: Site Speed Fundamentals

http://www.nngroup.com/articles/response-times-3-important-limits/Jakob Nielsen on response time limits

0.1 seconds make user feel that the system is reacting instantaneously

1 second is the limit for the user's flow of thought to stay uninterrupted

10 seconds is the limit for keeping the user's attention focused on the dialogue

Page 13: Site Speed Fundamentals

Site speed has an impact on conversion rates ...

Page 15: Site Speed Fundamentals

… and other business metrics

● bounce rate

● cart size

● revenue

● time on site

● page views

http://www.soasta.com/whitepapers/time-is-money-the-business-value-of-web-performance/Time is Money, The Business Value of Web Performance, Tammy Everts

● user satisfaction

● user retention

● organic search traffic

● brand perception

● productivity

Page 16: Site Speed Fundamentals

However sites are getting bigger

Page 18: Site Speed Fundamentals

But next billion users will access Web ...

Page 19: Site Speed Fundamentals

… through feature phones, like a Nokia X2-01, ...

https://brucelawson.github.io/talks/2015/velocity/velocity-AMS.pdf Top Handsets: India

Page 21: Site Speed Fundamentals

What does Site Speed depend on?

Page 22: Site Speed Fundamentals

Latency and bandwidth mostly

Page 23: Site Speed Fundamentals

LatencyTime from source sending a packet to destination receiving it

Page 24: Site Speed Fundamentals

LatencyTime from source sending a packet to destination receiving it

BandwidthMaximum throughput of a logical or physical communication path

Page 26: Site Speed Fundamentals

Submarine fibre links 70 Tbit/s

http://submarinecablemap.com

Page 27: Site Speed Fundamentals

http://www.speedtest.net

Last mile Leipzig cable 5 Mbit/s

Page 28: Site Speed Fundamentals

Last mile Bangladesh 2G EDGE network 500 Kbit/s

Page 29: Site Speed Fundamentals

Site speed depends most on network latency

and round trip times (RTT) ...

Page 30: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Page 31: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Distance 2235 km

Page 32: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Distance 2235 kmRTT 42.45 ms

Page 33: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Distance 2235 kmRTT 42.45 ms

Speed of light in vacuum = ~300 km/msSpeed of light in optical fiber = ~200 km/msRTT = 2236 km * 1 ms / 200 km * 2 = 22.36 msDeviation = 22.36 ms / 42.45 ms - 100 = 47,32%

Page 34: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Page 35: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Distance 13822 km

Page 36: Site Speed Fundamentals

Dallas

New York

Sydney

https://wondernetwork.com/pings/Dallas

Distance 13822 kmRTT 194.23 ms

Page 37: Site Speed Fundamentals

Site speed depends on DNS lookup, TCP handshake

and TCP slow-start

Page 38: Site Speed Fundamentals

Application Layer

Transport Layer

Network Layer

Network Interface Layer

Short reminder - TCP/IP Network Model

TCP/IP Layers

HTTP

TCP/IP Protocols

FTP Telnet SMTP DNS

TCP UDP

IP ARP ICMP IGMP

Ethernet Token RingOther Link-Layer

Protocols

https://en.wikipedia.org/wiki/Internet_protocol_suite

Page 39: Site Speed Fundamentals

Loading a basic Web site ...

we need DNS

● to resolve domain name, i.e. www.spreadshirt.com, to IP address

we need HTTP

● to load HTML and depending resources like CSS, Javascript and Images

Page 40: Site Speed Fundamentals

Application Layer

Transport Layer

Network Layer

Network Interface Layer

DNS Protocol Stack

TCP/IP Layers

HTTP

TCP/IP Protocols

FTP Telnet SMTP DNS

TCP UDP

IP ARP ICMP IGMP

Ethernet Token RingOther Link-Layer

Protocols

https://en.wikipedia.org/wiki/Internet_protocol_suite

Page 41: Site Speed Fundamentals

Application Layer

Transport Layer

Network Layer

Network Interface Layer

HTTP Protocol Stack

TCP/IP Layers

HTTP

TCP/IP Protocols

FTP Telnet SMTP DNS

TCP UDP

IP ARP ICMP IGMP

Ethernet Token RingOther Link-Layer

Protocols

https://en.wikipedia.org/wiki/Internet_protocol_suite

Page 42: Site Speed Fundamentals

Ethernet

IP

TCP

Protocols are wrapped in each other

HTTP

Page 43: Site Speed Fundamentals

Ethernet

IP

TCP

Each protocol adds additional overhead

HTTP

Ethernet header … (uncompressed)

IP header … (uncompressed)

TCP header … (uncompressed)

HTTP Header … (uncompressed)

HTTP Payload … (compressed or uncompressed)like HTML, Javascript, CSS, Images

1460 byte payload1480 byte payload

1500 byte payload

Page 44: Site Speed Fundamentals

Three-way handshake startsTCP connection

Page 46: Site Speed Fundamentals

Data exchange starts via TCP slow-start

Page 47: Site Speed Fundamentals
Page 48: Site Speed Fundamentals
Page 49: Site Speed Fundamentals
Page 50: Site Speed Fundamentals

How many round trips do we need for loading a Web page?

Page 51: Site Speed Fundamentals

Round trips required

DNS lookup1 RTT

TCP handshake

1 RTT

HTTP Request1-n RTTs

Page 52: Site Speed Fundamentals

How many round trips are required for loading www.speadshirt.com from different locations?

DNS TCP handshake HTTP request Sum

Dallas - New York 42.45 ms 42.45 ms 2 x 42.45 ms 169.80 ms (4)

Dallas - Sydney 194.23 ms 194.23 ms 2 x 194.23 ms 776.92 ms (4)

spreadshirt.com = 500 byte (header) + 24 kb (compressed payload) = 25 576 byte segments = 25 576 byte / 1460 byte = 17,5 = ~18initial congestion window (segments) = 10 (instead of 4 see link) -> 14 600 byte

https://tools.ietf.org/html/rfc6928Increase of initial congestion window from 4 to 10

Page 53: Site Speed Fundamentals

Why don’t we use multiple TCP connections to parallelize things?

Page 54: Site Speed Fundamentals

Number of TCP connections per domain is limited

http://www.browserscope.org/?category=network&v=top

Browser Connections per Domain Max Connections

Chrome 46.0.2490 6 10

Safari 9.0.1 6 16

Firefox 42.0.1 6 17

Internet Explorer 11 13 17

Page 55: Site Speed Fundamentals

Each additional TCP connection comes at a cost!

Page 56: Site Speed Fundamentals

Site Speed depends on processing time

Page 57: Site Speed Fundamentals

DNS lookupInitial connection(TCP handshake +

Client send)

Time to first byte(Server processing)

Content download(Client receive)

Page 58: Site Speed Fundamentals

Site Speed also depends on critical rendering path (CRP)

and page load times

Page 59: Site Speed Fundamentals

Render tree construction works as follows

Page 61: Site Speed Fundamentals

Problem is that CSS is render blocking

Page 62: Site Speed Fundamentals

2 critical resources

2 or more round trips for the minimum critical path length

9 KB of critical bytes

https://developers.google.com/web/fundamentals/performance/critical-rendering-path/

Page 63: Site Speed Fundamentals

Next problem is that WebFonts block text painting

Page 65: Site Speed Fundamentals

And Javascript is parser blocking

Page 66: Site Speed Fundamentals

https://developers.google.com/web/fundamentals/performance/critical-rendering-path/

3 critical resources

2 or more round trips for the minimum critical path length

11 KB of critical bytes

Page 67: Site Speed Fundamentals

The difference is ...

Page 68: Site Speed Fundamentals
Page 69: Site Speed Fundamentals

But wait. Does the whole page need to be rendered?

Page 70: Site Speed Fundamentals
Page 71: Site Speed Fundamentals

Viewport

Page 72: Site Speed Fundamentals

Viewport Above the fold

Below the fold

Page 73: Site Speed Fundamentals

ViewportMac

ViewportIPad

Page 74: Site Speed Fundamentals

User can start interacting with page

Page is fully loaded

Page starts loading

Page 75: Site Speed Fundamentals

How can we measure Site Speed and its business impact?

Page 76: Site Speed Fundamentals

Which metrics are available?

Page 77: Site Speed Fundamentals

Core metrics overview

time to first byte

Page 78: Site Speed Fundamentals

Core metrics overview

time to first byte start render time

Page 79: Site Speed Fundamentals

Core metrics overview

time to first byte start render time

above the fold time

Page 80: Site Speed Fundamentals

Core metrics overview

time to first byte start render time

above the fold time page load time

Page 81: Site Speed Fundamentals

Metric detailstime to first byte start render time page load time fully loaded

above the fold time

Page 82: Site Speed Fundamentals

Metric detailsbackend frontend

Page 83: Site Speed Fundamentals

Metric detailsDNS lookup

Init TCP connectionServer processing

Content download

Page 84: Site Speed Fundamentals

Metric detailsNumber of resources and transfered bytes +

order of resources

Page 85: Site Speed Fundamentals

How can we continuously measure Site Speed?

Page 86: Site Speed Fundamentals

Generic testing with WebPagetest

Page 87: Site Speed Fundamentals
Page 88: Site Speed Fundamentals

Synthetic monitoringwith Rigor

Page 89: Site Speed Fundamentals
Page 90: Site Speed Fundamentals

Real user monitoringwith SOASTA

Page 91: Site Speed Fundamentals
Page 92: Site Speed Fundamentals
Page 93: Site Speed Fundamentals

How can we optimize Site Speed?

Page 94: Site Speed Fundamentals

How do we find out what needs to be optimized?

Page 95: Site Speed Fundamentals

Focus on important pages

● pages that drive in traffic

● pages where people browse and search

● pages that have impact on business metrics

Page 96: Site Speed Fundamentals

Compare to competition

Page 97: Site Speed Fundamentals

Focus on frontend rather than backend

backend frontend

Page 98: Site Speed Fundamentals

Focus on important resources

Page 99: Site Speed Fundamentals

Have a look at third party content

Page 100: Site Speed Fundamentals

Have baseline measurements in connection to business metrics in place

Page 101: Site Speed Fundamentals

Find out what to optimize

Start with free tools like

● WebPagetest

http://www.webpagetest.org

● PageSpeed Insights

https://developers.google.com/speed/pagespeed/insights/

● Chrome Developer Tools

https://developer.chrome.com/devtools#audits

Consider to buy tools like

● Zoompf

https://zoompf.com

Page 102: Site Speed Fundamentals

Which optimization rules exist?

Page 103: Site Speed Fundamentals

Basic Optimizations

● Avoid landing page redirects

● Reuse connections

● Reduce HTTP requests

● Reduce DNS lookups

● Improve server response times

● Leverage caching

● Enable compression

● Minify resources

● Optimize images

● Shard dominant domains

● Serve static content from cookieless domain

● Make Javascript and CSS external

● Optimize CSS delivery

● Prioritize visible content

● Flush document early

● Remove render-blocking Javascript

● Use asynchronous scripts

● Reduce DOM complexity

● Optimize CSS

● Optimize Javascript

● ...

https://developers.google.com/speed/docs/insights/ruleshttp://stevesouders.com/efws/blogposts.php

Page 104: Site Speed Fundamentals

Live Demo

Page 105: Site Speed Fundamentals

HTTP/2 is on its way and will make some optimizations obsolete

Page 106: Site Speed Fundamentals

Key take aways

Page 107: Site Speed Fundamentals

Key take aways

● Latency, bandwidth and TCP/IP network model are limiting factors

● Look at frontend times if you want to improve user experience

● Understand critical rendering path and page load times

● Setup baseline measurements in connection to business metrics

● Optimize in iterations and compare results (or better run A/B tests)