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
360
Goのパフォーマンス計測 / go performance measurement
go 標準のツールチェインでプロファイル取るときのメモ
convto
February 20, 2019
Tweet
Share
More Decks by convto
See All by convto
Go1.22からの疑似乱数生成器について/go-122-pseudo-random-generator
convto
2
200
Go1.20からサポートされるtree構造のerrの紹介と、treeを考慮した複数マッチができるライブラリを作った話/introduction of tree structure err added since go 1_20
convto
0
510
byte列のbit表現を得るencodingライブラリ作った
convto
1
880
Go runtimeの歩き方/how to follow go runtime function
convto
1
810
入出金ドメインの苦労話と解決へのアプローチ/funds in/out difficulties and solutions
convto
2
1.2k
rsa_understanding_memo
convto
0
470
検索エンジンことはじめ/First step towards full-text search engine
convto
0
87
自作コンパイラやっていきの巻💪💪/making my own compiler!
convto
0
89
kubernetes 浅瀬 dive / kubernetes shallow dive
convto
0
490
Other Decks in Technology
See All in Technology
開発生産性大幅アップ!Postman VS Code拡張機能
nagix
2
350
自動生成を活用した、運用保守コストを抑える Error/Alert/Runbook の一元集約管理 / Centralized management of Error/Alert/Runbook to minimize operational costs using automated code generation
biwashi
12
2.3k
[PlatformCon 24] Platform Orchestrators: The Missing Middle of Internal Developer Platforms?
danielbryantuk
1
820
GraphQL 成熟度モデルの紹介と、プロダクトに当てはめた事例 / GraphQL maturity model
mh4gf
7
1.3k
プロトタイピングによる不確実性の低減 / Reducing Uncertainty through Prototyping
ohbarye
5
370
4年前、あるじゃん老害エンジニアLT合戦に登壇、米国西海岸コンピュータ歴史博物館体験記の続編
toshi_atsumi
0
220
JSON攻略法.pdf
miyakemito
8
4.6k
Postman v10リリース後を振り返る / Looking back at Postman v10 after release
yokawasa
1
150
Azure Container Apps + Bicep 〜 こんな感じで運用しています
kaz29
2
400
KubeCon EU 2024 Recap “Kubernetes Policy Time Machine: Where to Next?”
ryysud
0
190
Compose Compiler Metricsを使った実践的なコードレビュー
tomorrowkey
1
210
MySQL の SQL クエリチューニングの要所を掴む勉強会
andpad
2
5.6k
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
KATA
mclloyd
14
12k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
The Cost Of JavaScript in 2023
addyosmani
15
3.8k
Visualization
eitanlees
135
14k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
It's Worth the Effort
3n
180
27k
Testing 201, or: Great Expectations
jmmastey
27
6.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
9
8.3k
We Have a Design System, Now What?
morganepeng
42
6.7k
Building a Scalable Design System with Sketch
lauravandoore
455
32k
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 の ヨークプレゼンテーションテンプレー ト を利用しています クレジット表記
ご静聴ありがとう ございました