Slide 1

Slide 1 text

Better performances with HTTP/2 @julienviet

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Latency vs Bandwidth impact on Page Load Time Page Load Time as bandwidth increases 1000 1550 2100 2650 3200 1Mbps 2Mbps 2Mbps 4Mbps 5Mbps 6Mbps 7Mbps 8Mbps 9Mbps 10Mbps Page Load Time as latency decrease 1000 1750 2500 3250 4000 200 ms 180 ms 160 ms 140 ms 120 ms 100 ms 80 ms 60 ms 40 ms 20 ms

Slide 5

Slide 5 text

HTTP/1 in the browser

Slide 6

Slide 6 text

HTTP / TCP impedance mismatch

Slide 7

Slide 7 text

HTTP/2 in the browser

Slide 8

Slide 8 text

HTTP/2 intent Not a new version of the protocol it’s about how it gets onto the wire

Slide 9

Slide 9 text

HTTP/2 brings network sympathy

Slide 10

Slide 10 text

HTTP/2 origins HTTP is 20 years old HTTP bis started but Google prototyped SPDY Which became HTTP/2

Slide 11

Slide 11 text

The good news: no changes to HTTP paradigms!

Slide 12

Slide 12 text

B1n4ry

Slide 13

Slide 13 text

S-l-i-c-e

Slide 14

Slide 14 text

COMPR ESS headers headers headers headers headers headers headers headers headers headers headers headers headers headers headers headers headers headers

Slide 15

Slide 15 text

Priorities

Slide 16

Slide 16 text

PUSH

Slide 17

Slide 17 text

HTTP/2 on the server

Slide 18

Slide 18 text

Benchmark HTTP/1 vs HTTP/2 performances Client / frontend / backend servers Client -> Frontend : HTTP/1 or HTTP/2 Front -> Backend : HTTP/1 Backend has 20ms service time

Slide 19

Slide 19 text

Benchmark Pace requests at a given rate Log ratio of requests performed/planned Log response time percentiles https://github.com/vietj/http2-bench

Slide 20

Slide 20 text

HTTP/1 - 8 connections - pipelined

Slide 21

Slide 21 text

What is limiting us ?

Slide 22

Slide 22 text

FIFO one thing at a time!

Slide 23

Slide 23 text

HTTP/2 multiplexing

Slide 24

Slide 24 text

HTTP/2 - 1 connections - concurrency 20

Slide 25

Slide 25 text

Concurrency increased !

Slide 26

Slide 26 text

But…

Slide 27

Slide 27 text

HTTP/2 - 1 connections - concurrency 400

Slide 28

Slide 28 text

Congestion

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Multithreading is an illusion of parallelism

Slide 31

Slide 31 text

Streams are an illusion of continuity

Slide 32

Slide 32 text

However the reality is different

Slide 33

Slide 33 text

In reality we have CPU which have cores and we manipulate network packets

Slide 34

Slide 34 text

We want to make a better usage of our resources

Slide 35

Slide 35 text

How to write programs that are efficient ?

Slide 36

Slide 36 text

The real problem is blocking

Slide 37

Slide 37 text

How to *not* block ?

Slide 38

Slide 38 text

Concurrency patterns with Vert.x

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Vert.x Polyglot Event driven Vert.x Core • core library for building a stack • embeddable (core 1MB) Vert.x stack • a coherent stack built on top of Vert.x Core

Slide 41

Slide 41 text

Vert.x Created in 2012 Eclipse project Stable 3.2.1 Next week 3.3.0

Slide 42

Slide 42 text

Vert.x Core TCP / HTTP / UDP / DNS File Event Bus Deployment Cluster / HA

Slide 43

Slide 43 text

Reactor pattern

Slide 44

Slide 44 text

–Johnny Appleseed “The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.” - Wikipedia

Slide 45

Slide 45 text

Non blocking server public static void main(String [] args) { Vertx vertx = Vertx.vertx(); HttpServer server = vertx.createHttpServer(); server.requestHandler(req -> { req.response() .putHeader(“Content-Type”, “text/plain”) .end(“Hello World”); }); server.listen(8080); }

Slide 46

Slide 46 text

Non blocking client public static void main(String [] args) { HttpClient client = vertx.createHttpClient(); client.getNow(“http: //backend”, resp -> { int status = resp.status(); resp.bodyHandler(body -> { System.out.println(body.length()); }); }); }

Slide 47

Slide 47 text

NB server+client server.requestHandler(req -> { HttpServerResponse resp = req.response(); client.getNow(“http: //backend”, clientResp -> { int code = clientResp.status() resp.setStatus(code); clientResp.bodyHandler(body -> { resp.end(body); }); }); });

Slide 48

Slide 48 text

client.getNow(url, …) resp.setStatus(code) resp.end(body)

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Meet the event loop 1 Thread

Slide 51

Slide 51 text

C10K it’s all about concurrency

Slide 52

Slide 52 text

HTTP/2 non blocking - 1 connection - concurrency 400

Slide 53

Slide 53 text

using… a single core!

Slide 54

Slide 54 text

reactor pattern multi

Slide 55

Slide 55 text

Load balancing

Slide 56

Slide 56 text

HTTP/2 non blocking - 4 connections - concurrency 200

Slide 57

Slide 57 text

Outro

Slide 58

Slide 58 text

Users & community

Slide 59

Slide 59 text

Community posts 0 300 600 900 1200 July September November Janvier Mars Mai

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

vertx.io