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.6k
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
950
Container Build Talk
orisano
3
2.4k
dockerignore talk
orisano
2
6.9k
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.3k
Other Decks in Technology
See All in Technology
Lexical Analysis
shigashiyama
1
150
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
心が動くエンジニアリング ── 私が夢中になる理由
16bitidol
0
100
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
320
AGIについてChatGPTに聞いてみた
blueb
0
130
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
210
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
170
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.3k
Done Done
chrislema
181
16k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Building Adaptive Systems
keathley
38
2.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Docker and Python
trallard
40
3.1k
Why Our Code Smells
bkeepers
PRO
334
57k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Bash Introduction
62gerente
608
210k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
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Λ͛Δ
͜Μͳʹ ύϑΥʔϚϯενϡʔχϯά ͍͢͠ݴޠଞʹͳ͍
͍ͬͯ͜͏
ඞཁΛײ͡Δ·Ͱ νϡʔχϯά͠ͳ͍
Ͱ ܭଌ͕Ͱ͖Δڥ༻ҙ͖͢