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
Golang @ISUCON
Search
y_matsuwitter
November 30, 2014
Programming
10
4.2k
Golang @ISUCON
GoCon 2014 Autmun
y_matsuwitter
November 30, 2014
Tweet
Share
More Decks by y_matsuwitter
See All by y_matsuwitter
Building Products in the LLM Era
ymatsuwitter
10
5.4k
Product Utilization of Large Language Models Starting Today
ymatsuwitter
3
2.5k
経営・意思・エンジニアリング
ymatsuwitter
23
19k
LLM in 2023 and 2024
ymatsuwitter
8
5.5k
Turbulent Technological Changes and Career Strategies
ymatsuwitter
2
2.6k
LLM in toB Service and Its UX
ymatsuwitter
7
10k
Agent and small LLM validation
ymatsuwitter
7
2.9k
Information management for a culture of speed: The story of Notion and LayerX
ymatsuwitter
4
9.9k
Monorepo on AWS
ymatsuwitter
0
290
Other Decks in Programming
See All in Programming
Formの複雑さに立ち向かう
bmthd
1
850
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
900
CI改善もDatadogとともに
taumu
0
120
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
250
仕様変更に耐えるための"今の"DRY原則を考える / Rethinking the "Don't repeat yourself" for resilience to specification changes
mkmk884
0
160
Ruby on cygwin 2025-02
fd0
0
140
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
750
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
320
ARA Ansible for the teams
kksat
0
150
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
120
時計仕掛けのCompose
mkeeda
1
300
Pulsar2 を雰囲気で使ってみよう
anoken
0
240
Featured
See All Featured
Building Applications with DynamoDB
mza
93
6.2k
Rails Girls Zürich Keynote
gr2m
94
13k
Writing Fast Ruby
sferik
628
61k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
133
33k
Practical Orchestrator
shlominoach
186
10k
Site-Speed That Sticks
csswizardry
4
380
The Language of Interfaces
destraynor
156
24k
Side Projects
sachag
452
42k
BBQ
matthewcrist
87
9.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Bash Introduction
62gerente
611
210k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Transcript
Golang @ISUCON y_matsuwitter
!Z@NBUTVXJUUFS Gunosy inc., ࣥߦһ ! Goྺ1ऑ͘Β͍ ! όϥϯεϘʔϧਖ਼࠲ͷਓ
ීஈͷۀ GoʹΑΔAPIαʔόߏங (2014.3~) iOS/AndroidͷΞϓϦ։ൃ Django/RailsʹΑΔWebApp։ൃ
ʊਓਓਓਓਓਓਓਓਓਓਓਓਓʊ ʼɹGolangΤϯδχΞืूதɹʻ ʉY^Y^Y^Y^Y^Y^Y^Y^Y^Yʉ
ࠓͷ ॳΊͯͷISUCONΛGolangͰઓͬͯΈͨ ※GolangҎ֎ͷ͠·ͤΜ Ґͱத్ͳ݁ՌͰ͕ͨ͠ʜ
ISUCONͱ Iikanjini Speed Up CONtest ! 8࣌ؒͰ༩͑ΒΕͨWebAppΛग़དྷΔݶΓߴ Խ͢Δίϯςετ
༧બ αʔό: 1 େMySQLΛDB ࠓۜߦͷϩάΠϯϖʔδ͕ࡐͰͨ͠
ܾউ αʔό: 3~4 ը૾ॲཧಈըͷ৴ͳͲ͋Δఔෛՙͷߴ ͍ॲཧΛؚΉWebApp ࠓಈըࠂͷ৴αʔόͰͨ͠
ߴͳWebαʔόͷͨΊʹ ϦιʔεΛ͍Δ CPU … Encode/decode, ը૾ॲཧͳͲ Memory … ϓϩηε্ͷσʔλྔ Data
Transfer … αʔόؒɺαʔόΫϥΠΞϯτؒͷ૯௨৴ྔ ! ͦͷ্ͰదͳॲཧʹϦιʔεΛׂΓͯΔ
ݴޠੑೳ ܾఆతͳࠩʹͳΒͳ͍
Why Go? վળͷޮͷߴ͞ - ߏจ͕SimpleͳͨΊ࣌ؒͷνʔϜ։ൃ͖ - ฒྻɾฒߦॲཧͰͷϝϞϦपΓͷѻָ͍͕ - σϓϩΠָ͕ -
ඪ४ύοέʔδ͕ඇৗʹ࣮༻త
औΓΜͩ͜ͱ 1. ϓϩηεΩϟογϡ 2. λεΫࢄॲཧ
ϓϩηεΩϟογϡ σʔλΛϓϩηε্ʹશͯอ͓࣋ͯ͘͠ ! ӬଓԽదͳλΠϛϯάͰRedisʹอଘͳ ΓϑΝΠϧʹdumpͳΓ͢Δ
߹ੑ વɺෳͷGoroutine͔ΒಡΈॻ͖͞ΕΔ ͨΊͷ߹ੑΛอূ͢Δඞཁ͕͋Δ
Race Condition ڝ߹͢Δมૢ࡞Λߦ͏ͱෆ҆ఆͳڍಈ Goroutine·͍ͨͰڞ༗ͷΛಡΈॻ͖͢Δ ࡍrace conditionΛආ͚ΔͨΊLock͕ඞཁ
sync ֤छͷϩοΫΛѻ͏ύοέʔδ ! sync.RWMutex - ReadΛWriteͰϩοΫϨϕϧΛͨ͠Lock sync/atomic - ΧϯλͳͲͷॲཧΛ࡞Δͷʹॏๅ
atomic.Value from golang1.4 ! ϓϩηε্ʹatomicʹσʔλߋ৽Ͱ͖Δετ Ξͱͯ͠ઃܭ͞Ε͍ͯ·͢
None
ಡΈࠐΈଆ7BMVF͔Β-PBE
ॻ͖ࠐΈଆ-PDLऔͬͨ͋ͱ 7BMVFʹ4UPSF
λεΫͷࢄॲཧ ཁ݅ - ॲཧʹ͔͔࣌ؒΔͷΛඇಉظɺ͔ͭฒߦ࣮ߦ Λ੍ݶ࣮ͯ͠ߦ͍ͨ͠ ! - ը૾ɾಈըͳͲॏෳͯ͠ॲཧͨ͘͠ͳ͍
Task Queueing capacity͖ͷchannelΛ͏ goroutine͕ͦͷ··workerతʹ͑Δ
None
ॏෳॲཧΛආ͚Δ ྫ͑ը૾ॲཧதʹɺͦͷը૾Λऔಘ͠ʹདྷ ΔϦΫΤετΛfailͤͯ͞ͳΒͳ͍ ! ͔͠͠ɺऔಘ࣌ʹॏෳॲཧ͕࣌ؒମແ͍
αʔό͕1ͷ߹
sync.Cond ॲཧதͷͷΛબతʹͭ
None
αʔό͕ෳͷ࣌
y-matsuwitter/mcond ෳͷαʔόؒͰsync.CondΛѻ͑ΔΑ͏ ʹͨ͠ͷ ! Redis + net/httpΛར༻
ೋͷαʔόͰͷmcond
ॲཧଆ ಡΈࠐΈଆ
ॲཧઌΛৼΓ͚Δ
stathat/consistent ίϯγεςϯτϋογϡϥΠϒϥϦ ! Ұఆͷ໊લʹରͯ͠ඞͣಉ͡ॲཧઌΛܾఆ ࠓճଳҬΛ͍௵ͨ͢Ίෳͷwebdav αʔόʹৼΓ͚Δ༻్Ͱར༻
None
ͪͳΈʹ ഊҼCache-Control HeaderͰͨ͠ IUUQTTV[VSJKQZ@NBUTVXJUUFSUTIJSUNCMBDL
࠷ޙʹ
ProductionͰ͓͏
None
ࢀߟ ඪ४ύοέʔδ http://golang.org/pkg/ go1.4 http://tip.golang.org/doc/go1.4 mcond https://github.com/y-matsuwitter/mcond consistent https://github.com/stathat/consistent