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
Go駆動開発で超速Pushエンジンを作った話
Search
kadota kyohei
May 31, 2014
Technology
19
7.3k
Go駆動開発で超速Pushエンジンを作った話
Go Conference 2014 spring で発表した資料。
受託開発に持ち込んだ事例紹介。
http://connpass.com/event/6370/
kadota kyohei
May 31, 2014
Tweet
Share
More Decks by kadota kyohei
See All by kadota kyohei
最近変わった開発時のあれこれ/features-of-recent-go
lufia
0
810
GCPとGoの話/gcpug-osaka-6
lufia
0
490
調べながらGCPやってみた話/gcpug-osaka-3
lufia
1
460
REST is not only (web) API interface
lufia
1
930
Other Decks in Technology
See All in Technology
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
2024年にチャレンジしたことを振り返るぞ
mitchan
0
140
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
190
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
3
310
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
ハイテク休憩
sat
PRO
2
160
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
110
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
4 Signs Your Business is Dying
shpigford
181
21k
How GitHub (no longer) Works
holman
311
140k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Music & Morning Musume
bryan
46
6.2k
Designing Experiences People Love
moore
138
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
A better future with KSS
kneath
238
17k
The Cult of Friendly URLs
andyhume
78
6.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Transcript
Goۦಈ։ൃͰPushΤϯδϯΛ࡞ͬͨ @plan9user GoCon 2014 spring
GoΛ͍͍ͨҰ৺Ͱडୗۀ࣋ͪࠐΜͩ࣌ͷ
ࣗݾհ • ଟګฏ • झຯ”Plan 9”Ͱ͢ʂ • Go͖ͳΒPlan 9ͷࢥΉͣ •
2011͔ΒϑΣϯϦϧͰಇ͍ͯ·͢
• ͜ͳ͍ͩSleipnir 6͕ग़·ͨ͠ʂ • ڞಉ։ൃ෦ • اۀ༷͔Βͷडୗ։ൃΛߦ͏෦ॺ • ࣮հ -
http://biz.fenrir-inc.com • Sleipnirͷ͝ҙݟެࣜαΠτ͔Β ϑΣϯϦϧגࣜձࣾ
• εϚʔτϑΥϯΞϓϦ։ൃͬͯ·͢ • iOS, Android • Windows 8 (एׯ) •
ࡢ͋ͨΓ͔ΒXamarin͡Ί·ͨ͠ ۀ༰
go? • ϓογϡ௨ • ࠃαʔϏεͰͳ͚Ε×ɹͱ͔ • ࣗͰશମΛίϯτϩʔϧ͍ͨ͠ɹͱ͔ • ങ͍Γ͍ͨɹͱ͔
push௨ͷ͘͠Έ 1. ΞϓϦτʔΫϯΛαʔόʹૹ৴ 2. αʔόอଘ͍ͯ͠ΔτʔΫϯͱϝοηʔδ Ληοτʹͯ͠APNs/GCMૹ৴ 3. ϝοηʔδ͕֤ಧ͘ ܾͯ͘͠͠ͳ͍Μ͚ͩͲ…
• ࠷ॳPHPͰ࣮ • ਫ४Λຬͨͤͳ͍ • ेສ௨ʹ͑ΒΕͳ͍ • ઃܭ͕·͔ͣͬͨ • PHPѱ͘ͳ͍
performance problems… ඵ ඵ ඵ ඵ ඵ ສ ສ ສ ສ
ͩΊͩͬͨͱ͜Ζ
problem? • PHPͳͷͰฒྻԽ͕͔ͬͨ͠ • ೋॏૹ৴ࢭͷͨΊDBΛΩϡʔʹ͍ͯͨ͠ • ௨৴ΤϥʔͰϦτϥΠ͖͢߹్த Ͱམͪͨ߹Λఆ • ྃϚʔΫDBʹ͍࣋ͬͯͨ
goal? • ॲཧͷͪ࣌ؒΛͳͯ͘͠ੑೳΛ্͛Δ • ͕ଟ͍ͱ͖ࢄͯ͠ૹ৴͢Δ • ෳϚγϯͰͻͱͭͷγεςϜʹ͢Δ • DBͷґଘΛͳ͘͢
͓ʁ
͜ΕGoͷग़൪͡ΌͶʁ
GoΛΉཧ༝(࣌) • Rob PikeRuss Cox͕ࢀՃͯ͠Δ • Plan 9ʹؔΘ͓ͬͯΒΕ·ͨ͠ • Alef,
Limbo͔Βଓ͘CSPྑ͍ • ඪ४ύοέʔδॆ࣮ͯͦ͠͏(งғؾ)
GoͱXamarinಉ࣌ೖܾఆ • Α͘௨ͬͨͳͱࢥ͍·͢… • ӡ͕ྑ͘ظؒݶఆͷΞϓϦͩͬͨ • ظӡ༻ͳΒอकߟ͑Δඞཁ͕͋Δ • ։ൃظ͕ؒൺֱత͘औΕͨ •
࠷ॳௐͳ͕Βॻ͘ͷͰޮѱ͍
GoͰॻ͘ʂ
overview GSPOU GSPOU DUMS BHFOU BHFOU BHFOU rpcଓ ϊʔυ(ϓϩηε)
net/rpcύοέʔδ // ܾ·ͬͨܗͷϝιουΛΤΫεϙʔτ͓͍ͯͯ͠ fund (agent *Agent) Broadcast(r *Request, res *Response)
error { return nil } ! // ผͷϊʔυ͔ΒrpcΛίʔϧ͢Δ c, _ := rpc.Dial(“net”, “localhost:17030”) err := c.Call(“Broadcast”, r, &res)
front GSPOU GSPOU DUMS BHFOU BHFOU BHFOU rpcଓ ϊʔυ(ϓϩηε)
front • Ҋ݅ݻ༗ͷϩδοΫΛ୲ • ΄ͱΜͲ͕JSONΛड৴ͯ͠ɺctlrϦΫΤετૹ৴ • Ҋ݅ݻ༗ͷϩδοΫͳͷͰ࣮͢Δ • DBؔͷॲཧ͜ͷϊʔυ͕ରԠ͢Δ
controller GSPOU GSPOU DUMS BHFOU BHFOU BHFOU rpcଓ ϊʔυ(ϓϩηε)
controller • front͔ΒͷrpcϦΫΤετΛड͚͚Δϊʔυ • ෳͷΤʔδΣϯτΛཧ͢Δ • 1ϦΫΤετͷ௨͕ଟ͗͢Δ߹ෳ ΤʔδΣϯτׂసૹ • ΤʔδΣϯτͷબผۭ͍͍ͯΔͷΛબͿ
*
։͍͍ͯΔagentΛબ // ϦΫΤετ༻νϟωϧΛ1ຊ͚ͩ༻ҙ req := make(chan *Request, bufSize) ! //
ཧ͢ΔϊʔυɺϦΫΤετ༻νϟωϧ͔Βड৴͢ΔΰϧʔνϯΛىಈ͓ͯ͘͠ for agent := range agents { go func(c chan *Request){ _ = <-c }(req) } ! // νϟωϧʹϦΫΤετΛ͛Δͱػ͍ͯ͠ΔΰϧʔνϯͷͲΕ͔͕र͏ select { case req <- newReq: …. case <-time.After(timeoutInterval): …
agent GSPOU GSPOU DUMS BHFOU BHFOU BHFOU rpcଓ ϊʔυ(ϓϩηε)
• ίϯτϩʔϥ͔ΒͷϦΫΤετΛ࣮ࡍʹ APNs/GCMૹ৴͢Δ • ෳϦΫΤετՄೳͳΒ1ͭʹ·ͱΊΔ * agent
ෳ·ͱΊͯૹ৴ que := make(chan *Message, bufSize) … // ctlr͔ΒͷϦΫΤετड৴ req
:= <-que msgs = append(msgs, req) for len(que) > 0 { msgs = append(msgs, <-que) } conn.WriteMessages(msgs)
ੑೳଌఆ
ੑೳଌఆ • ࣮ࡍͷAPNs/GCMΛͬͯੑೳࢼݧ͍͠ • ࢼݧʹ͑͏ΔྔͷΛ͍࣋ͬͯͳ͍ • GCM1ສ݅ૹΔͱInternalServerError • Fake APNs/GCMΛ࡞ͬͯϕϯνϚʔΫ
• গͳ͘ͱલճΑΓྑ͘ͳͬͨͷ͔͔Δ
ςετίʔυ // ςετ༻Fake APNsαʔό(ຊgateway.push.apple.com:2195)Λىಈ s := apnstest.NewServer(func(w io.Writer, msg *apns.Message)
{ // wʹԿ͔Write͢ΕΤϥʔͱͯ͠ΫϥΠΞϯτʹฦ͢ // Կ͠ͳ͚Εਖ਼ৗʹ௨ྃ }) cli := NewClient(s.Addr) msg := newMessage() ! que := make([]<-chan error, b.N) for i := 0; i < b.N; i++ { que[i] = cli.Go(msg) }
result. • ฒྻʹΑΔ͕10ʙ 30ඵͰεέʔϧ͢Δ Α͏ʹͳͬͨ • άϥϑ15ฒྻఔ • 2ʙ300ສ͋ͨΓͳΒ ͓ͦΒ͘ಉ͡ఔ
ඵ ඵ ඵ ඵ ඵ ສ ສ ສ ສ 1)1൛ (P൛
डୗ։ൃͱGo
• डୗ։ൃͷ߹ɺGoಋೖ͘͠Έ͑Δ • ٕज़ऀ͕গͳ͍ • نͷେ͖ͳ։ൃʹ͑ΒΕͳ͍ • 2ޙ3ޙαϙʔτ͞Ε͍ͯΔ͔ෆಁ໌ • ࣮͕গͳ͍
Goͬͯେৎʁ
• ڥߏங͕؆୯ • όΠφϦ͚ͩͰಈ࡞͢Δ ˠຊ൪ڥͰϥΠϒϥϦཧ͕ෆཁ • WindowsͰLinuxͰಈ࡞͢Δ • ࠓྲྀߦΔݴޠʹϊϛωʔτ •
ྲྀߦͬͨࠒʹࣗຫͰ͖Δɺ͔ʁ ͚ͩͲϝϦοτ
GoͰྑ͔ͬͨ͜ͱ͋ͬͯ Go͔ͩΒࠔͬͨ͜ͱແ͍ डୗͰGoΛྲྀߦΒ͍ͤͯ͜͏
͋Γ͕ͱ͏͍͟͝·ͨ͠