Http2 is here! And why the web needs it

77
HTTP/2 is here! And why the web needs it Nilesh Naik Tata Consultancy Services

Transcript of Http2 is here! And why the web needs it

Page 1: Http2 is here! And why the web needs it

HTTP/2 is here!And why the web needs it

Nilesh NaikTata Consultancy Services

Page 2: Http2 is here! And why the web needs it

• How we got there• Limitations of HTTP/1.1• What’s new in HTTP/2• Best practices of today are anti-patterns in

HTTP/2• Impact on developer community• Current implementations• What’s next

What’s in here -

Page 3: Http2 is here! And why the web needs it

The web has changed significantly since then

1991HTTP/0.9

1996HTTP/1.0

1999HTTP/1.1

2015HTTP/2

HTTP Timeline

2009SPDY

Page 4: Http2 is here! And why the web needs it

HTTP 0.9 (1991)

GET /index.htm

<html><head> ….

</head><body>

…</body>

</html>

Page 5: Http2 is here! And why the web needs it

HTTP 1.0 (1996)

GET /index.htm HTTP/1.0User-Agent: mozillaAccept: text/html

HTTP/1.0 200 OK<html>

<head> ….

</head><body>

…</body>

</html>

Page 6: Http2 is here! And why the web needs it

HTTP 1.1 (1999)

GET /index.htm HTTP/1.0User-Agent: mozillaAccept: text/htmlConnection: keep-alive

HTTP/1.0 200 OK<html>

<head> ….

</head><body>

…</body>

</html>

Page 7: Http2 is here! And why the web needs it

First Web Page

Page 8: Http2 is here! And why the web needs it

Early 90’s – McDonald’s

Single Request – Response modelNot much interaction

Page 9: Http2 is here! And why the web needs it

MSN

Page 10: Http2 is here! And why the web needs it

Early 90’s

Most of the content was sent in response to single request

Minimal or no JS

Page 11: Http2 is here! And why the web needs it

Modern Web page - Amazon

- 308 requests, 8.1 MB data

Page 12: Http2 is here! And why the web needs it

Modern Web page

External resources requested Multiple requests, Multiple response

Page 13: Http2 is here! And why the web needs it

Modern Web page - Ads

Much of the site isnt about content, its about Ads.

Page 14: Http2 is here! And why the web needs it

HTTP abused!

Page 15: Http2 is here! And why the web needs it

And yes, every TCP connection is closed with a 3-way connection too!

Open connection: 3-way handshake

SYNx= rand()

SYN ACKX+1 y= rand()

ACKx+1 y+1

Application Data

0 ms

28 ms

56 ms

84 ms

Page 16: Http2 is here! And why the web needs it

More resource intensive than ever before HTTP 1.1 was not built to handle that kind of load HTTP 1.1 does not use TCP optimally

800K Transfer size

2300K Transfer size

80 Objects

100 Objects

In the last 4 years..

Page 17: Http2 is here! And why the web needs it

HTTP requests are expensive!

Workarounds

Page 18: Http2 is here! And why the web needs it

SpritingSpriting

Page 19: Http2 is here! And why the web needs it

Spriting

Text

To get just one flag…

Browser must downloadand encode the whole image

Spriting

Page 20: Http2 is here! And why the web needs it

Spriting - Contd.

Makes development harder Impacts caching Every change would require a fresh download Larger files takes longer to download and display on browser

Page 21: Http2 is here! And why the web needs it

Inlining Resources

Page 22: Http2 is here! And why the web needs it

Inlining – Contd. data: urls instead of sprites

Resources can’t be cached independently Development isn't easy

Page 23: Http2 is here! And why the web needs it

Concatenation

Merge multiple JavaScript/CSS files into one BIG file

Larger files to downloadand parse

Page 24: Http2 is here! And why the web needs it

Larger files to downloadand parse

Whole bundle is invalidated if a single file changes

Concatenation – contd.

