Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
-
Upload
alex-theedom -
Category
Technology
-
view
1.314 -
download
5
Transcript of Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
![Page 1: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/1.jpg)
What Servlet 4 and HTTP/2 mean to you
Alex Theedom @alextheedom
![Page 2: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/2.jpg)
Alex Theedom, Senior Java Developeralextheedom.com
@alextheedom
Who am I?
![Page 3: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/3.jpg)
What’s on?1 Why Do We Need HTTP/22 Work-Arounds to HTTP1.13 HTTP Sockets4 Topline HTTP/2 Features5 Servlet 4.0 Features6 Server Support7 What about SPDY?8 HTTP/2 Performance9 Tracking HTTP/2 Adoption10 Summary and Q&A
![Page 4: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/4.jpg)
■Increase perceived performance of web
■HTTP protocol not suitable
■Since 2011 average web page size increased by over 300%
■The problem with HTTP/1.1
Why Do We Need HTTP/2The Goal of HTTP/2
300%Source: HTTPArchive.com
![Page 5: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/5.jpg)
■Requests resources in parallel HTTP 1■One request per TCP connection■HTTP1.1 Pipelining: multiple requests■Responds in sequence■Delay causes head-of-line blocking
Why Do We Need HTTP/2How a browser loads a webpage?
open
close
client serverno pipelining
index.html
style_1.css
logo.jpg
open
close
client serverpipelining
time
index.html
style_1.csslogo.jpg
![Page 6: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/6.jpg)
Multiple connections
However two issues1. TCP sockets expensive
2. Browser max connections
Work-Arounds to HTTP1.1Solution to Head-Of-Line Blocking
open
close
client server
connection 1style_1.css
open
close
client server
connection 2javaScript_1.js
open
close
client server
connection 3image_1.png
![Page 7: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/7.jpg)
Work-Arounds to HTTP1.1CSS/JavaScript File Concatenation
background.cssheader.cssmenu.cssstyle.css
![Page 8: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/8.jpg)
Work-Arounds to HTTP1.1CSS and JavaScript Inlining
![Page 9: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/9.jpg)
■Embed image in web page■Base 64 encoded
■Time spent decoding■Caching difficult
Work-Arounds to HTTP1.1Inlined Assets
![Page 10: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/10.jpg)
One image file consists of many smaller images
Image sprites from Amazon, Google and Facebook.
Work-Arounds to HTTP1.1Image Sprite Sheet
![Page 11: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/11.jpg)
Work-Arounds to HTTP1.1Domain Sharding
web pagey.example.com
x.example.com
server 2
server 1
logo.jpg
icon.jpg
header.css
menu.css
![Page 12: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/12.jpg)
■Not much specified■Throw away resources
■No maximum open sockets
HTTP SocketsWhat HTTP1.1 Says About Sockets
![Page 13: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/13.jpg)
■Much is specified■Scares resources
■Ideally only open one socket
HTTP SocketsWhat HTTP/2 Says About Sockets
![Page 14: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/14.jpg)
HTTP SocketsAll connections now operate as one connection
open
close
client server
open
close
client server
open
close
client server
open
close
client server open
close
client serveropen
close
client server
![Page 15: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/15.jpg)
■HTTP/2 is comprised of two specifications:■Hypertext Transfer Protocol version 2 - RFC7540
■HPACK - Header Compression for HTTP/2 - RFC7541
■Binary Protocol Based on Frames
■Features:■Request/Response Multiplexing
■Binary Framing ■Header Compression■Stream Prioritization
■Server Push■Upgrade From HTTP1.1
Topline HTTP/2 Features What’s new
![Page 16: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/16.jpg)
■Most important feature■Request and response is multiplexed ■Fully bi-directional communication
■Concepts:■Connection - A TCP socket
■Stream – A channel of communication■Message – A request/response and control message■Frame –The smallest unit within a communication
■Resolves head-of-line blocking■Communication broken down into frames
■Frames facilitate interweaving the logical stream
Topline HTTP/2 FeaturesRequest/Response Multiplexing
![Page 17: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/17.jpg)
Hierarchical structure of logical communication blocks
Topline HTTP/2 FeaturesRequest/Response Multiplexing
connectionstream
frame frame frameframe frame frame
message
stream
frame frame frameframe frame frame
messageframe frame frameframe frame frame
message
stream
frame frame frameframe frame frame
messageframe frame frameframe frame frame
messageframe frame frameframe frame frame
message
![Page 18: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/18.jpg)
■Request/Response Multiplexing■Interweave the logical stream over a single TCP
Stream 3 sends header then body and server responds with stream 2 before it receives completed stream 3
Topline HTTP/2 FeaturesRequest/Response Multiplexing
STREAM 1HEADERS
STREAM 3DATA
STREAM 1DATA
STREAM 2HEADERS
STREAM 3HEADERS
STREAM 2DATA
browser
server
![Page 19: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/19.jpg)
■Decomposition of the frame■The frame has a header and the head consists of some information
■Type fields can be■HEADER corresponds to the HTTP headers
■DATA corresponds to the HTTP request body■PRIORITY specifies stream priority
■PUSH_PROMISE notifies of server push intent ■RST_STREAM notifying error, client rejects push
■SETTING, PING, GOAWAY, WINDOW_UPDATE, CONTINUATION
Topline HTTP/2 FeaturesBinary Framing
LENGTH (24)TYPE (8) FLAGS (8)
R STREAM IDENTIFIER (31)FRAME PAYLOADS (0.. n)
![Page 20: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/20.jpg)
Mapping the HTTP Request to Frames
Topline HTTP/2 FeaturesHeader Compression
HTTP request Header FrameGET /index.html HTTP/1.1Host: example.comAccept: text/html
HEADERS + END_STREAM - END_HEADERS :method: GET :scheme: http :path: /index.html :authority: example.com accept: text/html
![Page 21: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/21.jpg)
Mapping the HTTP Response to Frames
Topline HTTP/2 FeaturesHeader Compression
HTTP response Header FrameHTTP/1.1 200 OKContent-Length: 11Content-Type: text/htmlMay The Force Be With You
HEADERS - END_STREAM + END_HEADERS :status: 200 content-length: 11 content-type: text/htmlData FrameDATA + END_STREAMMay The Force Be With You
![Page 22: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/22.jpg)
■Reduces header duplication■scheme, accept, user-agent
■Server and client maintains a table of headers
■Send only difference and references header number
Topline HTTP/2 FeaturesHPACK header compression
HTTP Request 1:method GET:scheme https:host example.com:path /index.html:authority example.org:accept text/htmluser-agent Mozilla/5.0
HTTP Request 2:method GET:scheme https:host example.com:path /info.html:authority example.org:accept text/htmluser-agent Mozilla/5.0
HEADERS frame (Stream 1):method GET:scheme https:host example.com:path /index.html:authority example.org:accept text/htmluser-agent Mozilla/5.0
HEADERS frame (Stream 3):path /info.html
![Page 23: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/23.jpg)
■Attach priority information to streams■Priority can be entered in the header frame or the priority frame
■Only a suggestion to the server
Topline HTTP/2 FeaturesStream Prioritization
B D C
A
2 14 10
B C
A
4 8
![Page 24: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/24.jpg)
■Eliminate the need for resource inlining■The sever can proactively send resources to the client
■Client can reject PUSH_PROMISE by responding RST_STREAM
Topline HTTP/2 FeaturesServer Push
![Page 25: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/25.jpg)
■How do we talk in HTTP/2?
■Two ways to talk in HTTP2■HTTP 1.1 in clear text send upgrade header to upgrade to protocol
h2c■HTTPS use ALPN (TLS extension) and communication continues in
h2
■However Firefox or Chrome does not support h2c
■HTTPS all the way
Topline HTTP/2 FeaturesUpgrade Negotiation
![Page 26: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/26.jpg)
■Servlet API well positioned to enable HTTP2 optimisation
■Servlet 4.0 Appropriate Abstraction
■Provide high level abstraction■Don’t want to program frames at the servlet layer
■OUT: one request = one response■IN: one request = multiple responses
Servlet 4.0 FeaturesAppropriate Abstraction
![Page 27: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/27.jpg)
Servlet 4.0 FeaturesServer Push
■Most visible improvements in servlets
■Improve perceivable performance
■Best place to know what resources a request needs■logo image, stylesheet, menu javascript etc
■Not a replacement for websockets
■JSF will make good use of Server Push and other frameworks
■Implemented as PushBuilder API
![Page 28: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/28.jpg)
Servlet 4.0 FeaturesTypical Journey
1. Browser requests index.html2. Server discovers need for css and js3. Get PushBuilder from HTTP request4. Set path to css and invoke push5. Set path to js and invoke push6. Then responds with index.html
Note7. The pushBuilder can be reused8. index.html returned after pushed resources
RST_STREAM rejects cached resources
![Page 29: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/29.jpg)
■javax.servlet.http.PushBuilder■To use server push, obtain a reference to a PushBuilder from an
HttpServletRequest, mutate the builder as desired, then call push()
Servlet 4.0 FeaturesPushBuilder
![Page 30: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/30.jpg)
Servlet 4.0 FeaturesPushBuilder
■javax.servlet.http.PushBuilder■constructed with request method set to GET■conditional, range, expectation, authorization and request headers
are removed■cookies are only added if the maxAge has not expired■request header set to the request URL plus any query string present■only required setting is the URI path to the resource■must be set before every call to push()
![Page 31: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/31.jpg)
Servlet 4.0 FeaturesServlets and ServerPush
■Simple usage
![Page 32: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/32.jpg)
Servlet 4.0 FeaturesFilters and Server Push
![Page 33: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/33.jpg)
Servlet 4.0 FeaturesJSF Use Case
■Framework use case most important■Dependent on knowing the resources the client requires■Server side web frameworks best placed to take advantage of server
push
![Page 34: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/34.jpg)
Servlet 4.0 FeaturesJava 9 Support
■JEP 110■Does not reinvent HttpClient■Supports HTTP1.1 and HTTP/2
■Full server push support■Two modes: blocking and non-blocking
HttpClient.Builder HttpClient HttpRequest.BuilderHttpRequest: POSTHttpRequest: GET
![Page 35: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/35.jpg)
Servlet 4.0 FeaturesJava 9 Support
■GET
![Page 36: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/36.jpg)
Servlet 4.0 FeaturesJava 9 Support
■POST
![Page 37: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/37.jpg)
Servlet 4.0 FeaturesDisable/Reject Server Push
■Clients can explicitly disabled server push by sending a SETTINGS_ENABLE_PUSH
■Servlet containers must honor a client’s request to not receive a pushed response
■Browser already has the resource in its cache.■RST_STREAM rejects cached resources
![Page 38: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/38.jpg)
Server ImplementationServlet Support
■GlassFish 5.0 ■Reference implementation
■Payara 5.0■Recently created a branch for Java EE 8 development
■Jetty Stable-9 (9.3.8.v20160314)■org.eclipse.jetty.servlets.PushCacheFilter/PushBuilder
■WildFly 10 (Undertow)■Initial PushBuilder support implemented in Undertow master
■Tomcat 9.0.0.M4 alpha■Initial PushBuilder Supports Servlets 4.0's PushBuilder in the
javax.servlets.http package■Netty 4.1
■HTTP/2 implementation takes full advantage of headline features
![Page 39: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/39.jpg)
Server ImplementationTomcat Configuration
■TLS required■TLS virtual hosting and multiple certificate are supported for a single
connector each virtual host is able to support multiple certificates
![Page 40: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/40.jpg)
What About SPDY?Stepping Stone to HTTP/2
■Primary focus reduce web page load time■Same as HTTP/2■Formed first draft of HTTP/2■Stepping stone to HTTP/2■Chrome will drop support in favour of HTTP/2
![Page 41: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/41.jpg)
HTTP/2 PerformanceOverriding Goal to Improve Performance
■The goal of HTTP/2 is to improve performance
■Cloudflare HTTP/2 demonstration tool cloudflare.com/http2
■Anthum's HTTP vs HTTPS httpvshttps.com
![Page 42: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/42.jpg)
Tracking HTTP/2 AdoptionHow to Track Adoption
■Servers advise HTTP/2 support during the SSL handshake■Using shodan.io searches can be made using the ssl.alpn filter
![Page 43: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/43.jpg)
Tracking HTTP/2 AdoptionAdoption Data
■Analysis■Between December 2015 and April 2016 HTTP/2 adoption up to 10%■However growth comes from upgrading incumbent version HTTP/2■Combining protocols we see no meaningful change
![Page 44: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/44.jpg)
Q & A
![Page 45: Java EE 8: What Servlet 4.0 and HTTP/2 mean to you](https://reader034.fdocuments.us/reader034/viewer/2022051301/586fdbc31a28ab18428b6253/html5/thumbnails/45.jpg)
What Servlet 4 and HTTP/2 mean to you
Alex Theedom @alextheedom