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
convto
February 20, 2019
Technology
0
510
Goのパフォーマンス計測 / go performance measurement
go 標準のツールチェインでプロファイル取るときのメモ
convto
February 20, 2019
Tweet
Share
More Decks by convto
See All by convto
gob バイナリが Go バージョンによって 出力が変わることについて調べてみた / Investigating How gob Binary Output Changes Across Go Versions
convto
0
85
Go 関連の個人的おもしろCVE 5選 / my favorite go cve
convto
3
380
バイナリを眺めてわかる gob encoding の仕様と性質、適切な使い方 / understanding gob encoding
convto
6
2.4k
みんなでたのしむ math/big / i love math big
convto
0
230
Go1.22からの疑似乱数生成器について/go-122-pseudo-random-generator
convto
2
650
Go1.20からサポートされるtree構造のerrの紹介と、treeを考慮した複数マッチができるライブラリを作った話/introduction of tree structure err added since go 1_20
convto
0
1k
byte列のbit表現を得るencodingライブラリ作った
convto
1
1.2k
Go runtimeの歩き方/how to follow go runtime function
convto
1
950
入出金ドメインの苦労話と解決へのアプローチ/funds in/out difficulties and solutions
convto
2
1.3k
Other Decks in Technology
See All in Technology
ディスプレイ広告(Yahoo!広告・LINE広告)におけるバックエンド開発
lycorptech_jp
PRO
0
260
AIエージェント時代のエンジニアになろう #jawsug #jawsdays2025 / 20250301 Agentic AI Engineering
yoshidashingo
8
1.8k
AWS Well-Architected Frameworkで学ぶAmazon ECSのセキュリティ対策
umekou
2
130
JavaにおけるNull非許容性
skrb
2
2.5k
生成 AI プロダクトを育てる技術 〜データ品質向上による継続的な価値創出の実践〜
icoxfog417
PRO
5
1.9k
RemoveだらけのPHPUnit 12に備えよう
cocoeyes02
0
200
AIエージェント元年@日本生成AIユーザ会
shukob
0
120
分解して理解する Aspire
nenonaninu
2
800
【内製開発Summit 2025】イオンスマートテクノロジーの内製化組織の作り方/In-house-development-summit-AST
aeonpeople
2
530
OSS構成管理ツールCMDBuildを使ったAWSリソース管理の自動化
satorufunai
0
540
AI Agent時代なのでAWSのLLMs.txtが欲しい!
watany
2
180
(機械学習システムでも) SLO から始める信頼性構築 - ゆる SRE#9 2025/02/21
daigo0927
0
250
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Producing Creativity
orderedlist
PRO
344
40k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
How to train your dragon (web standard)
notwaldorf
91
5.9k
GraphQLとの向き合い方2022年版
quramy
44
14k
The Cult of Friendly URLs
andyhume
78
6.2k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
250
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 の ヨークプレゼンテーションテンプレー ト を利用しています クレジット表記
ご静聴ありがとう ございました