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
480
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
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.9k
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
110
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
230
FreeBSDでZabbixを動かす
kenkino
0
320
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
120
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
190
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
900
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
240
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
310
Security issues being discussed on Web Platforms
petamoriken
0
1.1k
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.4k
Featured
See All Featured
Speed Design
sergeychernyshev
33
2.1k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
A better future with KSS
kneath
240
18k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
530
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
480
Optimizing for Happiness
mojombo
378
71k
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/