Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTTP/2 performance and Non-blocking Architecture

Julien Viet
August 04, 2016
110

HTTP/2 performance and Non-blocking Architecture

Julien Viet

August 04, 2016
Tweet

Transcript

  1. HTTP/2 performance and Non-blocking Architecture @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. Why HTTP/2 performs better

  11. B1n4ry

  12. COMPR ESS headers headers headers headers headers headers headers headers

    headers headers headers headers headers headers headers headers headers headers
  13. S-l-i-c-e

  14. Priorities

  15. PUSH

  16. HTTP/2 on the server

  17. HTTP/1 vs HTTP/2 benchmark Frontend HTTP/1 vs HTTP/2 Backend Client

    connection pool 20ms think time
  18. Benchmark Pace requests at a given rate Log ratio of

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

  20. What is limiting us ?

  21. FIFO one thing at a time!

  22. HTTP/2 multiplexing

  23. HTTP/2 - 1 connections - concurrency 20

  24. Concurrency increased !

  25. But…

  26. HTTP/2 - 1 connections - concurrency 400

  27. Congestion

  28. None
  29. Multithreading is an illusion of parallelism

  30. Input / Output Streams of byte byte[]

  31. However the reality is different

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

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

  34. How to write programs that are efficient ?

  35. The real problem is blocking

  36. How to *not* block ?

  37. Concurrency with Vert.x

  38. http://vertx.io Library for building reactive applications Eclipse project (ASL2/EPL) Java

    8 Vert.x Core • core library for building a stack • embeddable (core 1MB) Vert.x stack • coherent set of libraries built on top of Vert.x Core • data access, messaging, metrics, etc…
  39. What’s Vert.x ? Inspired from Erlang/OTP and Node Event driven

    Polyglot Event bus High performances / easy to scale Lightweight / embeddable Clustering / HA
  40. Why Vert.x Simple concurrency model Unified async API for IO,

    filesystem, data access, messaging, … Easy to scale Easy to deploy Coherent stack Provides also an RxJava API
  41. 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); }
  42. 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()); }); }); }
  43. 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); }); }); });
  44. client.getNow(url, …) resp.setStatus(code) resp.end(body)

  45. None
  46. Reactor pattern: Event Loop Single Threaded

  47. C10K it’s all about concurrency

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

  49. using… a single core!

  50. Multi reactor pattern

  51. Load balancing

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

  53. Discussion From network to application Reactive back pressure Going distributed