jdkio: java ee 8 what servlet 4 and http2 mean to you

49
Alex Theedom @readlearncode Java EE 8: What Servlet 4.0 and HTTP/2 mean?

Upload: alex-theedom

Post on 16-Mar-2018

472 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Alex Theedom @readlearncode

Java EE 8:

What Servlet 4.0 and

HTTP/2 mean?

Page 2: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Who am I?

Alex Theedom

Author

Trainer

Blogger

Speaker

Page 3: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

What’s on?

Page 4: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Why Do We Need HTTP/2

• Workarounds to HTTP1.1

• HTTP Sockets

• Topline HTTP/2 Features

• Servlet 4.0 Features

• Server Support

• Status Update

• Extract Bits

• Q&A

What’s on?

Page 5: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Why Do We Need HTTP/2?

Page 6: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Increase perceived performance of web

• HTTP protocol not suitable

• Since May 2012 web page size increased 250%

• The problem with HTTP/1.1

Source: HTTPArchive.com

Why Do We Need HTTP/2?The Goal of HTTP/2

Page 7: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Requests resources in parallel HTTP 1.0

• One request per TCP connection

• HTTP1.1 Pipelining: multiple requests

• Responds in sequence

• Delay causes head-of-line blocking

How a browser loads a webpage?

open

close

client server

no pipelining

index.html

style_1.css

logo.jpg

open

close

client server

pipelining

time

index.html

style_1.css

logo.jpg

Why Do We Need HTTP/2?

Page 8: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Workarounds

Page 9: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Multiple connections

• Acceptable but has issues

• TCP sockets expensive

• Browser max connections

Workarounds to HTTP1.1Solution to Head-Of-Line Blocking

open

close

client server

connection 1

style_1.css

open

close

client server

connection 2

javaScript_1.js

open

close

client server

connection 3

image_1.png

Page 10: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Workarounds to HTTP1.1CSS/JavaScript File Concatenation

background.css

header.css

menu.css

style.css

Page 11: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Workarounds to HTTP1.1CSS and JavaScript Inlining

Page 12: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Embed image in web page

• Base 64 encoded

• Time spent decoding

• Caching difficult

Workarounds to HTTP1.1Inlined Assets

Page 13: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• One image file consists of many smaller images

Workarounds to HTTP1.1Image Sprite Sheet

Image sprites from Amazon, Google and Facebook.

Page 14: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Workarounds to HTTP1.1Domain Sharding

web page

y.example.com

x.example.com

domain 2

domain 1

logo.jpg

icon.jpg

header.css

menu.css

Page 15: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

HTTP Sockets

Page 16: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Not much specified

• Two maximum open sockets (ignored by browsers)

• Throw away resources

HTTP SocketsWhat HTTP1.1 Says About Sockets

Page 17: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Much is specified

• Scares resources

• Only open one socket

HTTP SocketsWhat HTTP/2 Says About Sockets

Page 18: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Topline HTTP/2 Features

Page 19: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• 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

Topline HTTP/2 FeaturesWhat’s new

Page 20: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Request/Response Multiplexing

• Binary Framing

• Header Compression

• Stream Prioritization

• Server Push

Topline HTTP/2 FeaturesFeatures

Page 21: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• 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

Topline HTTP/2 FeaturesRequest/Response Multiplexing

Page 22: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Hierarchical structure of logical communication blocks

Topline HTTP/2 FeaturesRequest/Response Multiplexing

connection

stream

frame frame frame

frame frame frame

message

stream

frame frame frame

frame frame frame

message

frame frame frame

frame frame frame

message

stream

frame frame frame

frame frame frame

message

frame frame frame

frame frame frame

message

frame frame frame

frame frame frame

message

Page 23: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Interweave the logical stream over a single TCP

Topline HTTP/2 FeaturesRequest/Response Multiplexing

Page 24: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Decomposition of the frame

• Type fields can be• HEADERS corresponds to the HTTP headers

• DATA corresponds to the HTTP request body

• PUSH_PROMISE server notifies of push intent

• RST_STREAM notifying error, client rejects push

• PRIORITY specifies stream priority

• SETTING, PING, GOAWAY, WINDOW_UPDATE, CONTINUATION

Topline HTTP/2 FeaturesBinary Framing

Page 25: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Mapping the HTTP Request to Frames

Topline HTTP/2 FeaturesHeader Compression

HTTP request Header Frame

GET /index.html HTTP/1.1

Host: example.com

Accept: text/html

HEADERS

+ END_STREAM

+ END_HEADERS

:method: GET

:scheme: http

