Http2 on go1.6rc2

21
HTTP2 on Go1.6 Go1.6 Release Party 2016 Jxck

Transcript of Http2 on go1.6rc2

HTTP2 on Go1.6Go1.6 Release Party 2016

Jxck

● id: Jxck● github: Jxck● twitter: @jxck_● blog: https://blog.jxck.io● podcast: http://mozaic.fm● Love: music

Jack

3

#http2study #wdpress vol.75#http2go (deprecated)

and more...

#mozaicfm ep2

http2 activity

RFC7540

4

5

HTTP2 in Go1.6

net/http supports http2

6

7

before

import (fmtlognet/http

)

func main() { var s http.Server s.Addr = ":8080"

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") fmt.Fprintf(w, "Hello World") })

log.Fatal(s.ListenAndServeTLS(cert, key))}

8

after

import (fmtlognet/http

)

func main() { var s http.Server s.Addr = ":8080"

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") fmt.Fprintf(w, "Hello World") })

log.Fatal(s.ListenAndServeTLS(cert, key))}

9

you don’t need this after 1.6

$ git clone --depth=1 https://go.googlesource.com/go $HOME/gotip$ cd $HOME/gotip/src$ ./make.bash$ cd $YOUR_PROJ$ $HOME/gotip/bin/go {install,build,test}.

10

how http2 bundled ?$ tree $GOROOT/src/net/http|-- fs.go|-- fs_test.go|-- h2_bundle.go|-- header.go|-- header_test.go|-- http_test.go

$ bundle golang.org/x/net/http2 net/http http2

bundle golang.org/x/net/http2

into net/http package

prefixed with `http2`

prefixed source

11

bundled

original

inject h2 to net/http2

12

App App

ALPNhttp/2 client

http/1.1 client

http/1.1 server

http/2 server

TCP

req/res|

frame

req/res|

frameframe

req/res req/resreq/res

inside(current status rc2)

13

hpack

14

● compress http header○ with static/dynamic table○ with huffman encoding○ with binary frame

● Encode Strategy○ depends on implement

● Benchmark○ using hpack-test-case○ https://gist.github.com/Jxck/a2125cfc162229e4f54f

implementation go-hpack haskell nghttp2 node-http2

ration(small is better) 31% 31% 31% 31%

2016/2/18benchmark script has a bug, results are updated.

Server Push

15

● Push data from server○ sending PUSH_PROMISE frame

● Low Level API○ WritePushPromise()

● High Level API○ not yet○ wip ? https://goo.gl/IV0fyI

// CAUTION: wip codeif p, ok := w.(http2.Pusher); push && ok {

p.Push("GET", “/path/to/push”, nil)}

Flow Control

16

● 2 Level Flow Control○ Stream level○ Connection level○ with WindowUpdate Frame

● Current Implement○ supported○ default sends big window update for connection○ stream window update each 4M transfer

Priority

17

● Priorities Contents○ with weight of Stream○ make dependency tree○ ignorable○ ex) high for html, low for image..

● Low Level○ WritePriority()

● High Level○ no high level api○ no auto priorities content like html, css, img etc○ priority respected ?? I can’t find.

Spec Coverage

18

● testing with h2spec○ https://github.com/summerwind/h2spec

● toward http2.golang.org

$ h2spec -t http2.golang.org 3.5. HTTP/2 Connection Preface ✓ Sends invalid connection preface

…..

8.2. Server Push ✓ Sends a PUSH_PROMISE frame

71 tests, 58 passed, 0 skipped, 13 failed

more

19

● DEBUG

● h2i

$ GODEBUG="http2debug=1" go run main.go$ GODEBUG="http2debug=2" go run main.go

$ h2i jxck.ioConnected to 160.16.234.102:443...h2i> headers(as HTTP/1.1)> GET / HTTP/1.1(as HTTP/1.1)>Opening Stream-ID 1:...

Go to the HTTP2!!

20

Jack