Too much data when only a little is needed Too much to reload when a change is needed Annoyance for developers Impacts caching

Page 25: Http2 is here! And why the web needs it

Domain shardingBrowsers use 6-8 connections per host

Page 26: Http2 is here! And why the web needs it

Domain sharding – contd.Sites use many host names to allow more connection

index.html

style.css

image.png

Page 27: Http2 is here! And why the web needs it

Domain sharding on Single Server

domain.com/index.html

images.domain.com/image.png

styles.domain.com/styles.css

Page 28: Http2 is here! And why the web needs it

Domain sharding – bbc.co.uk

www.bbc.co.ukstatic.bbc.co.uknav.files.bbci.co.ukhomepage.files.bbci.co.uk

Still suffers from head of blocking Every new connection takes up resources Every new host needs a name lookup*http://yslow.org/

Page 29: Http2 is here! And why the web needs it

Useful, but are really just Band-aids Annoying for the developers Adds a layer of tools Hampers caching Downloads too much

Hacks

Page 30: Http2 is here! And why the web needs it

Ideal Protocol Interaction

Send minimal data to the server

Download minimal data needed

Extra data -> more time to transfer, adds latency (especially on mobile networks)

Page 31: Http2 is here! And why the web needs it

HTTP/1.1

HTTP/1.x is “chatty”

Several round-trips, adds latency

Page 32: Http2 is here! And why the web needs it
Page 33: Http2 is here! And why the web needs it

Latency vs Bandwidth

Page 34: Http2 is here! And why the web needs it

Announced in 2009

Target 50% reduction in PLT

Initial tests - 55% faster

On track to de facto standard

Page 35: Http2 is here! And why the web needs it

Enter HTTP/2 - RFC 7540

Built on top of SPDY

One TCP Connection

Improved end-user perceived latency

Binary framing layer

Page 36: Http2 is here! And why the web needs it

Enter HTTP/2

Page 37: Http2 is here! And why the web needs it

Connection

Stream

DATA HEADERRequest message

Response messageHEADER HEADERDATA

Stream

PRIORITY HEADERRequest message

Response messageHEADER DATA

Page 38: Http2 is here! And why the web needs it

An HTTP 1.x connection

Response<HTML> <HEAD> -- </HEAD> <BODY> -- </BODY></HEAD>

RequestGET /index.html HTTP 1.1User-Agent: mozillaAccept: text/html

TCP Connection

Page 39: Http2 is here! And why the web needs it

An HTTP/2 connection

Response000010001101100001000000100101

Request000100010100100100001001000

TCP Connection

Page 40: Http2 is here! And why the web needs it

Demo

• https://http2.akamai.com/demo

Page 41: Http2 is here! And why the web needs it

Multiplexing

GET /foo

200 OK

GET /bar

200 OK 200 OK

200 OK

200 OK

200 OK

GET /fooGET /bar

GET /baz

GET /saz

GET /taz

GET /taz

Head of Line Blocking

No QueuingOne connectionMany requestsOut of orderinterleaved

HTTP/1.1 HTTP/2

Still serializedLong download/long think time can block other requests

Page 42: Http2 is here! And why the web needs it

Multiplexing – contd.

Page 43: Http2 is here! And why the web needs it

Multiplexing – network graph

Page 44: Http2 is here! And why the web needs it

Header Compression

Unnecessary metadata (headers) add up quickly

100+ requests, with few KB of headers -> hundreds of KB’s!

Bytes are slow and expensive to transfer

Page 45: Http2 is here! And why the web needs it

Header Duplication

Page 46: Http2 is here! And why the web needs it

Header Duplication – contd.

Page 47: Http2 is here! And why the web needs it

Header Duplication – contd.

Page 48: Http2 is here! And why the web needs it

Header Duplication – contd.

Page 49: Http2 is here! And why the web needs it

Header Duplication – contd.

Four requests 2,596 bytes total 1,797 redundant bytes

Page 50: Http2 is here! And why the web needs it

