Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Goのパフォーマンス計測 / go performance measurement
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
convto
February 20, 2019
Technology
710
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Goのパフォーマンス計測 / go performance measurement
go 標準のツールチェインでプロファイル取るときのメモ
convto
February 20, 2019
More Decks by convto
See All by convto
Go 1.27 の標準パッケージに uuid が入った!のでいろいろ喋る / go_127_std_go_uuid
convto
3
810
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
700
詳解!defer panic recover のしくみ / Understanding defer, panic, and recover
convto
0
400
MCPと認可まわりの話 / mcp_and_authorization
convto
2
1.7k
バクラクの認証基盤の成長と現在地 / bakuraku-authn-platform
convto
4
2.3k
gob バイナリが Go バージョンによって 出力が変わることについて調べてみた / Investigating How gob Binary Output Changes Across Go Versions
convto
0
180
Go 関連の個人的おもしろCVE 5選 / my favorite go cve
convto
3
610
バイナリを眺めてわかる gob encoding の仕様と性質、適切な使い方 / understanding gob encoding
convto
6
3.5k
みんなでたのしむ math/big / i love math big
convto
0
360
Other Decks in Technology
See All in Technology
書籍『生成AIの安全性入門』の入門
wataoka
0
210
JAWS-UG初心者支部#88わいわい初心塾(夏休みの宿題やったかGit編)
otsuki
0
140
WAF 運用改善の承認サイクル/SRE_BizReach_MIXI_1
visional_engineering_and_design
0
110
Tab5をRubyで動くパソコンにする
kishima
1
190
コスト最適化の「めんどくさい」を AWS FinOps Agent でチョット楽にする
classmethod_kaz
0
220
V8コントリビュート超入門
riyaamemiya
0
140
PM領域でのAI Agentの活用
lycorptech_jp
PRO
0
270
AI時代に、プロダクトの数だけ積み上がる所有コストをどうエンジニアリングするか / Engineering the Cost of Ownership
kzkmaeda
0
1k
Sigmaユーザーのための有用リソース一挙公開 & Sigmaで使えるMCP #sigma_ucj /useful-resources-for-sigma-computing-users-and-mcps-with-sigma
shinyaa31
0
110
Genie Code ワークショップ 基礎編 / Genie-Code-Workshop-fundamental
databricksjapan
PRO
0
360
Kiro Crewしか勝たん!?
miu_crescent
PRO
0
180
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
2
420
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
How to Talk to Developers About Accessibility
jct
2
540
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
Color Theory Basics | Prateek | Gurzu
gurzu
0
460
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
260
Practical Orchestrator
shlominoach
191
12k
Music & Morning Musume
bryan
47
7.4k
4 Signs Your Business is Dying
shpigford
187
23k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.9k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
Abbi's Birthday
coloredviolet
3
9.8k
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 の ヨークプレゼンテーションテンプレー ト を利用しています クレジット表記
ご静聴ありがとう ございました