YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Benjamin Wollmer -
Page 2: Benjamin Wollmer -
Page 3: Benjamin Wollmer -

Benjamin Wollmer

Going for Speed: Network

19.04.2021

Page 4: Benjamin Wollmer -

Invoking a Request Is Easy….

fetch('https://example.com/profil').then(response => response.json()).catch((error) => {console.error('Error:', error);

});

<link rel="stylesheet" href="styles.css">

19.04.2021 4

Page 5: Benjamin Wollmer -

19.04.2021 5

Stephen Ludin, Javier GarzaLearning HTTP/2 – A practical guide for beginners. 2017

Get RequestDNS inCache?

Is HTTPS?

Connectionopen?

Y

Resolve DNS

N

Send RequestY

Perform TLS Handshake

YOpen TCP Connection

N

… But Handling It?

N

Page 6: Benjamin Wollmer -

Request Waterfall

19.04.2021 Thema, Name des Referenten/der Referentin 6

Page 7: Benjamin Wollmer -

19.04.2021 7

DNS Lookup Initial Connection

TLS Handshake

Time to First Byte Content Downloadhttps://example.com/

20 ms0 60 ms 80 ms 100 ms40 ms

TCP Handshake

Optimization Knobs▪ DNS Performance▪ TCP Connection Handling

▪ TLS Handshakes▪ HTTP/2 Usage

Request Breakdown

Page 8: Benjamin Wollmer -

Hypertext Transfer Protocol

Page 9: Benjamin Wollmer -

HTTP

19.04.2021 9

TLS

HTTP/0.9

REST

HTTP/1.0 HTTP/1.1 HTTP/2 HTTP/3

Just GET it

Get different files

Do itdynmically

Do it secure

Do it fast

State Transfer

1991 Now

Do it faster

Page 10: Benjamin Wollmer -

HTTP Requests and Responses

19.04.2021 10

Page 11: Benjamin Wollmer -

HTTP Requests and Responses

▪ Standarized HTTP requestheaders:

▪ authority

▪ path

▪ cookies

▪ user-agent

19.04.2021 11

Page 12: Benjamin Wollmer -

HTTP Requests and Responses

▪ Negotiation

▪ Preferred Encodings/ Compression algorithms

▪ User’s languages

19.04.2021 12

Page 13: Benjamin Wollmer -

HTTP Requests and Responses

▪ Indicates the type of operation:

▪ GET/HEAD: read

▪ PUT: (over-)write

▪ POST: update

▪ DELETE: delete

▪ Others: PATCH, OPTIONS

▪ Different semantics:

▪ Safe, Idempotent, Cacheable

19.04.2021 13

Page 14: Benjamin Wollmer -

HTTP Requests and Responses

19.04.2021 14

HTTP Method

Request HasBody

Response Has Body

Safe Idempotent Cacheable

GET Optional Yes Yes Yes Yes

HEAD No No Yes Yes Yes

POST Yes Yes No No Yes

PUT Yes Yes No Yes No

DELETE No Yes No Yes No

CONNECT Yes Yes No No No

OPTIONS Optional Yes Yes Yes No

PATCH Yes Yes No No No

Page 15: Benjamin Wollmer -

HTTP Requests and Responses

▪ Bypass any web caches

▪ Other options, for Cache-Control e.g.:

▪ max-age

▪ max-stale

▪ only-if-cached

19.04.2021 15

Page 16: Benjamin Wollmer -

Domain Name System

16

DNS Lookup Initial Connection

TLS Handshake

Time to First Byte Content Download

20 ms0 60 ms 80 ms 100 ms40 ms

TCP Handshake

Page 17: Benjamin Wollmer -

Domain Name System

▪ Translates Domain Names to IP AddressesBased on (unreliable but fast) UDP

▪ Database: <Name, Value, Type, Class, TTL>TTL-based caching ensures performance

▪ Highly Performance-RelevantDNS lookup in the critical request path

19.04.2021 17

Page 18: Benjamin Wollmer -

19.04.2021 18

ClientLocal DNS Server

baqend.com

Root DNS Server

TLD DNS Server for .com

Authoritative NameServer for baqendPotentially 3-5 RTTs per Domain!

DNS: How it works

Page 19: Benjamin Wollmer -

DNS: Performance Measures

▪ DNS Replicas + IP Anycasting

▪ Setting TTLs for Caching (e.g., 1 hour)Problem: Can lead to unavailability

▪ Combine multiple DNS providers

▪ ISP favors the fastest server per region

▪ Availability increased (cf. Dyn attack)

19.04.2021 19Stackoverflow Blog: https://blog.serverfault.com/2017/01/09/surviving-the-next-dns-attack/

Page 20: Benjamin Wollmer -

Transmission Control Protocol

20

DNS Lookup Initial Connection

TLS Handshake

Time to First Byte Content Download

20 ms0 60 ms 80 ms 100 ms40 ms

TCP Handshake

Page 21: Benjamin Wollmer -

Transmission Control Protocol

19.04.2021 21I. Grigorik, High performance browser networking. O’Reilly Media, 2013.

Fall, Kevin R., and W. Richard Stevens. TCP/IP illustrated, volume 1: The protocols. addison-Wesley, 2011.

Tolerance againstpacket loss and

network congestion

Ensure that sent dataarrives in order

Provide dataintegrity

Page 22: Benjamin Wollmer -

Three-Way Handshake

19.04.2021 22I. Grigorik, High performance browser networking. O’Reilly Media, 2013.

Receiver Window: amount of datathe client is willing to receive at once

Sequence Number: order of data

Each side has itsown seq. numbers

Page 23: Benjamin Wollmer -

Congestion Avoidance

19.04.2021 23https://commons.wikimedia.org/wiki/File:TCP_Slow-Start_and_Congestion_Avoidance.svg

Variables & Constantscwnd – Congestion Window Sizessthresh – Slow Start ThresholdMSS – Maximum Segment Size

Page 24: Benjamin Wollmer -

Basics: Transmission Control Protocol

Core Question:How to balance between aggressive bandwidth use and packet loss?

Many Implementations:

▪ Original: TCP Tahoe and Reno (original implementations)

▪ Newer ones: TCP Vegas, TCP New Reno, TCP BIC, TCP CUBIC (Linux), or Compound TCP (Windows)

19.04.2021 24

Page 25: Benjamin Wollmer -

Transport Layer Security

DNS Lookup Initial Connection

TLS Handshake

Time to First Byte Content Download

20 ms0 60 ms 80 ms 100 ms40 ms

TCP Handshake

Page 26: Benjamin Wollmer -

TLS: Cryptographically Secure Channels Over TCP

19.04.2021 26

Encryptionto protect against

eavesdropping

Integrityto protect

againstmodifications

AuthenticationTo verify the

counterpart‘sidentity

Page 27: Benjamin Wollmer -

TLS Handshake

19.04.2021 27I. Grigorik, High performance browser networking. O’Reilly Media, 2013.

Initiate key exchangefor symmetric crypto

TLS Options and supported Ciphersuites

Pick TLS version & cipher, send certificate

Client Server

Acks sessionkey

Page 28: Benjamin Wollmer -

TLS False Start: Sending data in the 2nd handshake step

19.04.2021 28

Idea: session key known after 1st handshake▪ Client already sends application data in 2nd round▪ Does not change TLS protocol, only timing

Requirements for deplyoment:▪ Ciphersuite with Forward Secrecy

(Diffie-Hellmann) required by browsers▪ Server must support ALPN

Page 29: Benjamin Wollmer -

Application Layer Protocol Negotiation: Upgrading Protocols

19.04.2021 29

Problem: which protocol will be used over TLS?

Client attaches supported protocols to ClientHello message

Server selects a protocol and sends it back in ServerHello

message

Page 30: Benjamin Wollmer -

Session Resumption: Skipping key negotiation the 2nd time

