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
Product Utilization of Large Language Models Starting Today
ymatsuwitter
3
2.2k
経営・意思・エンジニアリング
ymatsuwitter
23
19k
LLM in 2023 and 2024
ymatsuwitter
8
5.3k
Turbulent Technological Changes and Career Strategies
ymatsuwitter
2
2.6k
LLM in toB Service and Its UX
ymatsuwitter
6
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.7k
Monorepo on AWS
ymatsuwitter
0
270
Tech behind LayerX SaaS products
ymatsuwitter
0
3k
Other Decks in Programming
See All in Programming
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
선언형 UI에서의 상태관리
l2hyunwoo
0
140
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
Go の GC の不得意な部分を克服したい
taiyow
2
770
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
130
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
370
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
たのしいparse.y
ydah
3
120
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Into the Great Unknown - MozCon
thekraken
33
1.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Being A Developer After 40
akosma
87
590k
How STYLIGHT went responsive
nonsquared
95
5.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
97
Optimising Largest Contentful Paint
csswizardry
33
3k
Automating Front-end Workflow
addyosmani
1366
200k
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