:path: /index.html

:authority: example.com

accept: text/html

Page 26: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Mapping the HTTP Response to Frames

Topline HTTP/2 FeaturesHeader Compression

HTTP response Frames

HTTP/1.1 200 OK

Content-Length: 11

Content-Type: text/html

May The Force Be With You

HEADERS

- END_STREAM

+ END_HEADERS

:status: 200

content-length: 11

content-type: text/html

DATA

+ END_STREAM

May The Force Be With You

Page 27: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Topline HTTP/2 FeaturesHPACK header compression

HTTP Request 1

:method GET

:scheme https

:host example.com

:path /index.html

:authority example.org

:accept text/html

user-agent Mozilla/5.0

HTTP Request 2

:method GET

:scheme https

:host example.com

:path /info.html

:authority example.org

:accept text/html

user-agent Mozilla/5.0

HEADERS frame (Stream 1)

:method GET

:scheme https

:host example.com

:path /index.html

:authority example.org

:accept text/html

user-agent Mozilla/5.0

HEADERS frame (Stream 3)

:path /info.html

Page 28: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Attach priority information to streams

• Priority located 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 29: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• 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 30: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Servlet 4.0 Features

Page 31: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Servlet 4.0 FeaturesServer Push

• Most visible improvements in servlets

• Best place to know what resources a request needs

Page 32: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Servlet 4.0 FeaturesPushBuilder

Page 33: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Browser requests index.html

• Server discovers need for css and js

• Get PushBuilder from HTTP request

• Set path to css and invoke push

• Set path to js and invoke push

• Then responds with index.html

• The PushBuilder can be reused

Servlet 4.0 FeaturesTypical Journey

Page 34: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Servlet 4.0 FeaturesPushBuilder Dive Deeper

• Constructed with request method set to GET by default

• Conditional, range, expectation, authorization and request headers

are removed• Cookies are only added if the maxAge has not expired

• Only required setting is the URI path to the resource• Must be set before every call to push()

Page 35: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Simple usage

Servlet 4.0 FeaturesServlets and ServerPush

Page 36: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Servlet 4.0 FeaturesFilters and Server Push

Page 37: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Web framework use case most important

• Dependent on knowing the resources the client requires

• Frameworks best placed to take advantage of server push

• JSF users get server push for free

Servlet 4.0 FeaturesJSF Use Case

Page 38: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• SETTINGS_ENABLE_PUSH clients disable server push

• RST_STREAM rejects cached resources

• Servlet containers must honour request to not receive

Servlet 4.0 FeaturesDisable/Reject Server Push

Page 39: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Perfectly backward compatible

• Rework to take advantage of Server Push

• Consider removing frontend workarounds

• JSF developers do nothing

Servlet 4.0 FeaturesBackward Compatible

Page 40: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Server Support

Page 41: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• GlassFish 5.0 (nightly)

Reference implementation

• Payara 5.0

Has a branch for Java EE 8 development

• Jetty Stable-9 (9.4.5.v20170502)

org.eclipse.jetty.servlets.PushCacheFilter/PushBuilder

Server ImplementationServlet Support

Page 42: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• WildFly 10 (Undertow)

Initial PushBuilder support implemented in Undertow master

• Tomcat 9.0.0.M20

PushBuilder support in thejavax.servlets.http package

• Netty 4.1

HTTP/2 implementation takes full advantage of headline

features

Server ImplementationServlet Support

Page 43: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Status Update

Page 44: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• As of 23 May 2017 in Public Review ballot status

• Issue Tracker: github.com/javaee/servlet-spec/issues

• JCP Specification: jcp.org/en/jsr/detail?id=369

• Twitter: @servlet_spec

Status UpdateJSP 369: Servlet Specification

Page 45: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Extra Bits

Page 46: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• The goal of HTTP/2 is to improve performance

• Cloudflare HTTP/2 demonstration tool

www.cloudflare.com/http2

• Anthum's HTTP vs HTTPS

www.httpvshttps.com

Performance TestsShow me the performance

Page 47: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

• Daniel Stenberg book: bagder.gitbooks.io/http2-explained

• Free O’Reilly e-book:

www.oreilly.com/webops-perf/free/HTTP2-high-perf-

browser-networking.csp

• FAQ: http2.github.io/faq

Useful Resources

Page 48: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

@readlearncode readlearncode.com

Q & A

Page 49: JDKIO: Java EE 8 what Servlet 4 and HTTP2 mean to you

Alex Theedom @readlearncode

Java EE 8:

What Servlet 4.0 and

HTTP/2 mean?