SlideShare une entreprise Scribd logo
1  sur  64
Andrii Bezruchko
Software Engineer @ EPAM
HOW WE GOT HERE
Total Transfer Size & Total Requests
HTTP HISTORY
Browser Compatibility of HTTP/2
22.3% of all Web sites support the HTTP/2
protocol
SUPPORT OF HTTP/2
SUPPORT OF HTTP/2
IIS: Windows Server
2016
Apache 2.4.17
nginx 1.9.5
Apache Tomcat 9.0.0
WildFly 10
Jetty Stable-9
Netty 4.1
Payara 5.0
Vert.x
GlassFish 5.0
Problem of HTTP/1.1
Responds in sequence
Head-of-Line blocking
One request per TCP connection
HTTP header fields are often
repetitive and verbose
client server
open
close
client server
open
close
client server
open
close
client server
open
close
HOL
How developers resolves problems of HTTP 1.1
• Creating sprites
• Inlining
• Joining
• Sharing
Image sprites
How HTTP/2.0 resolves problems
• Request/Response multiplexing
• Stream Prioritization and Dependency
• Server Push
• Header compression
HTTP/2 Units
CONNECTION
STREAM
FRAME FRAME FRAME FRAME
• Connection – single TCP connection
• Streams - channel that carries messages in two
directions
• Messages - request or response
• Frames – messages, which are broken down for
Binary Framing
STREAM IDENTIFIER (31)
FRAME PAYLOADS (0..N)
LENGTH (24)
R
TYPE (8) FLAGS (8)
Type of Frames in HTTP/2.0
DATA
Used to transport HTTP message bodies
HEADERS
Used to communicate header fields for a stream
PRIORITY
Used to communicate sender-advised priority of a stream
RST_STREAM
Used to signal termination of a stream
SETTINGS
Used to communicate configuration parameters for the
connection
PUSH_PROMISE
Used to signal a promise to serve the referenced resource
PING
Used to measure the roundtrip time and perform "liveness"
checks
GOAWAY
Used to inform the peer to stop creating streams for current
connection
WINDOW_UPDATE
Used to implement flow stream and connection flow control
CONTINUATION
Type of Frames in HTTP/2.0
HTTP 1.1 round-trip
Host: maven.apache.org
SecurityToken: j13c72208c9u5fa2
Accept: application/json
Accept-Encoding: gzip
GET /install.html HTTP/1.1
Content-Length: 327
Cache-Control: private, max-age=60, s-
maxage=0
Vary: SecurityToken
Date: Wed, 17 Jan 2018 21:31:57 GMT
Content-Type: application/json
Content-Encoding: gzip
GET /install HTTP/1.1
GZIPPED DATA
HTTP/2 round-trip
:method: GET
:authority: maven.apache.org
:path: /install.html
securitytoken: j13c72208c9u5fa2
accept: application/json
accept-Encoding: gzip
HEADERS
Stream: 3
Flags: END_HEADERS, END_STREAM :status: 200
content-Length: 327
cache-Control: private, max-age=60, s-
maxage=0
vary: SecurityToken
date: Wed, 17 Jan 2018 21:31:57 GMT
content-Type: application/json
content-Encoding: gzip
HEADERS
Stream: 3
Flags: END_HEADERS
GZIPPED DATA
DATA
Stream: 3
Flags: END_STREAM
Comparison requests of HTTP 1.1 & HTTP/2
:method: GET
:authority: maven.apache.org
:path: /install.html
securitytoken: j13c72208c9u5fa2
accept: application/json
accept-Encoding: gzip
HEADERS
Stream: 3
Flags: END_HEADERS, END_STREAM
Host: maven.apache.org
SecurityToken: j13c72208c9u5fa2
Accept: application/json
Accept-Encoding: gzip
GET /install.html HTTP/1.1
Comparison responses of HTTP 1.1 & HTTP/2
:status: 200
content-Length: 327
cache-Control: private, max-age=60, s-
maxage=0
vary: SecurityToken
date: Wed, 17 Jan 2018 21:31:57 GMT
content-Type: application/json
content-Encoding: gzip
HEADERS
Stream: 3
Flags: END_HEADERS
GZIPPED DATA
DATA
Stream: 3
Flags: END_STREAM
Content-Length: 327
Cache-Control: private, max-age=60,
s-maxage=0
Vary: SecurityToken
Date: Wed, 17 Jan 2018 21:31:57 GMT
Content-Type: application/json
Content-Encoding: gzip
GET /install HTTP/1.1
GZIPPED DATA
HTTP/2.0 HEADLINE FEATURE
Multiplexing
Priority
Flow control
Header
compression
Server push
Multiplexing
Priority
Flow control
Header
compression
Server push
HTTP/2.0 HEADLINE FEATURE
Request/Response Multiplexing
MaximumconcurrentopenTCPconnections
Browser
Parallel connections
per hostname
Chrome 6
Firefox 6
Opera 6
Safari 6
Internet Explorer 11 13
Microsoft Edge 13
Request/Response Multiplexing
HTTP/2 interleavingHEADERS
Stream: 3
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 5
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 3
Flags: END_HEADERS
DATA
Stream: 5
Flags:
HEADERS
Stream: 5
Flags: END_HEADERS
DATA
Stream: 3
Flags: END_STREAM
DATA
Stream: 5
Flags: END_STREAM
HTTP/2 canceling a Stream
HEADERS
Stream: 3
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 5
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 3
Flags: END_HEADERS
DATA
Stream: 5
Flags:
HEADERS
Stream: 5
Flags: END_HEADERS
DATA
Stream: 3
Flags: END_STREAM
RST_STREAM
Stream: 5
ErrorCode: CANCEL
HTTP/2 control framesHEADERS
Stream: 3
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 5
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 3
Flags: END_HEADERS
DATA
Stream: 5
Flags:
HEADERS
Stream: 5
Flags: END_HEADERS
DATA
Stream: 3
Flags: END_STREAM
DATA
Stream: 5
Flags: END_STREAM
SETTINGS
Stream: 0
Flags:
SETTINGS
Stream: 0
Flags: ACK
Multiplexing
Priority
Flow control
Header
compression
Server push
HTTP/2.0 HEADLINE FEATURE
Stream Prioritization
Before any application data can be sent, a new stream must be created and the
appropriate metadata such as HTTP headers must be sent.
In addition to the common header, an optional 31-bit stream priority has been
added.
STREAM IDENTIFIER (31)
FRAME PAYLOADS (0..N)
LENGTH (24)
R
TYPE (8) FLAGS (8)
PRIORITY (31)R
HTTP/2 priorityHEADERS
Stream: 3
Flags: END_HEADERS, END_STREAM
HEADERS
Stream: 5
Flags: END_HEADERS, END_STREAM
Priority: 0 HEADERS
Stream: 3
Flags: END_HEADERS
DATA
Stream: 5
Flags:
HEADERS
Stream: 5
Flags: END_HEADERS
DATA
Stream: 5
Flags: END_STREAM
DATA
Stream: 3
Flags: END_STREAM
Priority: stream is
more (lower number)
or less (higher
number) important
data might be sent earlier
Priority Stream
STREAM IDENTIFIER (31)
LENGTH (24)
R
TYPE (8) FLAGS (8)
STREAM DEPENDENCY (31)E
WEIGHT (8)
Stream Prioritization
*
A
12
B
4
*
A
12
B
4
D
8
*
A
12
B
4
*
A
12
B
4
D
8
С
8
Multiplexing
Priority
Flow control
Header
compression
Server push
HTTP/2.0 HEADLINE FEATURE
HTTP/2 flow control
HTTP/2.0 HEADLINE FEATURE
Multiplexing
Priority
Flow control
Header
compression
Server push
HTTP 1.1 headers
HTTP/2 header compression
Header compression
Header compression
HTTP/2.0 HEADLINE FEATURE
Multiplexing
Priority
Flow control
Header
compression
Server push
HTTP/2 push promise
Comparison of time to fetch HTTP resources
Typical Journey
setPath(“/style.css”)
push( )
setPath(“/jquery.js”)
push( )
style.css
jquery.js
GET /index.html
index.html
browser servlet
PushBuilder
request.newPushBuilder( )
When you don’t know if it supports HTTP/2
GET / HTTP/1.1
Host: server.example.com
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS
payload>
● “h2c” means no TLS connection
● “h2” means TLS connection [TLS-
ALPN]
● A server MUST NOT upgrade the connection to
HTTP/2 if this header field is not present or if more
than one is present.
● A server MUST NOT send this header field.
[ Response ]
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: h2c
Implicit acknowledgement of HTTP2-
Settings
Configure Tomcat 9 for HTTP/2
Open the conf/server.xml file and make the following
configuration changes.
<Connector port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https"
secure="true"
sslImplementationName="org.apache.tomcat.util.net.jsse.JSSEImp
lementation"
keystoreFile=“/conf/tomcat-sslkey" keystorePass=“*******"
clientAuth="false" sslProtocol="TLS">
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol“
initialWindowSize=“65535”
keepAliveTimeout=“-1”
Servlet 4.0 dependency
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
41 req
172 kb
66 req
215 kb
130
req
427 kb
230
req
2.0 mb
330
req
4.2 mb
430
req
5.4 mb
HTTP/2 332.37 415.33 774.13 1.26 1.83 2.31
HTTP
1.1
545.67 629.30 877.77 1.40 1.94 2.46
Diff % 64.18 51.52 13.39 11.61 5.73 6.52
Push Builder from HTTP Request
HttpServletRequest
• getPushBuilder( ):
PushBuilder
• …( )
I
PushBuilder
• addHeader(String, String): PushBuilder
• etag(String): PushBuilder
• lastModified(String): PushBuilder
• queryString(String): PushBuilder
• sessionId(String): PushBuilder
• path(String): PushBuilder
• push( )
• …( )
I
fun getHttpSample(req: HttpServletRequest, resp: HttpServletRes
req.newPushBuilder()?.path("/res/css/style.css")?.push()
req.newPushBuilder()?.path("/res/js/common.js")?.push()
req.newPushBuilder()?.path("/res/images/background.jpg")?.p
Push Builder from HTTP Request
fun pushSample(req: HttpServletRequest, resp: HttpServl
val pushBuilder = req.newPushBuilder()
pushBuilder?.apply {
for (i in 1..250) {
pushBuilder
.path("res/images/space/space_$i.j
.addHeader("content-type", "image/
.push()
}
}
Filter and Server Push feature
@WebFilter(urlPatterns = ["/*"])
class PushFilter : Filter {
override fun doFilter(req: ServletRequest, resp: ServletResponse,
chain: FilterChain) {
val httpRequest: HttpServletRequest = req as HttpServletRequest
val requestURI = httpRequest.requestURI
val pushBuilder = httpRequest?.newPushBuilder()
when (requestURI) {
"index.html" -> {
pushBuilder?.path("/style.css")?.push()
pushBuilder?.path("/logo.png")?.push()
}
else -> pushBuilder?.path("/nature.png")?.push()
}
chain.doFilter(req, resp)
}
}
What about HTTP/2 client?
Client for HTTP/2 has been introduced in Java 9:
jdk.incubator.httpclient
Creating HTTP/2 client
val client: HttpClient = HttpClient.newHttpClient()
val client: HttpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.build()
HTTP/2 client – GET request
val request: HttpRequest = HttpRequest.newBuilder()
.uri(URI("http:/google.com.ua"))
.GET()
.header(“page”, “1”)
.header (“limit”, “20”)
.build()
HTTP/2 client – GET request
val response: HttpResponse<String> =
client.send (request, HttpResponse.BodyHandler.asString ( ))
val response: CompletableFuture<HttpResponse<String>> =
client.sendAsync (request,
HttpResponse.BodyHandler.asString())
Conclusion: what we get with HTTP/2
• 1 socket for 100+ concurrent streams.
• Advanced features like:
- flow control
- cancellation
- cache push.
• Dramatically less header overhead.
THANK YOU!

Contenu connexe

Tendances

Tendances (20)

HTTP2 & HPACK #pyfes 2013-11-30
HTTP2 & HPACK #pyfes 2013-11-30HTTP2 & HPACK #pyfes 2013-11-30
HTTP2 & HPACK #pyfes 2013-11-30
 
Introduction to HTTP/2
Introduction to HTTP/2Introduction to HTTP/2
Introduction to HTTP/2
 
Introducing HTTP/2
Introducing HTTP/2Introducing HTTP/2
Introducing HTTP/2
 
Altitude San Francisco 2018: Programming the Edge
Altitude San Francisco 2018: Programming the EdgeAltitude San Francisco 2018: Programming the Edge
Altitude San Francisco 2018: Programming the Edge
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
 
Introduction to HTTP/2
Introduction to HTTP/2Introduction to HTTP/2
Introduction to HTTP/2
 
Altitude San Francisco 2018: Testing with Fastly Workshop
Altitude San Francisco 2018: Testing with Fastly WorkshopAltitude San Francisco 2018: Testing with Fastly Workshop
Altitude San Francisco 2018: Testing with Fastly Workshop
 
HTTP/2 Update - FOSDEM 2016
HTTP/2 Update - FOSDEM 2016HTTP/2 Update - FOSDEM 2016
HTTP/2 Update - FOSDEM 2016
 
HTTP/2 standard for video streaming
HTTP/2 standard for video streamingHTTP/2 standard for video streaming
HTTP/2 standard for video streaming
 
HTTP2 is Here!
HTTP2 is Here!HTTP2 is Here!
HTTP2 is Here!
 
Http2
Http2Http2
Http2
 
Http2 right now
Http2 right nowHttp2 right now
Http2 right now
 
Performance #4 network
Performance #4  networkPerformance #4  network
Performance #4 network
 
SPDY - http reloaded - WebTechConference 2012
SPDY - http reloaded - WebTechConference 2012SPDY - http reloaded - WebTechConference 2012
SPDY - http reloaded - WebTechConference 2012
 
Covert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache HeadersCovert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache Headers
 
Introduction to Haproxy
Introduction to HaproxyIntroduction to Haproxy
Introduction to Haproxy
 
HTTP 2.0 Why, How and When
HTTP 2.0 Why, How and WhenHTTP 2.0 Why, How and When
HTTP 2.0 Why, How and When
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2
 
Covert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache HeadersCovert Timing Channels using HTTP Cache Headers
Covert Timing Channels using HTTP Cache Headers
 

Similaire à Http2 kotlin

Interactive web. O rly?
Interactive web. O rly?Interactive web. O rly?
Interactive web. O rly?
timbc
 

Similaire à Http2 kotlin (20)

Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.Enabling Googley microservices with HTTP/2 and gRPC.
Enabling Googley microservices with HTTP/2 and gRPC.
 
HTTP
HTTPHTTP
HTTP
 
SPDY & HTTP2.0 & QUIC - #bpstudy 2013-08-28
SPDY & HTTP2.0 & QUIC - #bpstudy 2013-08-28SPDY & HTTP2.0 & QUIC - #bpstudy 2013-08-28
SPDY & HTTP2.0 & QUIC - #bpstudy 2013-08-28
 
Проксирование HTTP-запросов web-акселератором / Александр Крижановский (Tempe...
Проксирование HTTP-запросов web-акселератором / Александр Крижановский (Tempe...Проксирование HTTP-запросов web-акселератором / Александр Крижановский (Tempe...
Проксирование HTTP-запросов web-акселератором / Александр Крижановский (Tempe...
 
Implementing Early Hints in Chrome - Approaches and Challenges
Implementing Early Hints in Chrome - Approaches and ChallengesImplementing Early Hints in Chrome - Approaches and Challenges
Implementing Early Hints in Chrome - Approaches and Challenges
 
Http methods
Http methodsHttp methods
Http methods
 
Http/2
Http/2Http/2
Http/2
 
Introduction to HTTP/2
Introduction to HTTP/2Introduction to HTTP/2
Introduction to HTTP/2
 
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to youJava EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
 
HTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 era
HTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 eraHTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 era
HTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 era
 
HTTP/2 - Differences and Performance Improvements with HTTP
HTTP/2 - Differences and Performance Improvements with HTTPHTTP/2 - Differences and Performance Improvements with HTTP
HTTP/2 - Differences and Performance Improvements with HTTP
 
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
 
Java EE 8: What Servlet 4 and HTTP2 Mean
Java EE 8: What Servlet 4 and HTTP2 MeanJava EE 8: What Servlet 4 and HTTP2 Mean
Java EE 8: What Servlet 4 and HTTP2 Mean
 
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
 
HTTP
HTTPHTTP
HTTP
 
Interactive web. O rly?
Interactive web. O rly?Interactive web. O rly?
Interactive web. O rly?
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the Web
 
Taking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocketTaking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocket
 
Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET Works
 
Introduction to HTTP2
Introduction to HTTP2Introduction to HTTP2
Introduction to HTTP2
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Http2 kotlin

  • 2. HOW WE GOT HERE
  • 3. Total Transfer Size & Total Requests
  • 6. 22.3% of all Web sites support the HTTP/2 protocol SUPPORT OF HTTP/2
  • 7. SUPPORT OF HTTP/2 IIS: Windows Server 2016 Apache 2.4.17 nginx 1.9.5 Apache Tomcat 9.0.0 WildFly 10 Jetty Stable-9 Netty 4.1 Payara 5.0 Vert.x GlassFish 5.0
  • 8. Problem of HTTP/1.1 Responds in sequence Head-of-Line blocking One request per TCP connection HTTP header fields are often repetitive and verbose
  • 10.
  • 12. How developers resolves problems of HTTP 1.1 • Creating sprites • Inlining • Joining • Sharing
  • 13.
  • 15.
  • 16. How HTTP/2.0 resolves problems • Request/Response multiplexing • Stream Prioritization and Dependency • Server Push • Header compression
  • 17. HTTP/2 Units CONNECTION STREAM FRAME FRAME FRAME FRAME • Connection – single TCP connection • Streams - channel that carries messages in two directions • Messages - request or response • Frames – messages, which are broken down for
  • 18. Binary Framing STREAM IDENTIFIER (31) FRAME PAYLOADS (0..N) LENGTH (24) R TYPE (8) FLAGS (8)
  • 19. Type of Frames in HTTP/2.0 DATA Used to transport HTTP message bodies HEADERS Used to communicate header fields for a stream PRIORITY Used to communicate sender-advised priority of a stream RST_STREAM Used to signal termination of a stream SETTINGS Used to communicate configuration parameters for the connection
  • 20. PUSH_PROMISE Used to signal a promise to serve the referenced resource PING Used to measure the roundtrip time and perform "liveness" checks GOAWAY Used to inform the peer to stop creating streams for current connection WINDOW_UPDATE Used to implement flow stream and connection flow control CONTINUATION Type of Frames in HTTP/2.0
  • 21. HTTP 1.1 round-trip Host: maven.apache.org SecurityToken: j13c72208c9u5fa2 Accept: application/json Accept-Encoding: gzip GET /install.html HTTP/1.1 Content-Length: 327 Cache-Control: private, max-age=60, s- maxage=0 Vary: SecurityToken Date: Wed, 17 Jan 2018 21:31:57 GMT Content-Type: application/json Content-Encoding: gzip GET /install HTTP/1.1 GZIPPED DATA
  • 22. HTTP/2 round-trip :method: GET :authority: maven.apache.org :path: /install.html securitytoken: j13c72208c9u5fa2 accept: application/json accept-Encoding: gzip HEADERS Stream: 3 Flags: END_HEADERS, END_STREAM :status: 200 content-Length: 327 cache-Control: private, max-age=60, s- maxage=0 vary: SecurityToken date: Wed, 17 Jan 2018 21:31:57 GMT content-Type: application/json content-Encoding: gzip HEADERS Stream: 3 Flags: END_HEADERS GZIPPED DATA DATA Stream: 3 Flags: END_STREAM
  • 23. Comparison requests of HTTP 1.1 & HTTP/2 :method: GET :authority: maven.apache.org :path: /install.html securitytoken: j13c72208c9u5fa2 accept: application/json accept-Encoding: gzip HEADERS Stream: 3 Flags: END_HEADERS, END_STREAM Host: maven.apache.org SecurityToken: j13c72208c9u5fa2 Accept: application/json Accept-Encoding: gzip GET /install.html HTTP/1.1
  • 24. Comparison responses of HTTP 1.1 & HTTP/2 :status: 200 content-Length: 327 cache-Control: private, max-age=60, s- maxage=0 vary: SecurityToken date: Wed, 17 Jan 2018 21:31:57 GMT content-Type: application/json content-Encoding: gzip HEADERS Stream: 3 Flags: END_HEADERS GZIPPED DATA DATA Stream: 3 Flags: END_STREAM Content-Length: 327 Cache-Control: private, max-age=60, s-maxage=0 Vary: SecurityToken Date: Wed, 17 Jan 2018 21:31:57 GMT Content-Type: application/json Content-Encoding: gzip GET /install HTTP/1.1 GZIPPED DATA
  • 25. HTTP/2.0 HEADLINE FEATURE Multiplexing Priority Flow control Header compression Server push
  • 28. MaximumconcurrentopenTCPconnections Browser Parallel connections per hostname Chrome 6 Firefox 6 Opera 6 Safari 6 Internet Explorer 11 13 Microsoft Edge 13
  • 30. HTTP/2 interleavingHEADERS Stream: 3 Flags: END_HEADERS, END_STREAM HEADERS Stream: 5 Flags: END_HEADERS, END_STREAM HEADERS Stream: 3 Flags: END_HEADERS DATA Stream: 5 Flags: HEADERS Stream: 5 Flags: END_HEADERS DATA Stream: 3 Flags: END_STREAM DATA Stream: 5 Flags: END_STREAM
  • 31. HTTP/2 canceling a Stream HEADERS Stream: 3 Flags: END_HEADERS, END_STREAM HEADERS Stream: 5 Flags: END_HEADERS, END_STREAM HEADERS Stream: 3 Flags: END_HEADERS DATA Stream: 5 Flags: HEADERS Stream: 5 Flags: END_HEADERS DATA Stream: 3 Flags: END_STREAM RST_STREAM Stream: 5 ErrorCode: CANCEL
  • 32. HTTP/2 control framesHEADERS Stream: 3 Flags: END_HEADERS, END_STREAM HEADERS Stream: 5 Flags: END_HEADERS, END_STREAM HEADERS Stream: 3 Flags: END_HEADERS DATA Stream: 5 Flags: HEADERS Stream: 5 Flags: END_HEADERS DATA Stream: 3 Flags: END_STREAM DATA Stream: 5 Flags: END_STREAM SETTINGS Stream: 0 Flags: SETTINGS Stream: 0 Flags: ACK
  • 33.
  • 35. Stream Prioritization Before any application data can be sent, a new stream must be created and the appropriate metadata such as HTTP headers must be sent. In addition to the common header, an optional 31-bit stream priority has been added. STREAM IDENTIFIER (31) FRAME PAYLOADS (0..N) LENGTH (24) R TYPE (8) FLAGS (8) PRIORITY (31)R
  • 36. HTTP/2 priorityHEADERS Stream: 3 Flags: END_HEADERS, END_STREAM HEADERS Stream: 5 Flags: END_HEADERS, END_STREAM Priority: 0 HEADERS Stream: 3 Flags: END_HEADERS DATA Stream: 5 Flags: HEADERS Stream: 5 Flags: END_HEADERS DATA Stream: 5 Flags: END_STREAM DATA Stream: 3 Flags: END_STREAM Priority: stream is more (lower number) or less (higher number) important data might be sent earlier
  • 37. Priority Stream STREAM IDENTIFIER (31) LENGTH (24) R TYPE (8) FLAGS (8) STREAM DEPENDENCY (31)E WEIGHT (8)
  • 41. HTTP/2.0 HEADLINE FEATURE Multiplexing Priority Flow control Header compression Server push
  • 46. HTTP/2.0 HEADLINE FEATURE Multiplexing Priority Flow control Header compression Server push
  • 48. Comparison of time to fetch HTTP resources
  • 49. Typical Journey setPath(“/style.css”) push( ) setPath(“/jquery.js”) push( ) style.css jquery.js GET /index.html index.html browser servlet PushBuilder request.newPushBuilder( )
  • 50. When you don’t know if it supports HTTP/2 GET / HTTP/1.1 Host: server.example.com Connection: Upgrade, HTTP2-Settings Upgrade: h2c HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload> ● “h2c” means no TLS connection ● “h2” means TLS connection [TLS- ALPN] ● A server MUST NOT upgrade the connection to HTTP/2 if this header field is not present or if more than one is present. ● A server MUST NOT send this header field. [ Response ] HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade: h2c Implicit acknowledgement of HTTP2- Settings
  • 51.
  • 52. Configure Tomcat 9 for HTTP/2 Open the conf/server.xml file and make the following configuration changes. <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" sslImplementationName="org.apache.tomcat.util.net.jsse.JSSEImp lementation" keystoreFile=“/conf/tomcat-sslkey" keystorePass=“*******" clientAuth="false" sslProtocol="TLS"> <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol“ initialWindowSize=“65535” keepAliveTimeout=“-1”
  • 54. 41 req 172 kb 66 req 215 kb 130 req 427 kb 230 req 2.0 mb 330 req 4.2 mb 430 req 5.4 mb HTTP/2 332.37 415.33 774.13 1.26 1.83 2.31 HTTP 1.1 545.67 629.30 877.77 1.40 1.94 2.46 Diff % 64.18 51.52 13.39 11.61 5.73 6.52
  • 55. Push Builder from HTTP Request HttpServletRequest • getPushBuilder( ): PushBuilder • …( ) I PushBuilder • addHeader(String, String): PushBuilder • etag(String): PushBuilder • lastModified(String): PushBuilder • queryString(String): PushBuilder • sessionId(String): PushBuilder • path(String): PushBuilder • push( ) • …( ) I
  • 56. fun getHttpSample(req: HttpServletRequest, resp: HttpServletRes req.newPushBuilder()?.path("/res/css/style.css")?.push() req.newPushBuilder()?.path("/res/js/common.js")?.push() req.newPushBuilder()?.path("/res/images/background.jpg")?.p
  • 57. Push Builder from HTTP Request fun pushSample(req: HttpServletRequest, resp: HttpServl val pushBuilder = req.newPushBuilder() pushBuilder?.apply { for (i in 1..250) { pushBuilder .path("res/images/space/space_$i.j .addHeader("content-type", "image/ .push() } }
  • 58. Filter and Server Push feature @WebFilter(urlPatterns = ["/*"]) class PushFilter : Filter { override fun doFilter(req: ServletRequest, resp: ServletResponse, chain: FilterChain) { val httpRequest: HttpServletRequest = req as HttpServletRequest val requestURI = httpRequest.requestURI val pushBuilder = httpRequest?.newPushBuilder() when (requestURI) { "index.html" -> { pushBuilder?.path("/style.css")?.push() pushBuilder?.path("/logo.png")?.push() } else -> pushBuilder?.path("/nature.png")?.push() } chain.doFilter(req, resp) } }
  • 59. What about HTTP/2 client? Client for HTTP/2 has been introduced in Java 9: jdk.incubator.httpclient
  • 60. Creating HTTP/2 client val client: HttpClient = HttpClient.newHttpClient() val client: HttpClient = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_2) .build()
  • 61. HTTP/2 client – GET request val request: HttpRequest = HttpRequest.newBuilder() .uri(URI("http:/google.com.ua")) .GET() .header(“page”, “1”) .header (“limit”, “20”) .build()
  • 62. HTTP/2 client – GET request val response: HttpResponse<String> = client.send (request, HttpResponse.BodyHandler.asString ( )) val response: CompletableFuture<HttpResponse<String>> = client.sendAsync (request, HttpResponse.BodyHandler.asString())
  • 63. Conclusion: what we get with HTTP/2 • 1 socket for 100+ concurrent streams. • Advanced features like: - flow control - cancellation - cache push. • Dramatically less header overhead.