Better performances with HTTP/2and Eclipse Vert.xThomas Segismont, Senior Software Engineer, Red Hat
Agenda
• Improving web performance with HTTP/2
• Scalable service architectures with HTTP/2
Who am I?
• tsegismont @ GitHub / Twitter / Gmail / Freenode
• Vert.x core team since August 2016
• At Red Hat since November 2012 (RHQ and Hawkular)
IMPROVING WEB PERFORMANCE WITH
HTTP/2
Latency matters more!
100015502100265032003750
10001750250032504000
HTTP/1 Optimization techniques
• Persistent connections
• Multiple connections
• Domain sharding
• CDN
• Browser caching
• Compression / minification
• Concatenation
Still a bottleneck!
GET
OK
GET
OK
HTTP/2
• A better TCP transport for actual HTTP request and responses
• Same HTTP semantics
• RFC7540 : Hypertext Protocol version 2
• RFC7541 : Header Compression for HTTP/2
HTTP/2
• H2– TLS/SSL
– Mandatory for browsers
– ALPN extension to negotiate HTTP/1 or HTTP/2
• H2C– Clear text
– Via HTTP/1 upgrade or directly
Framed protocol
• Defines a set of frames encoded in binary on a single connection
– Settings
– Headers
– Data
– Flow control
– Push, Priority, Ping
– Reset
Settings frames
• First frame exchanged by client and server– Max concurrency
– Max frame size
– … etc
GET /index.html HTTP/1.1\r\nHost: www.free.fr\r\nUser-Agent: Mozilla/5.0\r\nAccept-Encoding: text/html\r\nAccept-Language: en-US\r\n\r\n
000035012500000003000000000f824488355217caf3a69a3f874189f1e3c2f2d852af2d9f7a88d07f66a281b0dae05087497ca589d34d1f51842d4b70dd
Request headers
2x smaller
length type flags stream_id
Subsequent request headers
4x smaller
GET /products.html HTTP/1.1\r\nHost: www.free.fr\r\nUser-Agent: Mozilla/5.0\r\nAccept-Encoding: text/html\r\nAccept-Language: en-US\r\n\r\n
000017012500000005000000000f82448aaec3c9691285e74d347f87c2c1c0bf
Response headers + data
HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nCache-Control: max-age=86400\r\nContent-Length: 37\r\n\r\n<html><body>Hello World</body></html>
00001f012400000003000000000f885f87497ca589d34d1f588aa47e561cc581e71a003f5c023337
0000250001000000033c68746d6c3e3c626f64793e48656c6c6f20576f726c643c2f626f64793e3c2f68746d6c3e
length type flags stream_id
DEMO
SCALABLE SERVICES WITH HTTP/2
Target architectures
serviceservice
serviceservice
gatewaygateway
backendbackend
serviceservicebackendbackend
Constraints
• 1ms ping
• 1G < bandwidth < 10G
• 1ms < service time < 200ms
• 200b < body size < 2kb
HTTP/1.1 vs HTTP/2
serverserver
HTTP/1vs
HTTP/2
backendbackendclientclient20 msthinktime
0 100 200 300 400 500 600 700 8000
200
400
600
800
HTTP/1 - 8 connections
planned (req / sec)
per
form
ed (
req/
sec)
HTTP/1.1 Head Of Line Blocking
Client Server
} 20ms
Backend
GET
}
0 100 200 300 400 500 600 700 800 900 1000 1100 12000
300
600
900
1200
HTTP/1 - 8 connectionsHTTP/2 - 1 connection / max_concurrent_streams 20
planned (req / sec)
perf
orm
ed (
req
/ sec
)
HTTP/2.0 Multiplexing
Client Server
} 20ms
Backend
request
}}
Thread pool concurrency
0 1000 2000 3000 4000 50000
1250
2500
3750
5000
HTTP/2 thread pool
planned (req / sec)
perf
orm
ed (
req
/ sec
)
Eclipse Vert.x is a toolkit for building reactive and polyglot
applications for the JVM
Vert.x
• Latest and greatest Vert.x 3.4.1– Scala and Kotlin support
– RxJava improvements
– MQTT server
– Kafka client
– gRPC support
– Web client
– Infinispan cluster manager
– … and much more!
Toolkit
• Embeddable
• Composable
• Modular
• Minimum dependencies
• Classloading / Injection free
Polyglot
Reactive
• Non blocking
• Event driven
• Distributed
• Rxified APIs
• Reactive-streams
HTTP/2 with Vert.x
• Client / Server
• h2 / h2c
• HTTP Request / response API
• HTTP/2 specific features for extensions
DEMO
Event Driven
• NIO selectors
• Disk operations
• Timers
• Messages
• Database
• … etc
Reactor pattern with Event Loop
Singlethread
Event loop benefits
• Easier to scale
• Mechanical sympathetic
• Simple concurrency model
Event loop concurrency
0 1000 2000 3000 4000 50000
1250
2500
3750
5000
HTTP/2 thread pool HTTP/2 non blocking
planned (req / sec)
perf
orm
ed (
req
/ sec
)
Multi-reactor pattern
Conclusion
• Unleash concurrency with HTTP/2
• Keep the good old HTTP/1 semantics
• Non blocking is a key factor for high concurrency
• Vert.x is a great fit for HTTP/2– Reactive ecosystem
– Easy to scale
Thank you
Links
• http://vertx.io
• https://github.com/vietj/http2-bench
• http://www.belshe.com/2010/05/24/more-bandwidth-doesnt-matter-much/
• https://www.infoq.com/presentations/latency-pitfalls
• https://hpbn.co
Top Related