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.1k
Golang @ISUCON
GoCon 2014 Autmun
y_matsuwitter
November 30, 2014
Tweet
Share
More Decks by y_matsuwitter
See All by y_matsuwitter
Product Utilization of Large Language Models Starting Today
ymatsuwitter
3
2.1k
経営・意思・エンジニアリング
ymatsuwitter
23
19k
LLM in 2023 and 2024
ymatsuwitter
8
5.2k
Turbulent Technological Changes and Career Strategies
ymatsuwitter
2
2.5k
LLM in toB Service and Its UX
ymatsuwitter
6
9.9k
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.6k
Monorepo on AWS
ymatsuwitter
0
260
Tech behind LayerX SaaS products
ymatsuwitter
0
3k
Other Decks in Programming
See All in Programming
ヤプリ新卒SREの オンボーディング
masaki12
0
130
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
Ethereum_.pdf
nekomatu
0
460
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Featured
See All Featured
Side Projects
sachag
452
42k
Building Adaptive Systems
keathley
38
2.3k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
We Have a Design System, Now What?
morganepeng
50
7.2k
Statistics for Hackers
jakevdp
796
220k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
A Philosophy of Restraint
colly
203
16k
The World Runs on Bad Software
bkeepers
PRO
65
11k
What's in a price? How to price your products and services
michaelherold
243
12k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Raft: Consensus for Rubyists
vanstee
136
6.6k
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