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

Better performances with HTTP/2

Julien Viet
June 17, 2016
280

Better performances with HTTP/2

Julien Viet

June 17, 2016
Tweet

Transcript

  1. Better performances
    with HTTP/2
    @julienviet

    View full-size slide

  2. 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

    View full-size slide

  3. HTTP/1 in the
    browser

    View full-size slide

  4. HTTP / TCP
    impedance mismatch

    View full-size slide

  5. HTTP/2 in the
    browser

    View full-size slide

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

    View full-size slide

  7. HTTP/2 brings
    network sympathy

    View full-size slide

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

    View full-size slide

  9. The good news:
    no changes to HTTP
    paradigms!

    View full-size slide

  10. COMPR
    ESS
    headers headers headers
    headers headers headers
    headers headers headers
    headers headers headers
    headers headers headers
    headers headers headers

    View full-size slide

  11. HTTP/2 on the server

    View full-size slide

  12. 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

    View full-size slide

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

    View full-size slide

  14. HTTP/1 - 8 connections - pipelined

    View full-size slide

  15. What is limiting us ?

    View full-size slide

  16. FIFO
    one thing
    at a time!

    View full-size slide

  17. HTTP/2
    multiplexing

    View full-size slide

  18. HTTP/2 - 1 connections - concurrency 20

    View full-size slide

  19. Concurrency
    increased !

    View full-size slide

  20. HTTP/2 - 1 connections - concurrency 400

    View full-size slide

  21. Multithreading is an
    illusion of parallelism

    View full-size slide

  22. Streams are an
    illusion of continuity

    View full-size slide

  23. However the reality is
    different

    View full-size slide

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

    View full-size slide

  25. We want to make a
    better usage of our
    resources

    View full-size slide

  26. How to write programs
    that are efficient ?

    View full-size slide

  27. The real problem is
    blocking

    View full-size slide

  28. How to *not* block ?

    View full-size slide

  29. Concurrency patterns
    with Vert.x

    View full-size slide

  30. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  33. Reactor
    pattern

    View full-size slide

  34. –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

    View full-size slide

  35. 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);
    }

    View full-size slide

  36. 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());
    });
    });
    }

    View full-size slide

  37. 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);
    });
    });
    });

    View full-size slide

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

    View full-size slide

  39. Meet the event loop
    1 Thread

    View full-size slide

  40. C10K
    it’s all about
    concurrency

    View full-size slide

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

    View full-size slide

  42. using…
    a single core!

    View full-size slide

  43. reactor pattern
    multi

    View full-size slide

  44. Load balancing

    View full-size slide

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

    View full-size slide

  46. Users & community

    View full-size slide

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

    View full-size slide