Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
$ go tool traceを使ってみよう/ Let's use go tool trace
nametake
December 11, 2017
Technology
2
1.7k
$ go tool traceを使ってみよう/ Let's use go tool trace
golang.tokyo #11(
https://techplay.jp/event/641403
)での発表資料です。
nametake
December 11, 2017
Tweet
Share
More Decks by nametake
See All by nametake
QAエンジニアが実例マッピングを2ヶ月運用した話 / Example Mapping for 2 months
nametake
2
670
1人目QAエンジニアよもやま話 / QA Test Talk Vol.1
nametake
4
270
アルプでのAgile Testing / Alp Agile Testing
nametake
0
860
CFD-Editorというツールを作ってみた話 / Made CFD-Editor
nametake
1
130
スタートアップで1人目QAエンジニアになった話 / Startup first QA
nametake
3
870
テスト技法の話 / Testing techniques
nametake
5
3.8k
社内の品質管理 / In House QA
nametake
0
2.7k
labelerrとsuberrを作った話 / created labelerr and suberr
nametake
1
370
goroutineとマルチスレッドデザインパターン/ goroutine and multithreaded design pattern
nametake
1
940
Other Decks in Technology
See All in Technology
マルチテナントSaaSのカスタム要件に、 Auth0テナントを分割せず向き合う! / Multi tenant SaaS with Auth0
hiroga
0
180
大声で伝えたい!定時に帰る方法
sbtechnight
0
260
Amazon Comprehendで始める感情分析
46ta
0
210
やってみたLT会 Fleet Managerのススメ
yukiiiiikuma
PRO
0
420
テクニカルライティングの検定を受けてみた話 / "My Story About Taking the Technical Writing Exam
line_developers
PRO
1
240
Microsoft Azure を使い始める前に Azure Active Directory と Azure サブスクリプションの役割や関係性を正しく理解する
yoshiakioi
0
190
セキュリティ・キャンプ全国大会2022 企業紹介イベント/seccamp2022-nikkei
nikkei_engineer_recruiting
0
170
Goで実装するブランドネットワークとの接続ポイント
pongzu
2
300
聊聊 Cgo 的二三事
david74chou
0
350
今 SLI/SLO の監視をするなら Sloth が良さそうという話
shotakitazawa
1
300
S3Gateway型エンドポイントのありがたさに気づいた話
yukiiiiikuma
PRO
1
140
品質特性のすすめ
honamin09
0
190
Featured
See All Featured
Unsuck your backbone
ammeep
659
55k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
15
3.9k
Clear Off the Table
cherdarchuk
79
290k
The Brand Is Dead. Long Live the Brand.
mthomps
46
2.7k
Rails Girls Zürich Keynote
gr2m
87
12k
Music & Morning Musume
bryan
35
4.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
19
1.2k
It's Worth the Effort
3n
172
26k
Support Driven Design
roundedbygravity
87
8.6k
How STYLIGHT went responsive
nonsquared
85
4k
How GitHub (no longer) Works
holman
297
140k
What’s in a name? Adding method to the madness
productmarketing
11
1.6k
Transcript
$ go tool trace ͬͯΈΑ͏ גࣜձࣾωΫετΧϨϯγʔ @nametake
ࣗݾհ
@nametake
Goྺ1ͪΐͬͱ
ύϑΥʔϚϯεܭଌ
runtime/pprof net/http/pprof
package main import ( "log" "net/http" _ "net/http/pprof" "runtime" )
func main() { runtime.SetBlockProfileRate(1) log.Println( http.ListenAndServe("0.0.0.0:6060", nil), ) }
localhost:6060/debug/pprof/
None
None
None
None
None
$ go tool trace
None
͍ํઆ໌
runtime/trace
package main import ( "os" "runtime/trace" ) func main() {
f, err := os.Create("trace.out") if err != nil { panic(err) } defer f.Close() err = trace.Start(f) if err != nil { panic(err) } defer trace.Stop() }
$ go tool trace trace.out
ϑΝΠϧॻ͖ࠐΈ
f, err := os.Create("test.txt") if err != nil { panic(err)
} defer f.Close() for i := 0; i < 100; i++ { fmt.Fprintf(f, "line number: %d\n", i) }
None
ॲཧ࣌ؒ
ॲཧ࣌ؒ
ϓϩάϥϜ͕֬อͨ͠ώʔϓྖҬ
goroutineͷͱ࣮ߦ࣌ؒ
OSͷThreadͷͱ࣮ߦ࣌ؒ
Proc(CPU)Ͱॲཧ͍ͯ͠Δ༰
ͳΜ͔৭ʑͳใ
Goݴޠ ׂΓͱؾܰʹ syscallΛݺͿ
None
syscallͷݺͼग़͠
ͱ͍ͯ͋͠
syscallΛݺΜͰΔ
f, err := os.Create("test.txt") if err != nil { panic(err)
} defer f.Close() for i := 0; i < 100; i++ { fmt.Fprintf(f, "line number: %d\n", i) }
f, err := os.Create("test.txt") if err != nil { panic(err)
} defer f.Close() for i := 0; i < 100; i++ { fmt.Fprintf(f, "line number: %d\n", i) }
bufio
f, err := os.Create("test.txt") if err != nil { panic(err)
} defer f.Close() w := bufio.NewWriter(f) defer w.Flush() for i := 0; i < 100; i++ { fmt.Fprintf(w, "line number: %d\n", i) }
None
None
None
None
None
GUIͰ֬ೝग़དྷΔʂ
GC
None
GC
None
GCຖʹ֬อ͍ͯ͠͠Δ
n := 400000 list := []int{} for i := 0;
i < n; i++ { list = append(list, i) }
n := 400000 list := []int{} for i := 0;
i < n; i++ { list = append(list, i) }
n := 400000 list := make([]int, n) for i :=
0; i < n; i++ { list[i] = i }
None
GC͕ൃੜ͍ͯ͠ͳ͍
࠷ॳʹΨοπϦྖҬ֬อ
6ms → 2ms
ฒྻԽ
https://making.pusher.com/go-tool-trace/ Connʹॻ͖ࠐΈ
https://making.pusher.com/go-tool-trace/ ͜ͷ෦Ͱॻ͖ࠐΜͰ͍Δ
https://making.pusher.com/go-tool-trace/
https://making.pusher.com/go-tool-trace/ ଞͷϓϩηεͬͯͳ͍
https://making.pusher.com/go-tool-trace/
https://making.pusher.com/go-tool-trace/
https://making.pusher.com/go-tool-trace/ CPUΛແବͳ͘ར༻
͍Ζ͍ΖΘ͔Δ
શ෦ͷ͕ Θ͔ΔΘ͚Ͱͳ͍
CPUͷ༻ pprofͱ͔Λ ݟͨ΄͏͕͍͍
ϓϩάϥϜͷ ྲྀΕΛΔ
ͱΓ͋͑ͣ ݟͯΈΔ͚ͩͰ ͍͍͔
go traceͷ͜ͱɺ ࣌ʑͰ͍͍͔Β……ɹ ࢥ͍ग़͍ͯͩ͘͠͞