Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Goのパフォーマンス計測 / go performance measurement
convto
February 20, 2019
Technology
0
140
Goのパフォーマンス計測 / go performance measurement
go 標準のツールチェインでプロファイル取るときのメモ
convto
February 20, 2019
Tweet
Share
More Decks by convto
See All by convto
byte列のbit表現を得るencodingライブラリ作った
convto
1
140
Go runtimeの歩き方/how to follow go runtime function
convto
1
130
入出金ドメインの苦労話と解決へのアプローチ/funds in/out difficulties and solutions
convto
1
620
rsa_understanding_memo
convto
0
260
検索エンジンことはじめ/First step towards full-text search engine
convto
0
59
自作コンパイラやっていきの巻💪💪/making my own compiler!
convto
0
59
kubernetes 浅瀬 dive / kubernetes shallow dive
convto
0
410
GoogleCloudFunctionsでHTTPフックなGoスクリプトを書く / Write HTTP hook Go script with GoogleCloudFunctions
convto
0
47
Athenaのパーテション設定をCloudWatch Events + Lambda で自動化する
convto
0
64
Other Decks in Technology
See All in Technology
一人から始めるプロダクトSRE / How to start SRE in a product team, all by yourself
vtryo
4
2.5k
技術広報の役割を定義してみた 2022年春
afroscript
3
2.4k
Unity Package Managerで自作パッケージを配布する方法
yunoda
0
160
220510 プロセスマイニングを学ぶ PLAY与田さん
comucal
PRO
0
820
1,000万人以上が利用する「家族アルバム みてね」のSRE組織は4年間でどのように作られてきたのか/SRE NEXT 2022
isaoshimizu
4
2.8k
Poolにおける足を止めないシステム基盤構築
winebarrel
3
740
読者のことを考えて書いてみよう / Write with your reader in mind
line_developers
PRO
3
350
[SRE NEXT 2022]ヤプリのSREにおけるセキュリティ強化の取り組みを公開する
mmochi23
1
390
モダンデータスタックとかの話(データエンジニアのお仕事とは)
foursue
0
400
街じゅうを"駅前化"する電動マイクロモビリティのシェアサービス「LUUP」のIoTとSRE
0gm
1
600
ITエンジニアを取り巻く環境とキャリアパス / A career path for Japanese IT engineers
takatama
0
580
我々はなぜテストをするのか?
kawaguti
PRO
0
300
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
11
1.5k
Designing with Data
zakiwarfel
91
3.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
268
11k
GitHub's CSS Performance
jonrohan
1020
410k
Three Pipe Problems
jasonvnalue
89
8.6k
From Idea to $5000 a Month in 5 Months
shpigford
372
44k
The Illustrated Children's Guide to Kubernetes
chrisshort
14
34k
Keith and Marios Guide to Fast Websites
keithpitt
404
21k
Unsuck your backbone
ammeep
659
55k
The Language of Interfaces
destraynor
148
20k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
655
120k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
315
19k
Transcript
Goのパフォーマンス計測 2019/02/20(水) Makuake LT Party #9
convto jisibari Twitter: @convto Github: convto 2
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
どういう時に必要? - ボトルネック調査 - コードレビュー - その他
どうせツールの導入が大変でしょ...?
標準のツールチェイン&パッケージでできます - testing - runtime/pprof - runtime
標準のツールチェイン&パッケージでできます - testing - runtime/pprof - runtime Thank you
除霊
どういう時に必要? - ボトルネック調査 - コードレビュー - その他
どういう時に必要? - ボトルネック調査 - コードレビュー - その他 気軽に試せるのでぜひ
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
Bench mark test - testingパッケージでできる - `Benchmark` プレフィックスが対象 - `$
go test -bench .` で実行できる - オプションがいくつかある
例
実行
実行 実行回数 1回あたり実行時間
実行 実行回数 1回あたり実行時間 1回あたり使用メモリ 1回あたりメモリ割り 当て回数
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
runtime/pprofパッケージ - runtimeパッケージのwrapperみたいなもの - 可視化ツールで想定されている形式で調査結果 を吐き出す - 可視化は `go tool
pprof` を利用する
“ Package pprof writes runtime profiling data in the format
expected by the pprof visualization tool. https://golang.org/pkg/runtime/pprof/
pprof (with test) - benchmark の結果をプロファイルとして出力する 機能 - `go test`
コマンドに組み込まれている - `go test -memprofile mem.out -bench .` のように実 行する
pprof (with test) - benchmark の結果をプロファイルとして出力する 機能 - `go test`
コマンドに組み込まれている - `go test -memprofile mem.out -bench .` のように実 行する テストコードをいじるだけでできます ビルドされるコードに影響はでません
実行
[demo] 吐かれたプロファイルを go tool で 分析してみる
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
pprof (埋め込み) - スタンドアロンなプログラムで使う - バイナリに埋め込むので配布先でもプロファイル が吐ける
ドキュメントで紹介されている例
ドキュメントで紹介されている例 main関数にこれを埋めるとプロファイル吐け るようになる
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
pprof (with http) - net/httpのサブパッケージ(net/http/pprof)を使う - HTTP経由でプロファイルを取得できる - testも書いてないし、バイナリに埋め込むのは面 倒、とかでサクッと試す時におすすめ
こう書く
こうやってプロファイルとる
対応してるエンドポイント - http://localhost:6060/debug/pprof/profile - http://localhost:6060/debug/pprof/heap - http://localhost:6060/debug/pprof/block - http://localhost:6060/debug/pprof/mutex -
より詳しくはこちら https://golang.org/pkg/net/http/pprof/
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
runtimeパッケージでもパフォーマンス観測はできる - たとえば https://golang.org/pkg/runtime/#MemProfile を 使ったりする - が、ドキュメントでも「ほとんどの場合はpprof使っ た方がいいよ」とちょいちょい出てくる
runtimeパッケージのメリット - https://golang.org/pkg/runtime/#ReadMemStats を使うとstack 領域のメモリ使用量がわかる - pprofはstackは基本的に読めない、heapのみ - その他、比較的低レイヤーな処理を生で触れる
runtimeパッケージのメリット - https://golang.org/pkg/runtime/#ReadMemStats を使うとstack 領域のメモリ使用量がわかる - pprofはstackは基本的に読めない、heapのみ - その他、比較的低レイヤーな処理を生で触れる ランタイムレベルの操作をサポートするパッ
ケージなので、wrapperがあれば 理由がない限りそっちを使おう
こうやってプロファイルとる
もくじ - どういう時に必要? - bench mark test - pprof (with
test) - pprof (埋め込み) - pprof (with http) - runtime - まとめ
まとめ - Goは標準でいろいろ覗けるからよい - pprofは色々な方法で使える - runtimeでの計測は基本しなくていい
- プレゼンテーションテーマは SlidesCarnival の ヨークプレゼンテーションテンプレー ト を利用しています クレジット表記
ご静聴ありがとう ございました