19.04.2021 30

32-Byte Session ID identifies parameters1. Client sends session ID to server2. Server looks up ID and reuses ciphersuite and session

key

Problem: shared state across servers

→ Encrypt stateless Session Ticket (RFC 5077)based on a secret server key

Page 31: Benjamin Wollmer -

Optimizing TLS Certificates: Performance Best Practices

Minimize length of the trust chain

▪ Missing certs will be fetched → DNS, TCP, HTTP overhead

▪ Include intermediate certs

▪ But not CA cert

19.04.2021 31I. Grigorik, High performance browser networking. O’Reilly Media, 2013.

Page 32: Benjamin Wollmer -

Optimizing Certificate Revocation

Problem:▪ Clients have to check if certificates were

revoked

▪ Certificate Revocation Lists (CRLs): CA maintains list of revoked serial numbers → large & slow

▪ Online Certificate Status Protocol (OCSP): client requests CA database for each serial number → additional RTT

Improvement: ▪ OCSP Stapling

▪ Server staples pre-fetched, timestamped OCSP responses to certificate reply

19.04.2021 32

Page 33: Benjamin Wollmer -

Content Delivery Network

DNS Lookup Initial Connection

TLS Handshake

Time to First Byte Content Download

20 ms0 60 ms 80 ms 100 ms40 ms

TCP Handshake

Page 34: Benjamin Wollmer -

Latency vs Bandwidth

19.04.2021 34I. Grigorik, High performance browser networking. O’Reilly Media, 2013.

?

?

Page 35: Benjamin Wollmer -

Latency vs Bandwidth

19.04.2021 35I. Grigorik, High performance browser networking. O’Reilly Media, 2013.

Page 36: Benjamin Wollmer -

Adding a Content Delivery Network (CDN)

19.04.2021 36

Page 37: Benjamin Wollmer -

Client- (Browser-)

CacheProxy

CachesISP

CachesCDN

CachesReverse-

Proxy Cache

Miss

Hit

MissMiss

MissMiss

Orestes

Expiration vs Invalidation

19.04.2021 37

Client- (Browser-)

CacheProxy

CachesISP

CachesCDN

CachesReverse-

Proxy Cache

Miss

Hit

MissMiss

MissMiss

Orestes

Expiration-based Invalidation-based

Backend

Page 38: Benjamin Wollmer -

HTTP/2

DNS Lookup Initial Connection

TLS Handshake

Time to First Byte Content Download

20 ms0 60 ms 80 ms 100 ms40 ms

TCP Handshake

Page 39: Benjamin Wollmer -

HTTP/2 – What is it about

19.04.2021 39

Give new knobs totune networkperformance

Fix design flawsof HTTP1.x in

terms ofperformance

Keep HTTP semantics

intact

Page 40: Benjamin Wollmer -

HTTP/2 – Features

19.04.2021 40

Multiplexing(1 Connection)

ResourcePrioritization

ServerPush

HeaderCompression

Page 41: Benjamin Wollmer -

HTTP/1.1 Pipelining

19.04.2021 41

Client ServerHTTP/1.1 Client ServerHTTP/1.1Pipelining

Client ServerHTTP/2 Multiplexing

Problem:Head-of-line blocking

vs. HTTP/2 Multiplexing

Page 42: Benjamin Wollmer -

Features: Multiplexing (vs. Pipelining)

19.04.2021 42

HTTP/1.1 HTTP/26 TCP connectionswith handshake

Requests in blocks of 6

Load time cut in half

Higher load time per request but fullconcurrency

Page 43: Benjamin Wollmer -

Multiplexing vs. Priorities

19.04.2021 43

CSS

JavaScript

JavaScript

PNG

JPG

PNG

JPG

Time

First Paint

CSS

JavaScript

JavaScript

PNG

JPG

PNG

JPG

Time

First Paint

} Higher Priorities

Page 44: Benjamin Wollmer -

Resource Prioritization

