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
11
8.2k
Product Utilization of Large Language Models Starting Today
ymatsuwitter
3
2.6k
経営・意思・エンジニアリング
ymatsuwitter
23
20k
LLM in 2023 and 2024
ymatsuwitter
8
5.6k
Turbulent Technological Changes and Career Strategies
ymatsuwitter
2
2.7k
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
10k
Monorepo on AWS
ymatsuwitter
0
300
Other Decks in Programming
See All in Programming
ベクトル検索システムの気持ち
monochromegane
30
9.7k
Defying Front-End Inertia: Inertia.js on Rails
skryukov
0
420
AtCoder Heuristic First-step Vol.1 講義スライド(山登り法・焼きなまし法編)
takumi152
4
1k
SQL Server ベクトル検索
odashinsuke
0
150
家族・子育て重視/沖縄在住を維持しながらエンジニアとしてのキャリアをどのように育てていくか?
ug
0
260
AI時代のプログラミング教育 / programming education in ai era
kishida
23
22k
DataStoreをテストする
mkeeda
0
270
Fluent UI Blazor 5 (alpha)の紹介
tomokusaba
0
170
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
2.3k
Signal-Based Data FetchingWith the New httpResource
manfredsteyer
PRO
0
140
snacks.nvim内のセットアップ不要なプラグインを紹介 / introduce_snacks_nvim
uhooi
0
380
AI Coding Agent Enablement - エージェントを自走させよう
yukukotani
13
5.2k
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
75
9.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.5k
A Modern Web Designer's Workflow
chriscoyier
693
190k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7.1k
Facilitating Awesome Meetings
lara
53
6.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
31
4.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
102
19k
Site-Speed That Sticks
csswizardry
4
470
Typedesign – Prime Four
hannesfritz
41
2.6k
Six Lessons from altMBA
skipperchong
27
3.7k
It's Worth the Effort
3n
184
28k
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