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
960
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.3k
Other Decks in Technology
See All in Technology
Amazon VPC Lattice 最新アップデート紹介 - PrivateLink も似たようなアップデートあったけど違いとは
bigmuramura
0
190
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
330
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
110
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
520
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
100
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
260
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
300
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
Featured
See All Featured
Speed Design
sergeychernyshev
25
670
The Cult of Friendly URLs
andyhume
78
6.1k
Become a Pro
speakerdeck
PRO
26
5k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Documentation Writing (for coders)
carmenintech
66
4.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
The Invisible Side of Design
smashingmag
298
50k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Mobile First: as difficult as doing things right
swwweet
222
9k
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Λ͛Δ
͜Μͳʹ ύϑΥʔϚϯενϡʔχϯά ͍͢͠ݴޠଞʹͳ͍
͍ͬͯ͜͏
ඞཁΛײ͡Δ·Ͱ νϡʔχϯά͠ͳ͍
Ͱ ܭଌ͕Ͱ͖Δڥ༻ҙ͖͢