这个是一个自己工作中小组内的一个简单分享,关于HTTP2各种内容。以HTTP2作为标题,结合了一些工作里的业务场景,内容主要还是要靠讲的,并且在语速比较快的情况下也说了约40分钟,所以只能偷懒上些ppt的内容了。当然作为国际部门,现在内部要求都要英文交流,所以ppt也是英文的...
HTTP History
Concept Hypertext (1963)
HTTP 0.9 (before 1995)
Only get, no header, 1 page
HTTP 1.0 (1996)
Header, response code, redirect, post. Etc, 60 pages
HTTP 1.1 (1999)
Options, upgrade, cache header extends
SPDY (2009 google)
HTTP2 (2012, 2015/5/14 published)
HTTP2 related
Server (google)
Proxy (akamai)
Client (google firefox)
HTTP2 Features
One Connection
use one connection for parallelism (ares oversea)
Header Compression
uses header compression to reduce overhead
Server Push
allows servers to “push” responses proactively into client caches
HTTP2 Requirement
Stage 1 (NPN)
Web server supported H2 (nginx 1.9.5+)
TLS certificate (Let' s Encrypt)
Chrome 41, Firefox 36, Edge 12, Safari 9, Opera 28
Stage 2 (ALPN)
OpenSSL 1.0.2g
Chrome 51
Site: HTTP1.1 vs HTTP2
HTTP2 Features
One Connection
use one connection for parallelism (ares oversea)
Header Compression
uses header compression to reduce overhead
Server Push
allows servers to “push” responses proactively into client caches
HTTP2 Requirement
Stage 1 (NPN)
Web server supported H2 (nginx 1.9.5+)
TLS certificate (Let' s Encrypt)
Chrome 41, Firefox 36, Edge 12, Safari 9, Opera 28
Stage 2 (ALPN)
OpenSSL 1.0.2g
Chrome 51
Site: HTTP1.1 vs HTTP2
Site: HTTP1.1 vs HTTP2
sample demo parse
Questions about connection
How many connections browser can open, and why?
How many connections system can maintain?
What’s the ideal delay between Shanghai and New York?
Windows connections
ref: http://smallvoid.com/article/winnt-tcpip-max-limit.html
result: < 1000
Http1 problems
Head of line blocking
Inefficient of TCP usage rate
Slow start
Congestion window
Etc...
Http1.1 Optimization
Sprite Image
Domain sharding
Disable cookie
File concat
Then use http2
Http1.1 Optimization in H2
Sprite Image
It depends, heigh cost, bg image load when visible
Domain sharding
wrong
Disable cookie
wrong
File concat
It depends, unnecessary almost
Client Support detect
Upgrade header
TLS
NPN (Next Protocol Negotiation)
ALPN (Application Layer Protocol Negotiation)
HTTP Alternative services
Upgrade header
GET ws://example.com/ HTTP/1.1
Connection: Upgrade
Upgrade: websocket
Origin: http://swordair.com
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: xxx
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: xxxxx
GET / HTTP/1.1 Host: example.com
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload>
Unsupport:
HTTP/1.1 200 OK
Content-Length: 243
Content-Type: text/html
Unsupport:
HTTP/1.1 200 OK
Content-Length: 243
Content-Type: text/html
Upgrade header
GET ws://example.com/ HTTP/1.1
Connection: Upgrade
Upgrade: websocket
Origin: http://swordair.com
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: xxx
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: xxxxx
GET / HTTP/1.1 Host: example.com
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload>
Unsupport:
HTTP/1.1 200 OK
Content-Length: 243
Content-Type: text/html
Unsupport:
HTTP/1.1 200 OK
Content-Length: 243
Content-Type: text/html
GET ws://example.com/ HTTP/1.1
Connection: Upgrade
Upgrade: websocket
Origin: http://swordair.com
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: xxx
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: xxxxx
GET / HTTP/1.1 Host: example.com
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload>
Unsupport:
HTTP/1.1 200 OK
Content-Length: 243
Content-Type: text/html
Unsupport:
HTTP/1.1 200 OK
Content-Length: 243
Content-Type: text/html
but, just exist in RFC actually
ALPN
TLS connection ‘Client Hello’
Client double confirm
Connection preface
PRI * HTTP/ 2. 0\ r\ n\ r\ nSM\ r\ n\ r\ n
HTTP2 basics
TCP socket
Steam
Frame
HTTP2 Steam
Steam is H2 independent, two-way frame change
A new request will rise a new steam
Steam id
H2 Frame
HTTP based on ‘Text splite’
HTTP2 based on Frame (key of one connection for parallelism)
Frame Type
NAME
ID
DESC
DATA
0x0
Steam data
HEADERS
0x1
http header
PRIORTY
0x2
Priority of steam
RST_STEAM
0x3
Stop steam (error)
SETTINGS
0x4
Set connection param
PUSH_PROMISE
0x5
Server push tips
PING
0x6
Test connection and rtt
GOAWAY
0x7
Steam end
WINDOW_UPDATE
0x8
Flow control
CONTINUATION
0x9
Extends HEADERS frame
Header Compression
deflate & CRIME (Compression Ratio Info-leak Made Easy)
Gzip is unsafe
HPACK
Header infos are similar
Index specific header and value
HPACK sample
Header1: All work and no play
Header2: makes Steven
Header3: a dull boy
H2 Frame
HTTP based on ‘Text splite’
HTTP2 based on Frame (key of one connection for parallelism)
Frame Type
NAME
ID
DESC
DATA
0x0
Steam data
HEADERS
0x1
http header
PRIORTY
0x2
Priority of steam
RST_STEAM
0x3
Stop steam (error)
SETTINGS
0x4
Set connection param
PUSH_PROMISE
0x5
Server push tips
PING
0x6
Test connection and rtt
GOAWAY
0x7
Steam end
WINDOW_UPDATE
0x8
Flow control
CONTINUATION
0x9
Extends HEADERS frame
Header Compression
deflate & CRIME (Compression Ratio Info-leak Made Easy)
Gzip is unsafe
HPACK
Header infos are similar
Index specific header and value
HPACK sample
Header1: All work and no play
Header2: makes Steven
Header3: a dull boy
DATA
0x0
Steam data
HEADERS
0x1
http header
PRIORTY
0x2
Priority of steam
RST_STEAM
0x3
Stop steam (error)
SETTINGS
0x4
Set connection param
PUSH_PROMISE
0x5
Server push tips
PING
0x6
Test connection and rtt
GOAWAY
0x7
Steam end
WINDOW_UPDATE
0x8
Flow control
CONTINUATION
0x9
Extends HEADERS frame
Header Compression
deflate & CRIME (Compression Ratio Info-leak Made Easy)
Gzip is unsafe
HPACK
Header infos are similar
Index specific header and value
HPACK sample
Header1: All work and no play
Header2: makes Steven
Header3: a dull boy
Header1: All work and no play
Header2: makes Steven
Header3: a dull boy
Client generate this index and send to server, server will also create one
55
Header1
All work and no play
56
Header2
makes Steven
57
Header3
a dull boy
Next item send: 55 56 57
Every connection maintain it’s index status.
Server Push
Reasonable push decrease 20% - 50% render time
Push will waste bandwidth (resource cached already)
Best Timing:
Server busy
Client idle
Frame Type “PUSH_RPOMISE”
Client can reject use “RST_STEAM”
FTTB in H2
H2 Extra work:
Performance:
H2 <= H1
Experience
H2 > H1
HTTP2 debug
chrome://net-internals/ (early version)
Chrome debug tool -> network tab
Session key logging (env SSLKEYLOGFILE=~/key.log) wireshark
Firefox command mode record HTTP session log
TCP and UDP
TCP is not fast portocal but it is reliable
But we need more fast net
core problen is:
QUIC
Quick UDP Internet Connection
Google
Based on UDP which in user space
Provide equivalent HTTP2 new features
HTTP3 ?
FIN
评论加载中...
由Disqus提供评论支持,如果评论长时间未加载,请飞跃长城。