Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

HTTP2 and Java

57 views

Published on

HTTP2 is out there for almost 3 years already. Browsers have good support for it, application servers have good support and even Java9 have HTTP client that also support it. So what problems does HTTP2 solves and why should I use it?

Published in: Software
  • Be the first to comment

  • Be the first to like this

HTTP2 and Java

  1. 1. HTTP/2 and Java AUDRIUS MIČIULIS SENIOR JAVA DEVELOPER AT DEVBRIDGE
  2. 2. HTTP History 1991 – HTTP/0.9 1995 – HTTP/1.0 1997 – HTTP/1.1 2012 – SPDY/2 2015 – HTTP/2 (H2)
  3. 3. http://www.w3.org (1996) 1 html, 11 images, ~21.5 KB
  4. 4. http://www.w3.org (2018) 1 html, 4 css, 2 js, 32 images, ~643 KB
  5. 5. http://www.delfi.lt (2018) 86 html, 29 css, 720 js, 1316 images, 75 XHR, 2910 total ~35.1 MB
  6. 6. HTTP 1.0
  7. 7. HTTP 1.1
  8. 8. HTTP 1.1
  9. 9. Domain Sharding
  10. 10. Image Sprites
  11. 11. JavaScript Bundling and Minification
  12. 12. Image Inlining
  13. 13. Vulcanize
  14. 14. Head of Line Blocking
  15. 15. Revenue increase by fast response time • Shopzilla saw a 12% revenue increase after improving average page load times from 6 seconds to 1.2 seconds. • Amazon saw 1% revenue increase for every 100ms improvement. • AOL found visitors in the top ten percentile of site speed view 50% more pages than visitors in the bottom ten percentile. • Yahoo increased traffic by 9% for every 400ms improvement. • Mozilla estimated 60 million more Firefox downloads as a result of making page loads 2.2 seconds faster.
  16. 16. Banndwidth vs Latency
  17. 17. SPDY
  18. 18. HTTP/2 Be less sensitive to latency Fix head of line blocking problem Eliminate the need to increase the number of connections to each host Keep all existing interfaces , URI formats and schemes Be made within the IEFT’s HTTPbis working group
  19. 19. HTTP/2 Core Features Request/Response Multiplexing Binary Data Format Prioritisation Header compression Flow control Server push
  20. 20. Multiplexing
  21. 21. Multiplexing
  22. 22. Multiplexing
  23. 23. Frames
  24. 24. Multiplexing
  25. 25. HTTP/2 is Binary Protocol
  26. 26. TLS is a must
  27. 27. Header Compression
  28. 28. Header Compression
  29. 29. Gzip
  30. 30. Request Prioritization Weights/Dependencies
  31. 31. Mozilla example
  32. 32. Flow Control
  33. 33. Server Push
  34. 34. Server Push
  35. 35. Jetty Smart Push
  36. 36. Cache
  37. 37. Servlet 4.0 One Request = Multiple Responses Request/Response Multiplexing Stream Prioritization Server Push Upgrade from HTTP 1.1 (101 Switching Protocols)
  38. 38. Servlet 4.0 HttpServletRequest ◦ int getStreamId() ◦ Priority getPriority() ◦ PushBuilder getPushBuilder() HttpServletResponse ◦ int getStreamId() ◦ Priority getPriority() ◦ void setPriority(Priority priority)
  39. 39. Servlet 4.0 Priority ◦ boolean exclusive ◦ int streamId ◦ int weight PushBuilder ◦ PushBuilder path(String path) ◦ void push()
  40. 40. Example
  41. 41. HTTP/2 browser support
  42. 42. HTTP/2 infrastructure server support Jetty 9.3 Apache Tomcat 9.0 JBoss 9.0 Glass Fish 5.0 Apache 2.4.12 nginx 1.9.5 HA Proxy 1.8
  43. 43. Demo https://http2.golang.org/gophertiles?latency=0 http://http2.golang.org/serverpush
  44. 44. What’s next DevOps: ◦ Upgrade your infrastructure (e.g. servlet container, load balancer, etc.) ◦ TLS everywhere Developers: ◦ Servlet 4.0 is backward compatible ◦ Remove HTTP 1.1 hacks ◦ Frameworks(e.g. JSF) already use HTTP/2 push
  45. 45. JDK HTTP client (JEP-110, JEP-321)
  46. 46. JDK HTTP client (JEP-110, JEP-321) HttpClient(Builder) ◦ <T> HttpResponse<T> send(HttpRequest request, HttpResponse.BodyHandler<T> handler) ◦ <T> CompletableFuture<HttpResponse<T>> sendAsync( HttpRequest request, HttpResponse.BodyHandler<T> handler) ◦ <U, T> CompletableFuture<U> sendAsync( HttpRequest request, HttpResponse.MultiProcessor<U, T> processor) HttpRequest(Builder) HttpResponse ◦ int statusCode() ◦ <T> body()
  47. 47. JDK HTTP client (JEP-110, JEP-321) MultiProcessor ◦ Optional<BodyHandler<T>> onRequest(HttpRequest request) ◦ void onResponse(HttpResponse<T> response) ◦ void onError(HttpRequest request, Throwable t) ◦ CompletableFuture<U> completion( CompletableFuture<Void> onFinalPromise, CompletableFuture<Void> onComplete) CompletableFuture<T> ◦ allOf(CompletableFuture[] futures) ◦ join()
  48. 48. Example
  49. 49. Example
  50. 50. Example
  51. 51. Example
  52. 52. Example
  53. 53. Questions

×