Slide 1

Slide 1 text

The magic behind HTTP/2

Slide 2

Slide 2 text

@r31gN_ JS Instructor GDE

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

A brief history

Slide 5

Slide 5 text

HTTP/1.0 (year 1996) ● Made a new connection for every request ○ Overhead ○ 3 packets for setup ○ 4 packets for termination ○ https://tools.ietf.org/search/rfc1945

Slide 6

Slide 6 text

HTTP/1.1 (year 1997) ● Persistent connections ○ Reuse the connection for multiple requests ○ Still one request at a time ● Pipelined connections ○ Multiple requests at a time ○ Requests are served in FIFO order (slow requests are blocking) ○ Recommendation not to use it (Chromium project)

Slide 7

Slide 7 text

HTTP/1.0 HTTP/1.1 HTTP/1.1 Pipelining

Slide 8

Slide 8 text

Best practices ● Fewer files ○ JS/CSS concatenation ○ Image sprites ● Inline stuff ○ JS/CSS ○ Data URI for images ● Domain sharding ○ ~ 6 connections per domain ○ Share assets across multiple domains

Slide 9

Slide 9 text

Best practices DOWNSIDES ● Fewer files ○ Download and parse unnecessary content ● Inline stuff ○ Prevents caching ● Domain sharding ○ Each connection adds overhead ○ Race conditions

Slide 10

Slide 10 text

HTTP/2

Slide 11

Slide 11 text

HTTP/2 in one slide ● Binary framing layer ● Request/response multiplexing ● Other features ○ Prioritisation ○ Flow control ○ Server push ● Only one TCP connection ● Header compression (HPACK)

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Streams, messages, frames ● Stream: bidirectional flow of bytes which may carry one or more messages ● Message: a complete sequence of frames that map to a request/response ● Frame: smallest unit of communication in HTTP/2, containing a frame header, which at a minimum identifies the stream to which the frame belongs

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Stream prioritisation ● Each stream may be given an integer between 1 and 256 ● Each stream may depend on other streams ● The combination of dependencies and weights will result in a prioritisation tree ● This is used to prioritise CPU/memory allocation

Slide 17

Slide 17 text

R A B W - 12 W - 4

Slide 18

Slide 18 text

C A B W - 12 W - 4 R W - 1

Slide 19

Slide 19 text

Flow control ● Mechanism to prevent the sender from overwhelming the receiver ● ~ TCP Flow Control (but it was not granular enough) ● HTTP/2 does not implement an algorithm, but provides building blocks for this ○ Is directional ○ Is credit based ○ Cannot be disabled ○ It is hop-by-hop (an intermediary node can decide other algorithms)

Slide 20

Slide 20 text

Server push ● Serve more than one response per request (even if client did not request specifically) ● Server builds dependency graph based on referer header ● Server push streams are initiated by the PUSH_PROMISE frame (contain the HTTP headers of the promised resource) ● Client can opt to reject the stream (RST_STREAM frame) ● This is an optimisation over HTTP/1.1 inlining assets strategy (which was always forced)

Slide 21

Slide 21 text

HPACK compression format ● Headers are now compressed (including cookies!) ● Based on a shared compression context that both client and server understand (Huffman code) ● Has a static and a dynamic table ○ Static table is used for common HTTP header fields ○ Dynamic table is initially empty, but gets progressively built

Slide 22

Slide 22 text

Best practices ● No more concatenation ○ No more cache churn issues ○ Only download what is needed ● No more inlining ○ Better caching ● No more domain sharding ○ Better resource utilisation

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

Keep on smiling because you are the most beautiful people when you do.

Slide 26

Slide 26 text

Q&A

Slide 27

Slide 27 text

Thank you! @r31gN_