HPACK – Header Compression - RFC 7541

Compresses HeadersAvoids sending duplicated/repeated headers

Page 51: Http2 is here! And why the web needs it

Server push

Similar to Inlining Resources pushed directly to client’s cache Opportunity for servers to become smarter

– Don’t push on every request– Push based upon observed traffic pattern

GET / index.html

200 OK

GET /style.css

200 OK

GET / index.html

200 OK

200 OK

Browser can reject push

Page 52: Http2 is here! And why the web needs it

Implementations

H2O

mod_h2 (Apache)

Server push – Cache DigestGET / foo

Push /foo.css

200 OK

CACHE_DIGEST

Process requestDigest of /main.js & /main.css

<html><script src="/main.js"><link rel="stylesheet" href="/main.css"><link rel=STYLESHEET href="/foo.css"><body>… generated response …

Page 53: Http2 is here! And why the web needs it

Priortization – HTTP/1.x

Page 54: Http2 is here! And why the web needs it

Priortization – HTTP/1.x

In HTTP/1, Prioritization is a browser heuristic • CSS and images first, followed by images

Page 55: Http2 is here! And why the web needs it

Priortization – HTTP/2

Page 56: Http2 is here! And why the web needs it

Priortization – HTTP/2

In HTTP/2, it’s hinted by the client, determined by the server

Page 57: Http2 is here! And why the web needs it

Stream Priority

Stream Weight: <int> 1..256

• Lower the number, higher the priority

Page 58: Http2 is here! And why the web needs it

Stream Dependency

Stream

Root

Weight: 15

Dependency: {Stream id}

• Streams aren't isolated, they can be dependent on others

• If no dependency then id set to zero.

Page 59: Http2 is here! And why the web needs it

Dependency Tree

5

5

7

4

Page 60: Http2 is here! And why the web needs it

HTTP/2 User ImpactFaster page loads

More response loading

More HTTPS

Page 61: Http2 is here! And why the web needs it

Impact on developers

Page 62: Http2 is here! And why the web needs it

Does not modify the semantics

Page 63: Http2 is here! And why the web needs it

Uses binary format instead of text

Debugging can be a problemNo more telnetWhy?

Page 64: Http2 is here! And why the web needs it

TLS Overhead

• World is moving towards https already

• ALPN makes impact minimal• Cost of certificates and

administrative overhead

Page 65: Http2 is here! And why the web needs it
Page 66: Http2 is here! And why the web needs it

Browser support

Page 67: Http2 is here! And why the web needs it
Page 68: Http2 is here! And why the web needs it

Hosting .NET Apps

IIS 10 on Windows 10Windows Server 2016Nginx

Page 69: Http2 is here! And why the web needs it

Hosting Java Apps

Apache HTTP 2.4.17+Jetty 9.3+Tomcat 8.5

Page 70: Http2 is here! And why the web needs it

Hosting Node Apps

node-http2node-spdyExpressJS 5.0

Page 71: Http2 is here! And why the web needs it

HTTP/2 on JVMJDK 8 and upwards required

Include ALPN extensions in class path

Included in JDK 9

Page 72: Http2 is here! And why the web needs it

Implementations

https://github.com/http2/http2-spec/wiki/Implementations

Page 73: Http2 is here! And why the web needs it

HTTP/1.x workaround will hurt HTTP/2 perf

InliningSpriting

ConcatenatingSharding

Page 74: Http2 is here! And why the web needs it

Case study

Page 75: Http2 is here! And why the web needs it

What's next?

Page 76: Http2 is here! And why the web needs it

QUICRuns on top of UDP

Goodness of SPDY and HTTP/2

No head of line blocking in QUIC!

QUIC TCP + TLS

New connection 100 ms

Repeat connnection 0 ms RTT

New connection 300 ms

Repeat connection 200 ms RTT

Page 77: Http2 is here! And why the web needs it

Thank you!

@NileshRaviNaik