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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
1k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
Domain-Driven Transformation
hschwentner
2
2.3k
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
ジョジョの世界をXRで再現する
mofurune
0
160
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.6k
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
920
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
ラッコキーワード サービス紹介資料
rakko
1
5.3M
Balancing Empowerment & Direction
lara
6
1.3k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
エンジニアに許された特別な時間の終わり
watany
109
250k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
How to make the Groovebox
asonas
2
2.5k
Abbi's Birthday
coloredviolet
4
10k
Crafting Experiences
bethany
1
380
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/