QUIC(Quick UDP Internet Connections)是基於UDP的多路復用和安全的通用傳輸層協議,相當於在UDP上實現了TCP+TLS+HTTP/2數據傳輸。
理論上quic采用UDP傳輸數據,封裝了TLS和HTTP/2(HTTP3協議中,quic僅封裝TLS,HTTP3協議數據基於quic協議傳輸),首次連接加載時間為2RTT,之后重新為1RTT。
QUIC是HTTP3的基礎。目前quic協議未定稿,變動頻繁。
quic-go測試示例
git clone https://gitee.com/yuxio/quic-go.git cd quic-go/example go build -o ser main.go go build -o cli client/main.go
運行:
示例采用單向認證方式,證書簽發的CN=localhost,不能使用IP。
./ser -bind ":8088" server GET localhost:8088/demo/tiles server Responding with 200 server Peer closed session with error: Application error 0x100 server Connection 0xfc314d4e5df5d38b closed.
./cli https://localhost:8088/demo/tiles GET https://localhost:8088/demo/tiles client Starting new connection to localhost ([::]:52586 -> 127.0.0.1:8088), source connection ID (empty), destination connection ID 0xfc314d4e5df5d38b, version TLS dev version (WIP) Got response for https://localhost:8088/demo/tiles: &http.Response{Status:"200 OK", StatusCode:200, Proto:"HTTP/3", ProtoMajor:3, ProtoMinor:0, Header:http.Header{}, Body:(*http3.body)(0xc000324a00), ContentLength:0, TransferEncoding:[]string(nil), Close:false, Uncompressed:false, Trailer:http.Header(nil), Request:(*http.Request)(nil), TLS:(*tls.ConnectionState)(nil)} Request Body: <html><head><style>img{width:40px;height:40px;}</style></head><body><img src="/demo/tile?cachebust=0">...<img src="/demo/tile?cachebust=199"></body></html> client Closing session with error: Application error 0x100 client Connection 0xfc314d4e5df5d38b closed.
QUIC單向認證(22數據幀)
目前測試quic-go:同等條件下QUIC比HTTP2傳輸的數據包少,時間應該較短,目前測試效果不佳,但相差不大。大數據量、多次連接時QUIC才能體現優勢。
簡單測試單次鏈接時間:連接--發送--接收--斷開
grpc_simple: 28ms
grpc_single: 44ms
grpc_dul: 51ms
http_simple: 21ms
http_single: 32ms
http_dual: 38ms
quic_single: 35ms
參考: