Slide 1

Slide 1 text

Ian Lewis Developer Advocate Google Cloud Platform Go 1.5 & 1.6の新機能のおさらい

Slide 2

Slide 2 text

Confidential & Proprietary Google Cloud Platform 2 Ian Lewis Developer Advocate, Google Cloud Platform Tokyo, Japan @IanMLewis google.com/+IanLewis-hoge

Slide 3

Slide 3 text

Confidential & Proprietary Google Cloud Platform 3 Go! Image © Takuya Ueda. Licensed under CC BY 3.0.

Slide 4

Slide 4 text

Confidential & Proprietary Google Cloud Platform 4 Go(lang) ● Google で起こる問題解決するために Googleで開発 ○ 開発スピード ○ 使いにくい型システム ○ 並行処理

Slide 5

Slide 5 text

Confidential & Proprietary Google Cloud Platform 5 Goの機能 ● ネイティブコードにコンパイル ● ガーメージコレックション ● 型付き ● Goroutines ● Channels ● Structs/Interfaces

Slide 6

Slide 6 text

Confidential & Proprietary Google Cloud Platform 6 Goroutines & Channels Channel Goroutine Goroutine

Slide 7

Slide 7 text

Confidential & Proprietary Google Cloud Platform 7 Goroutines & Channels Channel Goroutine Goroutine Channel

Slide 8

Slide 8 text

Confidential & Proprietary Google Cloud Platform 8 Goroutines & Channels func sum(a []int, c chan int) { sum := 0 for _, v := range a { sum += v } c <- sum // send sum to c }

Slide 9

Slide 9 text

Confidential & Proprietary Google Cloud Platform 9 Goroutines & Channels func main() { a := []int{7, 2, 8, -9, 4, 0} c := make(chan int) go sum(a[:len(a)/2], c) go sum(a[len(a)/2:], c) x, y := <-c, <-c // receive from c fmt.Println(x, y, x+y) }

Slide 10

Slide 10 text

Confidential & Proprietary Google Cloud Platform 10 事例 Image © Takuya Ueda. Licensed under CC BY 3.0.

Slide 11

Slide 11 text

Confidential & Proprietary Google Cloud Platform 11 Docker ● コンテナランタイムエンジン ● HTTP API サーバー ● イメージパケージフォーマット Image © Docker All Rights Reserved http://docs.docker.com/

Slide 12

Slide 12 text

Confidential & Proprietary Google Cloud Platform 12 etcd ● Distributed Key-Value Store ● Used for Storing Cluster State/Config ● Implements RAFT Protocol

Slide 13

Slide 13 text

Confidential & Proprietary Google Cloud Platform 13 Vitess ● Used at Youtube ● Sharding MySQL Servers ● Serving all YouTube DB traffic since 2011 ● http://vitess.io/

Slide 14

Slide 14 text

Confidential & Proprietary Google Cloud Platform 14 Kubernetes ● Container Cluster Manager ● Manages a Distributed Cluster ● Supports Pods ● Provides HTTP API

Slide 15

Slide 15 text

Confidential & Proprietary Google Cloud Platform 15 Gorilla ● ウェブツールキット ● リクエストコンテキスト ● セッション管理 ● URLルーティング ● URLリバース ● Web Sockets

Slide 16

Slide 16 text

Confidential & Proprietary Google Cloud Platform 16 Go 1.5 Image © Takuya Ueda. Licensed under CC BY 3.0.

Slide 17

Slide 17 text

Confidential & Proprietary Google Cloud Platform 17 Go 1.5 ● Released Aug 2015 ● Go 1.0から、一番大きいリリース ● 新しい並行GC ● Go コンパイラやツールチェインの改善 ● パッケージベンダリング (beta) ● goroutineスケジューラーの改善

Slide 18

Slide 18 text

Confidential & Proprietary Google Cloud Platform 18 並行GC ● ユーザープログラムと並行に動く ● プログラムを停止する時間を短めに (<10ms)

Slide 19

Slide 19 text

Confidential & Proprietary Google Cloud Platform 19 並行GC

Slide 20

Slide 20 text

Confidential & Proprietary Google Cloud Platform 20 並行GC

Slide 21

Slide 21 text

Confidential & Proprietary Google Cloud Platform 21 並行GC

Slide 22

Slide 22 text

Confidential & Proprietary Google Cloud Platform 22 並行GC

Slide 23

Slide 23 text

Confidential & Proprietary Google Cloud Platform 23 並行GC

Slide 24

Slide 24 text

Confidential & Proprietary Google Cloud Platform 24 並行GC ● ユーザープログラムと並行に動く ● プログラムを停止する時間を短めに (<10ms)

Slide 25

Slide 25 text

Confidential & Proprietary Google Cloud Platform 25 Go コンパイラやツールチェインの改善 ● GoはGoで書かれている ● GoをビルドするにはCコンパイラーはいらな い ● Go開発はシンプルになる

Slide 26

Slide 26 text

Confidential & Proprietary Google Cloud Platform 26 Go コンパイラやツールチェインの改善 ● 新しい go tool trace コマンド ● Goシェアドライブラリー サポート

Slide 27

Slide 27 text

Confidential & Proprietary Google Cloud Platform 27 Go コンパイラやツールチェインの改善 $ go test -o pkg.test net/http -trace trace.out ok net/http 20.876s $ go tool trace pkg.test trace.out

Slide 28

Slide 28 text

Confidential & Proprietary Google Cloud Platform 28 Goパッケージベンダリング ● パッケージベンダリング ○ GO15VENDOREXPERIMENT=1 ○ vendor ディレクトリに依存ライブラリを入 れる

Slide 29

Slide 29 text

Confidential & Proprietary Google Cloud Platform 29 Goパッケージベンダリング hoge/ hoge.go vendor/piyo/ piyo.go fuga/ fuga.go

Slide 30

Slide 30 text

Confidential & Proprietary Google Cloud Platform 30 Goパッケージベンダリング hoge/ hoge.go vendor/piyo/ piyo.go fuga/ fuga.go piyo/ piyo.go

Slide 31

Slide 31 text

Confidential & Proprietary Google Cloud Platform 31 Goパッケージベンダリング ● 特定なバージョンを部分的に使う ● 分かりやすくて簡単 ● ベンダリングするツールがいくつか (Godeps など)

Slide 32

Slide 32 text

Confidential & Proprietary Google Cloud Platform 32 Go 1.6 Image © Takuya Ueda. Licensed under CC BY 3.0.

Slide 33

Slide 33 text

Confidential & Proprietary Google Cloud Platform 33 Go 1.6 ● Release Jan 2016? ● パッケージベンダリング (stable) ● HTTP/2 サポート (net/http) ● Text/HTMLテンプレートのコード ブロック ● メモリサニタイザー

Slide 34

Slide 34 text

Confidential & Proprietary Google Cloud Platform 34 HTTP/2 Old // hello world, the web server func HelloServer(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "hello, world!\n") } func main() { m := http.NewServeMux() m.HandleFunc("/", HelloServer) srv := &http.Server{ Addr: ":8000", // Normally ":443" Handler: m, } http2.ConfigureServer(srv, &http2.Server{}) log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key")) }

Slide 35

Slide 35 text

Confidential & Proprietary Google Cloud Platform 35 HTTP/2 // hello world, the web server func HelloServer(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "hello, world!\n") } func main() { http.HandleFunc("/", HelloServer) log.Fatal(http.ListenAndServeTLS( ":8000", "server.crt", "server.key", nil)) }

Slide 36

Slide 36 text

Confidential & Proprietary Google Cloud Platform 36 HTTP/2 // hello world, the web server func HelloServer(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "hello, world!\n") } func main() { http.HandleFunc("/", HelloServer) log.Fatal(http.ListenAndServeTLS( ":8000", "server.crt", "server.key", nil)) }

Slide 37

Slide 37 text

Confidential & Proprietary Google Cloud Platform 37 テンプレートの block キーワード ● テンプレート継承が実現できる ● block を定義して、別のテンプレートで オーバーライドできる

Slide 38

Slide 38 text

Confidential & Proprietary Google Cloud Platform 38 テンプレートの block キーワード {{ block "title" .}}Default title{{end}} {{ block "body" .}}Default body{{end}}

Slide 39

Slide 39 text

Confidential & Proprietary Google Cloud Platform 39 テンプレートの block キーワード {{define "title"}}About page{{end}} {{define "body"}}About me{{end}}

Slide 40

Slide 40 text

Confidential & Proprietary Google Cloud Platform 40 テンプレートの block キーワード baseTmpl, err := template.New("base").Parse(base) if err != nil { log.Fatal(err) } aboutPageTmpl, err := template.Must(baseTmpl.Clone()).Parse(aboutPage) if err != nil { log.Fatal(err) } if err := aboutPageTmpl.Execute(os.Stdout, nil); err != nil { log.Fatal(err) }

Slide 41

Slide 41 text

Goを使い尽く しましょう

Slide 42

Slide 42 text

Confidential & Proprietary Google Cloud Platform 42 Go を使い尽くしましょう ● Service Oriented Architecture ● サービス基盤 ● コンテナ

Slide 43

Slide 43 text

Confidential & Proprietary Google Cloud Platform 43 Ian Lewis Developer Advocate, Google Cloud Platform Tokyo, Japan @IanMLewis google.com/+IanLewis-hoge Thank You!