VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
ย
Recent Advances in HTTP, controlling them using ruby
1. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Recent Advances in HTTP,
controlling them using ruby
DeNA Co., Ltd.
Kazuho Oku
2. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Who am I
๏ฎ lead developer of H2O HTTP/2 server
โ one of the most sophisticated HTTP/2 impl.
โ initial public release: 2014/10 (license: MITL)
โ used by Fastly, etc.
๏ฎ author of Cache-Digests Internet Draft
โ considered as an essential work for HTTP/2 push
๏ฎ works at DeNA Co., Ltd.
๏ฎ also developer of: Q4M, Starlet, pisojson, ...
2Recend Advances in HTTP2, controlling them using ruby
3. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Current State of HTTP
3Recend Advances in HTTP2, controlling them using ruby
4. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Why use HTTP/2?
๏ฎ latency has become the bottleneck of the Web
๏ฎ HTTP/2 to conceal latency by raising concurrency
โ 6 concurrent requests in HTTP/1
โ ~100 in HTTP/2
4Recend Advances in HTTP2, controlling them using ruby
5. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Current state of HTTP
๏ฎ HTTP/2 (RFC 7540) released on May 2015
1: https://github.com/HTTPWorkshop/workshop2016/blob/master/talks/http2-review-data.pdf
5Recend Advances in HTTP2, controlling them using ruby
45
28
37
41
18
31
0% 20% 40% 60% 80% 100%
2015/7
2016/7
# of transactions by Firefox1
HTTP HTTPS (H1) HTTPS (H2)
6. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Key features of HTTP/2
๏ฎ header compression (HPACK)
๏ฎ multiplexing & prioritization
๏ฎ push
6Recend Advances in HTTP2, controlling them using ruby
7. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Header compression
๏ฎ working well
๏ฎ according to Mozilla1:
โ median โ 90% reduction
โ 80th percentile โ 75% reduction
โ 90th โ 10% reduction
7Recend Advances in HTTP2, controlling them using ruby
8. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Multiplexing & prioritization
๏ฎ HTTP/2 multiplexes responses into one TCP conn.
โ client gives hint for prioritization
โ server uses the hint to schedule the responses
๏ฎ but some client-server pairs donโt do it right
8Recend Advances in HTTP2, controlling them using ruby
9. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Push
๏ฎ positive reports:
โ โ20-30% speedup on page render timeโ2
๏ฎ negative comments:
โ many unnecessary pushes (47% are reset2)
โ increased render time in anti-patterns3
โ โconsider preload instead of pushโ3
๏ฎ push from edge
โ how?
2: https://github.com/HTTPWorkshop/workshop2016/blob/master/talks/server-push.pdf
3: https://docs.google.com/document/d/1K0NykTXBbbbTlv60t5MyJvXjqKGsCVNYHyLEXIxYMv0/edit
9Recend Advances in HTTP2, controlling them using ruby
10. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Fixes?
10Recend Advances in HTTP2, controlling them using ruby
11. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Flow of an ideal HTTP transaction
๏ฎ respond to high-priority requests
immediately
๏ฎ send resources in right order
โ first send CSS/JS
โ then send the HTML
โ then send the images
๏ฎ push only the resources not cached
by the client
11Recend Advances in HTTP2, controlling them using ruby
client server
1RTT
12. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
The reality
๏ฎ respond to high-priority requests
immediately
โ blocked by unsent data in TCP
๏ฎ send resources in right order
โ some browsers donโt specify
priority, some servers fail to
respect priority
โ issues caused by hidden resources
๏ฎ push only the resources not cached
by the client
โ how?
12Recend Advances in HTTP2, controlling them using ruby
client server
1RTT
13. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
TCP head-of-line blocking
๏ฎ head-of-line (HoL) blocking:
โ high-priority data blocked by preceding data in
flight
๏ฎ TCP HoL blocking:
โ data in TCP send buffer blocks following data of
higher priority
13Recend Advances in HTTP2, controlling them using ruby
14. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
TCP head-of-line blocking
14Recend Advances in HTTP2, controlling them using ruby
๏ฎ typical H2 server writes much more than that can be
sent immediately
โ unsent data in TCP send buffer (and TLS buffer)
HOL-blocks following data
TCP send buffer
CWND
unacked poll threshold
TLS buf.
TLS Records
sent immediately not immediately sent
HTTP/2 frames
15. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
TCP head-of-line blocking: the solution
๏ฎ write only what can be sent immediately
โ obtain CWND and unacked size using TCP_INFO
๏ฎ adjust poll threshold to delay write notification until
TCP becomes ready to send some data immediately
15Recend Advances in HTTP2, controlling them using ruby
CWND
unacked poll threshold
TLS Records
sent immediately not immediately sent
HTTP/2 frames
TCP send buffer
16. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
TCP head-of-line blocking: benchmark 1
16Recend Advances in HTTP2, controlling them using ruby
๏ฎ conditions:
โ server in Ireland, client in Tokyo (RTT 250ms)
โ load tiny js at the top of a large HTML
๏ฎ result: delay decreased from 511ms to 250ms
โ i.e. JS fetch latency was 2RTT, became 1 RTT
โข similar results in other environments
17. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
TCP head-of-line blocking: benchmark 2
๏ฎ using same data as previous
๏ฎ server: Sakura VPS (Ishikari DC)
17Recend Advances in HTTP2, controlling them using ruby
0
50
100
150
200
250
300
HTML JS
milliseconds
downloading HTML (and JS within)
RTT ~25ms
master latopt
18. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
HTTP/2 prioritization
18Recend Advances in HTTP2, controlling them using ruby
Root
Leader G
Follower G
weight: 1
HTML
weight: 32
Image
weight: 22
Image
weight: 22
Image
weight: 22
CSS
weight: 32
CSS
weight: 32
๏ฎ hybrid approach using weights and chaining
โ servers are expected to obey to the priority
specified by the clients
๏ฎ Firefoxโs prioritization graph is shown below
JS
weight: 32
JS
weight: 32
19. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
HTTP/2 prioritization
๏ฎ some web browsers fail to specify priority
โ Safari, Blink
โ older versions of Chrome also had issues
โ server-side countermeasures required
19Recend Advances in HTTP2, controlling them using ruby
Root
HTML
weight: 16
CSS
weight: 16
JS
weight: 16
Image
weight: 16
Image
weight: 16
Image
weight: 16
20. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
HTTP/2 prioritization: the solution
๏ฎ bandwidth distribution on server-side:
โ use Weighted Fair Queuing (WFQ) or Deficit
Round Robin (DRR)
โ some servers do it right:
โข nghttp2 (and Apache) implements WFQ in O(log N)
โข H2O approximates WFQ in O(1)
๏ฎ detect dumb clients and fallback to server-driven
prioritization
โ H2O reprioritizes CSS, JS for clients that do not
use priority chains
20Recend Advances in HTTP2, controlling them using ruby
21. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
HTTP/2 prioritization: benchmark
๏ฎ differences between the times spent until first-paint
(red bar)
21Recend Advances in HTTP2, controlling them using ruby
22. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Hidden resource
๏ฎ hidden resource: a resource
specified in CSS (@import) or
JavaScript
โ was anti-pattern in HTTP/1
โ anti-pattern in HTTP/2 as well
๏ฎ solution:
โ avoid use of hidden resources
that block rendering (e.g. CSS,
JS)
โ or, specify them using link:
rel=preload
22Recend Advances in HTTP2, controlling them using ruby
client server
23. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Push
๏ฎ three use-cases:
โ prioritization
โ push while processing request
โ push from edge
23Recend Advances in HTTP2, controlling them using ruby
24. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Pushing for prioritization
24Recend Advances in HTTP2, controlling them using ruby
client server
GET /
GET
/style.css
HTTP/2 200 OK
<html>
<link
rel=style.css...
HTTP/2 200 OK
body: ...
#title: ...
1. send CSS, JS first
2. then send HTML
(can be rendered
progressively)
without push
client server
GET /
GET /style.css HTTP/2
HTTP/2 200 OK
body: ...
#title: ...
with push
HTTP/2 200 OK
<html>
<link rel=style.css ...
25. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Push while processing request
๏ฎ web applications involving DB access, etc.
25Recend Advances in HTTP2, controlling them using ruby
req.
processrequest
push-asset
HTML
push-asset
push-asset
push-asset
req.
processrequest
asset
HTML
asset
asset
asset
req.
450ms(5RTT+processingme)
250ms(1RTT+processingme)
without push with push
26. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Push from edge
๏ฎ CDNsโ use-case
โ utilize the conn. while waiting for app. response
26Recend Advances in HTTP2, controlling them using ruby
req.
push-asset
HTML
push-asset
push-asset
push-asset
client edge server (CDN) app. server
req.
HTML
27. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
How to push
๏ฎ H2 server may push preloaded links
โ e.g. Link: </style.css>; rel=preload
โ H2 server may push preloaded links
โ recognized by Apache, H2O, nghttp2
โ patch exists for Nginx
๏ฎ use nopush attribute to opt-out
โ e.g. Link: </dontpush.jpg>; rel=preload; nopush
๏ฎ note: use of preload as a push indicator is upon the
process of standardization at W3C
27Recend Advances in HTTP2, controlling them using ruby
28. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
How to push while processing request
28Recend Advances in HTTP2, controlling them using ruby
๏ฎ send Link: rel=preload as interim response
โ application sends 100 then processes the request
๏ฎ supported in H2O 2.1
GET / HTTP/1.1
Host: example.com
HTTP/1.1 100 Continue
Link: </style.css>; rel=preload
HTTP/1.1 200 OK
Content-Type: text/html
<!DOCTYPE HTML>
...
HTTP/2 server app. server Web app.
GET /
100 Continue
Link: โฆ
GET /
200 OK
200 OK
processrequest
29. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
How to push while processing request
๏ฎ configure your H2 server
โ in case of H2O:
mruby.handler: |
Proc.new do |env|
push_paths = []
if /(/|.html)$/.match(env["PATH_INFO"])
push_paths << "/style.cssโ
...
end
[399, push_paths.empty? ? {} : {"link" =>
push_paths.map{|p| "<#{p}>; rel=preload"}.join("n")}, []]
end
file.dir: /path/to/doc-root
29Recend Advances in HTTP2, controlling them using ruby
30. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
BTW, you can do more by using mruby
๏ฎ HTTP authentication
mruby.handler: |
require "htpasswd.rb"
Htpasswd.new("/path/to/.htpasswd", "realm-name")
๏ฎ DoS mitigation
mruby.handler: |
require "dos_detector.rb"
DoSDetector.new({
:strategy => DoSDetector.CountingStrategy.new({
:period => 10,
:threshold => 100,
:ban_period => 300,
}),
})
30Recend Advances in HTTP2, controlling them using ruby
31. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
... and more
๏ฎ Access Control
mruby.handler: |
acl {
allow { addr == "127.0.0.1" }
deny {
user_agent.match(/curl/i) && !addr.start_with?("192.168.")
}
respond(503, {}, ["Service Unavailable"]) {
addr == malicious_ip
}
redirect("https://example.com/", 301) {
path =~ /moved/
}
use Htpasswd.new("/path/to/.htpasswd", "realm") {
path.start_with?("/admin")
}
}
31Recend Advances in HTTP2, controlling them using ruby
32. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
... and more
๏ฎ fast IPv4 address matching using Trie4
mruby.handler: |
require "trie_addr.rb"
trie = TrieAddr.new.add([
"192.168.0.0/16", "172.16.0.0/12", ...]
)
acl {
allow { trie.match?(addr) }
deny
}
4: http://dsas.blog.klab.org/archives/51293338.html
32Recend Advances in HTTP2, controlling them using ruby
33. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
How to push from edge
๏ฎ depends on CDN
โ some CDNs may use RUM-based approach
โ others may provide DSL
โข GCP provides http2-push-manifest (JSON-based)
โ though cannot be used for pushing from edge
โ anybody using (m)ruby on edge?
33Recend Advances in HTTP2, controlling them using ruby
34. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Push vs. cache
๏ฎ why would you ever push cached resources?
โ itโs waste of bandwidth (and time)
๏ฎ several ways to avoid pushing cached resources
โ cookie-based
โข supported by H2O
โ cache-digest
โข supported by Apache, H2O
โข needs browser support or ServiceWorker script
โข standardization in process at IETF
โ implement your own
34Recend Advances in HTTP2, controlling them using ruby
35. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Avoiding negative effect caused by push
๏ฎ donโt push unless your mechanism is cache-aware
๏ฎ only push resources that block rendering
โ reason:
โข H2 endpoints have difficulty in distributing bandwidth
bet. pushed and pulled responses
โข negative effect caused by HoL blocking, prioritization
and hidden resources becomes more apparent with
push
๏ฎ above rules donโt apply to the tiny pushes
โ i.e. those used as a replacement for inlining (i.e.
<img src=โdata:...โ>)
35Recend Advances in HTTP2, controlling them using ruby
36. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Summary
36Recend Advances in HTTP2, controlling them using ruby
37. Copyright (C) 2016 DeNA Co.,Ltd. All Rights Reserved.
Summary
๏ฎ HTTP/2 has become popular
๏ฎ the effectiveness varies between implementations
โ HoL-blocking avoidance, prioritization, cache-
aware push, ...
โ upcoming specs (e.g. TLS/1.3, QUIC) may cause
even more difference
โ careful evaluation of servers / CDNs is important
๏ฎ H2O is the leader in HTTP/2 server performance
โ and can be configured using mruby
37Recend Advances in HTTP2, controlling them using ruby
Editor's Notes
median โ 90% reduction
80th percentile โ 75% reduction
90th โ 10% reduction
TODO add source