Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ブログのリアクションから始めるGoのパフォーマンス分析入門
Search
Takayuki Miyahara
December 02, 2023
Programming
490
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ブログのリアクションから始めるGoのパフォーマンス分析入門
Takayuki Miyahara
December 02, 2023
More Decks by Takayuki Miyahara
See All by Takayuki Miyahara
次なるpkg/errorsを探して
always_allokay
2
1.7k
Other Decks in Programming
See All in Programming
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
250
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
オーケストレーション記述言語 Katari
yukikurage
0
250
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
420
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
230
Distance field of Julia set
kinakomoti321
0
310
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
250
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
420
AI-Powered Domain-Driven Design
ziobrando
0
430
仕様駆動開発入門 (何を作るかを先に決めて渡す) | 目指せ Kiro マスター 05
inariku
PRO
2
120
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
The Language of Interfaces
destraynor
162
27k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k
Fireside Chat
paigeccino
43
4.1k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
We Are The Robots
honzajavorek
0
440
Google's AI Overviews - The New Search
badams
0
1.7k
What's in a price? How to price your products and services
michaelherold
247
13k
Claude Code のすすめ
schroneko
67
230k
Transcript
ブログのリアクションから始めるGo のパフォーマンス分析入門 宮原 孝行 Go Conference mini 2023 2023/12/02
Copyright Kanmu, Inc. All right reserved. 2 宮原 孝行 software
engineer at Kanmu, Inc. @miyataka @always_allokay 自己紹介
Copyright Kanmu, Inc. All right reserved. 3 発表の目的 背景 パフォーマンス分析への入門
まとめ 1 2 3 目次 4
発表の目的 1
Copyright Kanmu, Inc. All right reserved. 発表の目的 5 1 パフォーマンス分析へ入門するための参考情報を提供す
ること
背景 2
Copyright Kanmu, Inc. All right reserved. 背景:発表&ブログを書いた 7 2 •
6月に「次なる`pkg/errors`を探して」という発表した&ブログを書いた https://speakerdeck.com/always_allokay/errorswotan-site
Copyright Kanmu, Inc. All right reserved. 背景:「次なる`pkg/errors`を探して」の3行まとめ 8 2 •
`pkg/errors`の移行先となるライブラリ選定について書いた記事 • 互換性・スタックトレースのサポート・性能評価で評価 • `cockroachdb/errors`が有力と結論 https://speakerdeck.com/always_allokay/errorswotan-site?slide=30
Copyright Kanmu, Inc. All right reserved. 背景:ブログを書いたらリアクションきた 9 2
Copyright Kanmu, Inc. All right reserved. 背景:「次なる pkg/errors を探してを読んで」3行まとめ 10
2 テキストを入れたり。テキストを入れたり。テキストを入れたり。テ キストを入れたり。テキストを入れたり。テキストを入れたり。テキ ストを入れたり。テキストを入れたり。 • cockroachdb/errorsはpkg/errorsを内部的に利用し、かつそこがボトル ネックになっている。 • ベンチマークの取り方が片方に有利になってしまっている(エラーの出力だ けでなく、生成も含めるべき) • 数値だけでなくなぜその結果になったかの分析をすべき https://orisano.hatenablog.com/entry/2023/06/21/231349
パフォーマンス分析への入門 3
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 12 3 •
自分でもframegraph分析をやってみる • Goでは標準ライブラリ・同梱ツールだけでできる ◦ `testing`パッケージ ◦ `go test` ◦ `go tool pprof`
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 13 3 •
手順は3つだけ ◦ `testing.B`を使ってベンチマークテストを書く ◦ profileを出力させる ▪ `go test -bench -cpuprofile=xxx` ◦ profile表示 ▪ `go tool pprof -http :8080 xxx`
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 14 3 •
cockroachdb/errorsのCPUプロファイルを取得
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 15 3 •
cockroachdb/errorsのCPUプロファイルを取得 FormatError(formatErrorInternal)が大半を占める
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 16 3 •
cockroachdb/errorsのCPUプロファイルを取得 同一Frameで同じ関数(FuncForPC, FileLine)が複 数回実行されている→最適化の余地あり
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 17 3 •
goark/errsのCPUプロファイルを取得
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 18 3 •
goark/errsのCPUプロファイルを取得 EncodeJsonが大半を占める
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 19 3 •
goark/errsのCPUプロファイルを取得 EncodeJsonが大半を占める →goccy/go-jsonへの置き換えで改善する可能性
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 20 3 •
「次なる pkg/errors を探してを読んで」3行まとめ(再掲) ◦ > ベンチマークの取り方が片方に有利になってしまっている(エラーの 出力だけでなく、生成も含めるべき) • →ベンチマークの取り方を変えてみる
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 21 3 •
cockroachdb/errorsのCPUプロファイルを取得(改ver)
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 22 3 •
cockroachdb/errorsのCPUプロファイルを取得(改ver) 生成時はほとんどruntime.Callers →最適化の余地が少ない→最適化済みといえる
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 23 3 •
goark/errsのCPUプロファイルを取得(改ver)
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 24 3 •
goark/errsのCPUプロファイルを取得(改ver) 生成時はほとんどruntime.Callers →最適化の余地が少ない→最適化済みといえる
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 25 3 •
生成時コストも同時にベンチマークをとる ◦ 前回と異なり、性能面でもcockroachdb/errorsが上回る結果となった ※ただし、マイクロベンチマークであり、実際の環境では異なる結果となる可能性があることに注意 すること
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 26 3 •
生成時コストも同時にベンチマークをとる ◦ 前回と異なり、性能面でもcockroachdb/errorsが上回る結果となった →⭕ https://speakerdeck.com/always_allokay/errorswotan-site?slide=30
Copyright Kanmu, Inc. All right reserved. パフォーマンス分析への入門 27 3 •
生成時コストも同時にベンチマークをとる ◦ 前回と異なり、性能面でもcockroachdb/errorsが上回る結果となった • エラー発生時にはスタックトレースの生成と出力が両方行われるので、前 回より妥当な比較になったと言える
まとめ 4
Copyright Kanmu, Inc. All right reserved. まとめ 29 4 テキストを入れたり。テキストを入れたり。テキストを入れたり。テ
キストを入れたり。テキストを入れたり。テキストを入れたり。テキ ストを入れたり。テキストを入れたり。 • Goでは標準でパフォーマンス分析をするためのツールがある • パフォーマンス分析の手順は3つだけ • 数値だけでなく、framegraphを使ってドリルダウンな分析をすることで性能改 善策やより妥当な検証をすることに繋がるよ!!!!!!!(反省)
付録 5
Copyright Kanmu, Inc. All right reserved. 参考文献 31 5 テキストを入れたり。テキストを入れたり。テキストを入れたり。テ
キストを入れたり。テキストを入れたり。テキストを入れたり。テキ ストを入れたり。テキストを入れたり。 • https://tech.kanmu.co.jp/entry/2023/06/19/150000 • https://orisano.hatenablog.com/entry/2023/06/21/231349 • https://www.oreilly.co.jp/books/9784814400072/ • https://go.dev/blog/pprof • https://github.com/rsc/benchgraffiti/ • https://deeeet.com/writing/2016/05/29/go-flame-graph/ • https://www.youtube.com/watch?v=N3PWzBeLX2M
Copyright Kanmu, Inc. All right reserved. 付録: 詳解システム・パフォーマンス 32 5
• 詳解システム・パフォーマンスを読み直す(!) ◦ 実は社内の勉強会で読んでいた • なにか頭を整理できる見方(地図)がみつかるのではないか? ◦ →あった!!
Copyright Kanmu, Inc. All right reserved. 付録: 詳解システム・パフォーマンス 33 5
テキストを入れたり。テキストを入れたり。テキストを入れたり。テ キストを入れテキストを入れたり。テキストを入れたり。テキストを 入れたり。テキストを入れたり。 • > 2.4 視点 • > パフォーマンス分析には、ワークロード分析(workload analysis)とリソース 分析(resource analysis)というふたつの視点があり、分析者、指標、アプ ローチが異なる Brendan Gregg 詳解システム・パフォーマンス 第2版 オライリー・ジャパン 2023 https://www.oreilly.co.jp/books/9784814400072/
Copyright Kanmu, Inc. All right reserved. 付録: パフォーマンス分析の2つの視点 34 5
テキストを入れたり。テキストを入れたり。テキストを入れたり。テ キストを入れテキストを入れたり。テキストを入れたり。テキストを 入れたり。テキストを入れたり。 • パフォーマンス分析 ◦ ワークロード分析(ドリルダウン、アプリケーション開発者) ◦ リソース分析(ボトムアップ、システム管理者) Brendan Gregg 詳解システム・パフォーマンス 第2版 オライリー・ジャパン 2023 https://www.oreilly.co.jp/books/9784814400072/
Copyright Kanmu, Inc. All right reserved. 付録: ワークロード分析 35 5
• ワークロード分析はシステムの動きを、入力→レイテンシ→完了の3つの段階 から構成されると捉える • 前回と今回のブログの違いはレイテンシの掘り下げの有無と言えそう Brendan Gregg 詳解システム・パフォーマンス 第2版 オライリー・ジャパン 2023 https://www.oreilly.co.jp/books/9784814400072/