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
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
32k
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
17
13k
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
UI State設計とテスト方針
rmakiyama
2
620
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
190
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
550
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
110
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
180
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
270
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Visualization
eitanlees
146
15k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Building Adaptive Systems
keathley
38
2.3k
Speed Design
sergeychernyshev
25
670
Thoughts on Productivity
jonyablonski
67
4.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.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Λ͛Δ
͜Μͳʹ ύϑΥʔϚϯενϡʔχϯά ͍͢͠ݴޠଞʹͳ͍
͍ͬͯ͜͏
ඞཁΛײ͡Δ·Ͱ νϡʔχϯά͠ͳ͍
Ͱ ܭଌ͕Ͱ͖Δڥ༻ҙ͖͢