Better performances with HTTP/2

Cb52062fbd7e159b54e3c298d622fe72?s=47 Julien Viet
June 17, 2016
250

Better performances with HTTP/2

Cb52062fbd7e159b54e3c298d622fe72?s=128

Julien Viet

June 17, 2016
Tweet

Transcript

  1. Better performances with HTTP/2 @julienviet

  2. None
  3. None
  4. 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
  5. HTTP/1 in the browser

  6. HTTP / TCP impedance mismatch

  7. HTTP/2 in the browser

  8. HTTP/2 intent Not a new version of the protocol it’s

    about how it gets onto the wire
  9. HTTP/2 brings network sympathy

  10. HTTP/2 origins HTTP is 20 years old HTTP bis started

    but Google prototyped SPDY Which became HTTP/2
  11. The good news: no changes to HTTP paradigms!

  12. B1n4ry

  13. S-l-i-c-e

  14. COMPR ESS headers headers headers headers headers headers headers headers

    headers headers headers headers headers headers headers headers headers headers
  15. Priorities

  16. PUSH

  17. HTTP/2 on the server

  18. 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
  19. Benchmark Pace requests at a given rate Log ratio of

    requests performed/planned Log response time percentiles https://github.com/vietj/http2-bench
  20. HTTP/1 - 8 connections - pipelined

  21. What is limiting us ?

  22. FIFO one thing at a time!

  23. HTTP/2 multiplexing

  24. HTTP/2 - 1 connections - concurrency 20

  25. Concurrency increased !

  26. But…

  27. HTTP/2 - 1 connections - concurrency 400

  28. Congestion

  29. None
  30. Multithreading is an illusion of parallelism

  31. Streams are an illusion of continuity

  32. However the reality is different

  33. In reality we have CPU which have cores and we

    manipulate network packets
  34. We want to make a better usage of our resources

  35. How to write programs that are efficient ?

  36. The real problem is blocking

  37. How to *not* block ?

  38. Concurrency patterns with Vert.x

  39. None
  40. 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
  41. Vert.x Created in 2012 Eclipse project Stable 3.2.1 Next week

    3.3.0
  42. Vert.x Core TCP / HTTP / UDP / DNS File

    Event Bus Deployment Cluster / HA
  43. Reactor pattern

  44. –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
  45. 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); }
  46. 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()); }); }); }
  47. 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); }); }); });
  48. client.getNow(url, …) resp.setStatus(code) resp.end(body)

  49. None
  50. Meet the event loop 1 Thread

  51. C10K it’s all about concurrency

  52. HTTP/2 non blocking - 1 connection - concurrency 400

  53. using… a single core!

  54. reactor pattern multi

  55. Load balancing

  56. HTTP/2 non blocking - 4 connections - concurrency 200

  57. Outro

  58. Users & community

  59. Community posts 0 300 600 900 1200 July September November

    Janvier Mars Mai
  60. None
  61. vertx.io