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
Profiling Go Application
Search
orisano
November 25, 2018
Technology
11
7.7k
Profiling Go Application
orisano
November 25, 2018
Tweet
Share
More Decks by orisano
See All by orisano
OSS Performance Tuning Tips
orisano
8
5.6k
Docker-Compose & BuildKit
orisano
4
970
Container Build Talk
orisano
3
2.4k
dockerignore talk
orisano
2
7k
Better docker image+
orisano
6
5.9k
Socket.IO Introduction
orisano
0
3k
Multi-stage Builds Patterns & Practice
orisano
6
5k
better docker image
orisano
22
30k
the world of characters
orisano
8
1.4k
Other Decks in Technology
See All in Technology
Amazon Route 53, 待ちに待った TLSAレコードのサポート開始
kenichinakamura
0
150
デジタルアイデンティティ技術 認可・ID連携・認証 応用 / 20250114-OIDF-J-EduWG-TechSWG
oidfj
2
610
Godot Engineについて調べてみた
unsoluble_sugar
0
370
JuliaTokaiとJuliaLangJaの紹介 for NGK2025S
antimon2
1
110
Alignment and Autonomy in Cybozu - 300人の開発組織でアラインメントと自律性を両立させるアジャイルな組織運営 / RSGT2025
ama_ch
1
2.3k
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
440
embedパッケージを深掘りする / Deep Dive into embed Package in Go
task4233
1
200
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
840
東京Ruby会議12 Ruby と Rust と私 / Tokyo RubyKaigi 12 Ruby, Rust and me
eagletmt
3
850
あなたの人生も変わるかも?AWS認定2つで始まったウソみたいな話
iwamot
3
830
いま現場PMのあなたが、 経営と向き合うPMになるために 必要なこと、腹をくくること
hiro93n
9
7.4k
技術に触れたり、顔を出そう
maruto
1
150
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
How GitHub (no longer) Works
holman
312
140k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
GraphQLとの向き合い方2022年版
quramy
44
13k
The Invisible Side of Design
smashingmag
299
50k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Making Projects Easy
brettharned
116
6k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
Transcript
Profiling Go Application Go Conference 2018 Autumn #gocon #gocon_a @orisano
ࣗݾհ • @orisano • ۦ͚ग़͠ΞϓϦέʔγϣϯΤϯδχΞ • ޮతͳdocker buildΛࢦ͍ͯ͠Δ • ύϑΥʔϚϯεʹڵຯ͕͋Δ
ࠓ͢͜ͱ • ߴԽ, ϓϩϑΝΠϦϯάΛߦ͖࣮ͬͯͨྫ • Ͳ͏͍͏վળΛ͢Δͷ͔ • Ͳ͏͍͏ϓϩηεͳͷ͔
ը૾มαʔόͷ kubeletͷ go-swaggerͷ
ը૾มαʔόͷ kubeletͷ go-swaggerͷ
ৄղ γεςϜɾύϑΥʔϚϯε ྠಡձ
ࡐͱͯ͠؆୯ͳ ը૾มαʔόΛѻͬͨ
ෛՙΛ͔͚Δͱ ΞϓϦέʔγϣϯ͕མͪͨ
topΛΈͨ
མͪͨݪҼ ϝϞϦͷ༻ྔ
ϝϞϦϦʔΫʁ
pprofΛ͏ GODEBUG=allocfreetrace=1 ͢Δ
runtimeʹखΛೖΕΔ
GC͍ͯ͠Δͱ͖ʹ ࢀরgraphΛdump͢ΔΑ͏ ʹͨ͠
None
ͪΌΜͱpprofͷmemory goroutineͷΛݟΔ
ಉ࣌มʹ੍ݶΛ͚ͭΔ
ແࣄղܾͨ͠
͋ͱߴԽ
disintegration/imaging
Boundary Check Elimination
GoجຊఴࣈΞΫηε͢Δͱ ൣғνΣοΫ͕ೖΔ
ίϯύΠϥ͕҆શͩͱ அ͢Δͱফ͑Δ
͜ΕΛ Boundary Check Elimination (BCE)ͱ͍͏
͜ΕΛ Boundary Check Elimination (BCE)ͱ͍͏ ref: https://go101.org/article/bounds-check-elimination.html
goͷඪ४ϥΠϒϥϦͰ ͦͦ͜͜ݟΔ
ը૾ͷಡΈࠐΈ, มͳͲ heavyʹఴࣈΞΫηε͢Δ ߹ͩͱޮՌ͕େ͖͍
https://github.com/ disintegration/imaging/ pull/81
https://github.com/ disintegration/imaging/ pull/81
None
pprofͳͲͰ ݪҼΛಛఆͨ͠Β
·ͣ BenchmarkΛॻ͜͏ *testing.B
Benchmarkͷ݁ՌΛ ͪΌΜͱݟΔ
golang.org/x/tools/cmd/ benchcmp golang.org/x/perf/cmd/ benchstat
https://github.com/ disintegration/imaging/ pull/81
ը૾มαʔόͷ kubeletͷ go-swaggerͷ
kubeletͷCPU͕ෛՙ͕ߴ͍ ͱ૬ஊΛड͚ͨ
Datadog͕ୟ͍ͯΔ Metrics༻ͷEndpoint͕ ݪҼͳͷͰͱ͍͏ͩͬͨ
kubeletnet/http/pprofΛ import͍ͯ͠Δ
͕ى͖͍ͯΔڥͷ ใ͕औͬͯ͜ΕΔ
None
prometheus/common google/cadvisor ͷҰ෦͕ॏ͍
None
֘Օॴ https://github.com/prometheus/ common/pull/148 ൃ֮ͷ1िؒલ͘Β͍ʹ allocation freeʹͳͬͯ 2ഒ͘Β͍ૣ͘ͳ͍ͬͯͨ
None
ͳΜ͔չ͔ͬͨ͠ͷͰ https://github.com/prometheus/ common/pull/150 ߋʹͦΕΛ2ഒ͘Β͍ૣ͘͠·ͨ͠
None
७ਮʹWrite͕ଟ͔ͬͨ
strings.Replacerʹ WriteString͕͋Γ·͢
ஔରՕॴҎ֎ ·ͱΊͯWriteͯ͘͠ΕΔ
allocationى͜Βͳ͍ͷͰ࠷ߴ
࣍ʹ
google/cadvisorͷ ListContainers͕ॏ͍
None
google/cadvisorͷ ListContainers͕ॏ͍ https://github.com/google/cadvisor/blob/8faf19092784b75fce10ce190d37e66f89de3612/container/common/helpers.go
ioutil.ReadDirͱsyscall ͕ॏ͍ʁ
ioutil.ReadDirͷதΛݟͯΈΔ
ref: https://golang.org/src/io/ioutil/ioutil.go
ref: https://golang.org/src/os/dir_unix.go
ͳΜ͔ҎԼʹ͋ΔϑΝΠϧશ෦ʹ lstatൃߦ͍ͯ͠Δ
ref: https://golang.org/src/os/dir_unix.go
readdirent͕ͬͯͭ͋Δ
Ͳ͏Β͜Ε entryͷtypeΛฦͯ͘͠ΕΔΒ͍͠
google/cadvisorͷ ListContainers͕ॏ͍ https://github.com/google/cadvisor/blob/8faf19092784b75fce10ce190d37e66f89de3612/container/common/helpers.go
readdirentΛ͏·͑͘Ε syscallͷճΛݮΒͤΔ
͔͠͠ golangඪ४ͷreaddirent typeΛऔಘͰ͖ͳ͍
͔͠ ࣮ʹඞཁͳॾʑ͕ privateʹͳ͍ͬͯΔ
ඪ४͔Βͦ͜Λίϐϖ͢Δͱ cadvisorͷ LICENSE Checkʹ௨Βͳ͍
࣮͜ͷํ๏ ͍ΖΜͳϥΠϒϥϦͰΘΕ͍ͯΔ goimports/internal/fastwalk ֎෦͔Βར༻Ͱ͖ͳ͍
ѹతʹ֎෦͔Βར༻Ͱ͖ͳ͍
github.com/karrick/godirwalk Α͏͘ݟ͚ͭͨ
https://github.com/google/ cadvisor/pull/2085
None
Memoryܥͷऔಘ͚ͩͨΒ͍
https://lkml.org/lkml/ 2018/7/3/101 cgroups v1ܥͷΒ͍͠ kernelͷversionΛ͋͛Α͏
ը૾มαʔόͷ kubeletͷ go-swaggerͷ
ࣗಈੜΛ݁ߏ͍ͬͯΔͷͰ͕͢
go-swagger͕͍
ૣ͘͠Α͏
cliܥͷϓϩϑΝΠϦϯάʹ pkg/profile͕ศར
None
https://github.com/go-openapi/ swag/pull/25
None
෦Ͱຖճ MustCompileͯͨ͠
None
https://github.com/go-openapi/ loads/pull/19
None
͍json.UnmarshalΛ deepcopyͷͨΊʹ2ճͯͨ͠
json.Unmarshal 1ճ {de,en}coding/gob Ͱ͓Λͨ͠
None
·ͱΊ
ීஈ͍ͬͯΔͷͰ ΧϦΧϦʹνϡʔχϯά ͞Ε͍ͯΔΘ͚Ͱͳ͍
͕͍ࣗͱײͨ͡Β ܭଌͯ͠ΈΔ վળͯ͠ΈΔ
cliͳΒpkg/profileΛࠐΜͰݟΔ
serverͳΒnet/http/pprofΛ͏
ݪҼͷಛఆͷखॿ͚ͷͨΊʹ svgʹͨ͠Γ uber/go-torchΛͬͯ flamegraphʹͨ͠Γ flamescopeΛͬͨΓ
ݪҼΛಛఆͨ͠Β BenchmarkΛॻ͘
-count=10ͳͲΛͬͨ͋ͱʹ benchcmp or benchstat ͯ͠ޮՌ͕ग़͍ͯΔ͜ͱΛ֬ೝ
͋ͱPRΛ͛Δ
͜Μͳʹ ύϑΥʔϚϯενϡʔχϯά ͍͢͠ݴޠଞʹͳ͍
͍ͬͯ͜͏
ඞཁΛײ͡Δ·Ͱ νϡʔχϯά͠ͳ͍
Ͱ ܭଌ͕Ͱ͖Δڥ༻ҙ͖͢