SlideShare a Scribd company logo
IN A HTTP/2 WORLD
DOUGLAS VAZ, EQUAL EXPERTS
DECCAN RUBYCONF 2017
1. CURRENT STATE
2. PROBLEMS WITH HTTP/1.x
3. HTTP/2 (H2) FEATURES
4. RETHINKING CURRENT PRACTICES
5. ADOPTION, AND THE STATE OF RUBY
HTTP - A brief history
1997 - RFC 2068 (HTTP/1.1 first draft)
1999 - RFC 2616 (standard for HTTP/1.1)
2014 - RFC 7230 (6 part spec to revise HTTP/1.1)
1989 - 1996 - HTTP/1.0
1. Current State
However…
1. Current State
SYN
SYN/ACK
ACK
Client Server
Request HTML
Response
Request CSS, JS, img *
assets
TCP
Handshake
1. Current State
1. Current State
Problem 1: HTTP/1.x only allowed sequential request/response
HTTP/1.x wasn’t designed for async requests.
Pipelining allowed async requests but responses need to be consumed in order. Slow
responses would block all later requests and reduce overall performance i.e. head-of-
line blocking
2. Problems with HTTP/1.x
Workaround:
Browsers disabled pipelining and used multiple connections
2. Problems with HTTP/1.x
Since only one requestconnection serviced at a given time, increasing bandwidth
doesn’t reduce latency.
Browsers open multiple connections for parallel requests, but are restricted to a
max number per domain
Problem 2: More bandwidth doesn’t mean lower latency
http://httparchive.org/
2. Problems with HTTP/1.x
Workaround:
Domain sharding and asset concatenation to
increase parallelism and reduce RTT
2. Problems with HTTP/1.x
SYN
SYN/ACK
ACK
Client
Server
Request HTML
Response
Request CSS, JS, img *
assets
TCP
Handshake
Processing
time
Problem 3: Transfers are blocked while the server
processes requests
2. Problems with HTTP/1.x
Workaround:
tely with an intermediate state and serve content when ready via
2. Problems with HTTP/1.x
ession data stored in cookies are transferred as uncompressed headers and can add several kilo
Problem 4: Protocol overhead due to headers
2. Problems with HTTP/1.x
Workaround:
Most servers impose a limit on header size
2. Problems with HTTP/1.x
HTTP/2RFC 7540, May 2015
3. H2 Features
3. H2 Features
H2 Key Features
• Parallel request streams on a single connection
• Binary protocol
• Server push
• Header compression
• Stream prioritisation
3. H2 Features
Binary Framing
Credits: Ilya Grigorik
Frame Multiplexing
3. H2 Features
Parallel requests with HTTP/1.1
- Open multiple connections (ex. 6 in Chrome)
- High request queue time
3. H2 Features
Parallel requests with HTTP/2
“Designed to reduce perceived latency”
- Request multiple files in parallel on same connection
- All requests are served immediately
Based on Go’s HTTP/2 Demo
3. H2 Features
Credits: Ilya Grigorik
HPACK
Header Compression
3. H2 Features
HPACK compression performance
3. H2 Features
Current Practices
Keep doing or stop?
4. Rethinking Practices
Domain Sharding
https://www.keycdn.com/support/domain-sharding/
Don’t do this with HTTP/2
4. Rethinking Practices
Asset Concatenation
http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/webpack.html
Not necessary anymore*
4. Rethinking Practices
HTTP/2
Implementations
How do I use it?
5. Adoption, Implementation, Ruby
Browser Support
5. Adoption, Implementation, Ruby
Server Support
5. Adoption, Implementation, Ruby
Available Tools
5. Adoption, Implementation, Ruby
• Chrome Dev Tools (inspect sessions and streams)
• Wireshark (inspect frames and compressed headers)
• nghttp2 (C library plus helpful binaries)
• curl (needs to be build from source)
What about Ruby?
+
HTTP/2
=
:`(
5. Adoption, Implementation, Ruby
Rack is not HTTP/2 compatible!
• Rack is designed for request/response cycles
• Communication with backend servers is not bi-directional
or message oriented
5. Adoption, Implementation, Ruby
Option 1: igrigorik/http-2
gem install http-2
Limitations:
1. Not Rack compatible, hence can’t be used with Rails
2. Does not negotiate a fallback to HTTP/1.x
Pure Ruby implementation of HTTP/2
5. Adoption, Implementation, Ruby
Option 2: H2 Enabled Proxy + Ruby backend
Limitations:
1. Multiplexing won’t work
2. Server push requires additional configuration
Proxy client requests via H20, nghttpx, Apache or nginx
Enables header compression!
5. Adoption, Implementation, Ruby
Option 3: Server push via a CDN
Hinted push: Use Link headers in the response
Link: </css/styles.css>; rel=preload; as=style
5. Adoption, Implementation, Ruby
Option 4: Server push via an edge proxy
Manual server push by configuring the edge proxy
5. Adoption, Implementation, Ruby
Caveats
1. Server might push files that are already cached
2. Server might push files not present on page
3. Stream prioritisation and cancelling might be affected by OS level TCP buffers
5. Adoption, Implementation, Ruby
Thank you
Douglas Vaz
@Mistcrafter
References
• Risks of pipelining: https://www.chromium.org/developers/design-
documents/network-stack/http-pipelining
• Design and technical goals: https://hpbn.co/http2/#design-and-technical-goals
• Study on bandwidth vs latency:
https://docs.google.com/a/chromium.org/viewer?a=v&pid=sites&srcid=Y2hyb2
1pdW0ub3JnfGRldnxneDoxMzcyOWI1N2I4YzI3NzE2
• Starting point for HTTP/2: https://http2.github.io/
• HTTP/2 for Ruby: https://www.speedshop.co/2016/01/07/what-http2-means-
for-ruby-developers.html

More Related Content

PDF
HTTP/2 standard for video streaming
PDF
Introduction to HTTP2
PPTX
Introduction to HTTP/2
PPTX
Introducing HTTP/2
PPTX
HTTP/2 Introduction
PPTX
Introduction to HTTP/2
PPTX
PDF
What HTTP/2.0 Will Do For You
HTTP/2 standard for video streaming
Introduction to HTTP2
Introduction to HTTP/2
Introducing HTTP/2
HTTP/2 Introduction
Introduction to HTTP/2
What HTTP/2.0 Will Do For You

What's hot (20)

PDF
O'Reilly Fluent Conference: HTTP/1.1 vs. HTTP/2
PDF
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
PPTX
PDF
HTTP2 & HPACK #pyfes 2013-11-30
PDF
HTTP/2 Update - FOSDEM 2016
PDF
Better performances with HTTP/2
PPTX
HTTP/2 Changes Everything
PDF
SPDY and HTTP/2
PPTX
HTML5, HTTP2, and You 1.1
PPTX
HTTP/2 : why upgrading the web? - apidays Paris
PPTX
Http/2 lightning
PDF
Communicating on the web
PDF
PDF
Attacking http2 implementations (1)
PDF
Stuart Larsen, attacking http2implementations-rev1
PDF
HTTP2 is Here!
PDF
Http smuggling 1 200523064027
PPTX
HTTP Request Smuggling
PPT
Tomcat Server
PPTX
Smuggling TCP traffic through HTTP
O'Reilly Fluent Conference: HTTP/1.1 vs. HTTP/2
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP2 & HPACK #pyfes 2013-11-30
HTTP/2 Update - FOSDEM 2016
Better performances with HTTP/2
HTTP/2 Changes Everything
SPDY and HTTP/2
HTML5, HTTP2, and You 1.1
HTTP/2 : why upgrading the web? - apidays Paris
Http/2 lightning
Communicating on the web
Attacking http2 implementations (1)
Stuart Larsen, attacking http2implementations-rev1
HTTP2 is Here!
Http smuggling 1 200523064027
HTTP Request Smuggling
Tomcat Server
Smuggling TCP traffic through HTTP
Ad

Similar to In a HTTP/2 World - DeccanRubyConf 2017 (20)

PPTX
Recent Advances in HTTP, controlling them using ruby
PPTX
Http2 Security Perspective
PDF
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
PPTX
HTTP/2 - Differences and Performance Improvements with HTTP
PDF
HTTP/2 (2017)
PPTX
Next generation web protocols
KEY
What's up with HTTP?
PDF
HTTP/2: What's new?
PDF
Http Status Report
PPTX
HTTP/2 and web development practices
PPTX
PPTX
PPTX
Servlet 4.0 at GeekOut 2015
PPTX
HTTP Presentation(What exactly is http).pptx
PDF
Http2 right now
PDF
HTTP/2: A Better Web Experience
PDF
HTTP2:新的机遇与挑战
PDF
HTTP 2.0 – What do I need to know?
PDF
The Case for HTTP/2 - EpicFEL Sept 2015
Recent Advances in HTTP, controlling them using ruby
Http2 Security Perspective
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
HTTP/2 - Differences and Performance Improvements with HTTP
HTTP/2 (2017)
Next generation web protocols
What's up with HTTP?
HTTP/2: What's new?
Http Status Report
HTTP/2 and web development practices
Servlet 4.0 at GeekOut 2015
HTTP Presentation(What exactly is http).pptx
Http2 right now
HTTP/2: A Better Web Experience
HTTP2:新的机遇与挑战
HTTP 2.0 – What do I need to know?
The Case for HTTP/2 - EpicFEL Sept 2015
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The AUB Centre for AI in Media Proposal.docx
Per capita expenditure prediction using model stacking based on satellite ima...
MIND Revenue Release Quarter 2 2025 Press Release

In a HTTP/2 World - DeccanRubyConf 2017

Editor's Notes

  • #4: First used in 1989, along with other protocols such as Gopher. By 1995, HTTP had become the de fecto application layer protocol. This lead to standardisation by the Internet Engineering Task Force and HTTP/1.1 was published in ‘97 In 2014, HTTP/1.1 was further clarified with a 6 part draft (with regard to use of certain headers (Content-*, Referer, Location)
  • #5: While HTTP continued to remain the same, the internet was not the same playing field. The number and size of assets on a web page increased nearly exponentially. Almost a 10x increase from 2000 to 2016. It was clear that the protocol imposed restrictions that could no longer be dealt with at the application layer.
  • #6: How HTTP/1.x behaves. Starts with a 3 way TCP handshake to establish a connection. Browser requests an HTML page, parses it, and then requests for images, Javascript files, CSS files and other assets (one at a time over a connection)
  • #7: Typical HTTP/1.1 request and response format. Method, followed by path followed by protocol, followed by mandatory and optional headers. Response is similar. Starts with a status line, followed by a newline, headers and then data NOTE: TEXT BASED and human readable which makes it easy to construct by hand or debug
  • #8: HTTP/1.0 needed one connection per asset, HTTP/1.1 introduced keep-alive, but requests were synchronous. Also introduced pipelining which enabled sending multiple requests without waiting for a response, but responses needed to be consumed in order. If the first response is slow, all other later responses will be blocked. Badly implemented by proxies
  • #9: (The option to enable pipelining has been removed from Chrome, as there are known crashing bugs and known front-of-queue blocking issues. There are also a large number of servers and middleboxes that behave badly and inconsistently when pipelining is enabled. )
  • #10: Data bandwidth today is much greater than in early-2000s. Yet we couldn't take advantage of this because of the protocol limitations. Both transfer sizes and number of assets per page are growing (ex. CNN has 157 resources) Connection limit: could exhaust server and client limit
  • #11: Common practices to get around browser limits to make assets download faster, bundling assets together (JS, CSS, images) to avoid multiple round trips
  • #12: The network connection is blocked when the server is processing a request (browsers can’t request anymore on the connection, servers can’t switch to sending alternate files in the meantime)
  • #13: Return a static view, which can then fetch the remaining content when it’s ready (how most SPAs work)
  • #14: Since, HTTP is stateless, every request needs to convey the context. This is useful but can also be a huge overhead due to duplication of data on the wire However, the fact that all HTTP headers are transferred in plain text (without any compression), can lead to high overhead costs for each and every request, which can be a serious bottleneck for some applications and devices with limited resources. 
  • #15: RFC 2616 (HTTP 1.1) does not define any limit on the size of the HTTP headers. in practice, many servers and proxies will try to enforce either an 8 KB or a 16 KB limit.
  • #16: In May 2015, HTTP/2 became a standard. A lot of vendors who had already supported SPDY due to Google’s influence quickly migrated to this spec
  • #17: Metaphor for HTTP/2’s design. Instead of placing an order one item at a time, you simply request for the entire meal upfront. You can also specify priorities such as wanting wine before the appetiser.
  • #18: A single TCP connection can have several logical connections, each transporting it’s own data. This is done by splitting packets into typed, interleaved frames, each having a unique identifier to indicate which stream it belongs to. H2 is a binary protocol, so not human readable and harder to debug. But much more efficient for a machine to process (think IoT with resource constraints) Server push is a feature where the server can send out data without an explicit request. This also indicated that streams are bidirectional in nature Headers are now sent in a frame at the start of a stream and the context is maintained for all frames in that stream. Additionally, the headers are compressed with a new algorithm called HPACK Clients can assign a priority weight to streams to fetch the more important files first (ex. CSS before images and fonts). Server doesn’t have to comply or can decide a default priority for different request types
  • #19: HTTP connection with 3 active streams. The colours indicate grouping of frames into a stream. Open a connection with HEADERS frame, send data with DATA frame. Streams can also be cancelled using a RST_STREAM header. How much of a difference does this make?
  • #20: A demonstration first constructed by the Golang team: The logo is tiled, comprising of 256 image tags on a web page. On page load, the browser requests for all 256 images in parallel. However, only one asset can be downloaded per connection and Chrome opens up 6 connections. That’s only 6 x 2 kb (12kbps) of a 2 Mbps connection.
  • #21: In contrast let’s see how HTTP/2 performs. All 256 tiles served at once. Less that a second on a 2 Mbps connection
  • #22: Header compression to reduce duplication with every request. HPACK is based on Huffman encoding with both a static and dynamic table. Header-value pairs sorted in descending order of frequency. The most frequently occurring header-value pair was given the smallest bit value. Apart from this static table, a connection can also negotiate a dynamic table which is used for lookups specific to that connection
  • #23: When I tested this on popular H2 enabled websites, the results were very positive. google.com shows an amazing 87% reduction in header size, which translates to lower bandwidth requirements.
  • #24: So should we continue with our existing best practices now that HTTP/2 is around
  • #25: Domain sharding is a practice of distributing assets among a set of domains to increase the number of connections to download in parallel. This is no longer needed cause parallel downloads can now be done with a single connection. Domain sharding is expensive cause of the DNS lookup plus handshake for each connection.
  • #26: Not necessary as a web optimisation. Easier to maintain cache consistency cause of separation. Keep stable vendor libs + frequently changing business code can be separated so that every small change does not invalidate the cache. Some bundling might be a good idea easy maintainability
  • #29: Common web servers, application server, CDNs Akamai and Cloudflare
  • #30: Chrome allows filtering on all active HTTP/2 sessions. Useful for viewing stream data Wireshark, network protocol analyser, has some support like decoding HPACK (but decoding streams is not straightforward) nghttp client to connect to H2 servers with HTTP Upgrade ALPN nghttpx -multi-threaded reverse proxy for HTTP/2, SPDY and HTTP/1.1 (mruby support available) Popular command line tool for fetching data from a server. Most OS distributions aren’t compiled with H2 capabilities (run with -V and look for HTTP2 under features)
  • #31: Turns out that Ruby has VERY limited support for HTTP/2. One of the reasons is that almost all Ruby web frameworks depend on Rack at the CGI level to talk to the web server
  • #32: The problem is, Rack is not HTTP/2 compatible. The architecture makes assumptions and hence cannot easily accommodate the new message oriented, bi-directional stream communication. There are still ways to use HTTP/2 with Ruby
  • #33: (don’t use in production, but good POC)
  • #35: Preload is a web optimisation technique to indicate assets which need an early fetch. Usually used via the <link> HTML tag. Some servers look for the LINK header in the application’s response and sends a PUSH_PROMISE frame followed by a DATA frame with actual content. Server can reject the push promise with a RST_STREAM frame Note: Server can only hint additional resource belonging to same origin policy.
  • #36: Similar to the CDN option, this relies on a configurable external proxy server to handle HTTP/2 requests. Advantage: Assets can be served via a server push while request is forwarded to application server for processing
  • #37: Cache digests is a proposed implementation to use a Bloom filter to inform the server of cached files Usually when CDN config and rendered page are out of sync. Managed by better engineering practices Not usually a worry but good to keep in mind