▪ Dependencies: A resource is transferred ahead of its dependencies

▪ Weights: Resources with same parent are send in proportion to their weight

▪ Browser sets priority automatically

19.04.2021 44

Page 45: Benjamin Wollmer -

Features: Header Compression

HPACK Compression:

▪ Dictionaries on client and server for sent headers

▪ Static dictionary for common headers

▪ Dynamic dictionary for other headers

▪ Huffman encoding for header fields

19.04.2021 45Ilya Grigorik - High Performance Browser Networking – HTTP/2https://hpbn.co/http2/

Page 46: Benjamin Wollmer -

Optimization: Domain Sharding

19.04.2021 46

Domain Sharding

Objective: parallelize requests

HTTP/2 Connection

Advantages

▪ Unlimited parallelism on one connection

▪ Less protocol overhead (1 vs 6 TLS handshakes)

▪ Better resource prioritization

▪ Better congestion control

Page 47: Benjamin Wollmer -

Optimization: Concatenation

19.04.2021 47

++

==

Advantages

▪ Better prioritization

▪ Individually cachable

Page 48: Benjamin Wollmer -

Optimization: Spriting

19.04.2021 48

PNG

Advantages

▪ Better prioritization

▪ Individually cachable

PNGPNG PNG

Page 49: Benjamin Wollmer -

HTTP/2: Push

19.04.2021 49

Client Server

HTML Request

HTML Response

CSS Request

CSS Response

• Server pushes needed resources proactively to the client

• Browser request is answered immediately from push cache

CSS Request

Response

Push CSS Response

Push Cache

Saves:

• one roundtrip for the request• several roundtrips for download

Page 50: Benjamin Wollmer -

HTTP/3

Page 51: Benjamin Wollmer -

Problem: HTTP/2 Head-Of-Line Blocking

▪ Now on TCP Level

▪ 1 Connection = Everything isblocked

▪ Performance may be worsethen HTTP/1.1 (Bad Connection)

19.04.2021 51

Page 52: Benjamin Wollmer -

HTTP/3: TCP → UDP (QUIC)

▪ Semantics Stay

▪ Browser Support

▪ (Only) Enabled in Chrome

▪ Additional Computing Overhead

▪ Quic

▪ Secure by Default

▪ Independed Requests

▪ Fast Network Switch

19.04.2021 52

Page 53: Benjamin Wollmer -

Compression

Page 54: Benjamin Wollmer -

HTTP Text Compression

Content Encoding Desktop Mobile Combined

No text compression 60.06% 59.31% 59.67%

Gzip 30.82% 31.56% 31.21%

Brotli 9.10% 9.11% 9.11%

Other 0.02% 0.02% 0.02%

19.04.2021 54Web Almanac 2020, Chapter 19: Compressionhttps://almanac.httparchive.org/en/2020/compression

Page 55: Benjamin Wollmer -

Deflate vs. Brotli

▪ Encoded Dictionary

▪ Decompression:

▪ ~443 MB/s - ~484 MB/s

▪ Compression:

▪ ~146 MB/s - ~32 MB/s

▪ Static Dictionary

▪ Decompression:

▪ ~441 MB/s - ~508 MB/s

▪ Compression:

▪ ~145 MB/s - ~0.6 MB/s

19.04.2021 55J. Alakuijala, E. Kliuchnikov, Z. Szabadka, L. Vandevenne: Comparison of Brotli, Deflate, Zopfli, LZMA, LZHAM and Bzip2 Compression Algorithms, 2015

Page 56: Benjamin Wollmer -

The Forgotten Ones

Delta Encoding

▪ Reuse Stale Content

▪ Only Updates

SDCH

▪ Predecessor of Brotli

▪ Dynamic Dictionaries

19.04.2021 56

Page 57: Benjamin Wollmer -

Summary

19.04.2021 57

Optimize TCP, DNS and TLS

Reduce Latencyby Caching

Make use of newHTTP Features

Page 58: Benjamin Wollmer -

Related Documents