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.8k
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
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
The Role of Developer Relations in AI Product Success.
giftojabu1
0
120
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
いざ、BSC討伐の旅
nikinusu
2
780
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Platform Engineering for Software Developers and Architects
syntasso
1
510
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Practical Orchestrator
shlominoach
186
10k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
YesSQL, Process and Tooling at Scale
rocio
169
14k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
KATA
mclloyd
29
14k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Rails Girls Zürich Keynote
gr2m
94
13k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
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Λ͛Δ
͜Μͳʹ ύϑΥʔϚϯενϡʔχϯά ͍͢͠ݴޠଞʹͳ͍
͍ͬͯ͜͏
ඞཁΛײ͡Δ·Ͱ νϡʔχϯά͠ͳ͍
Ͱ ܭଌ͕Ͱ͖Δڥ༻ҙ͖͢