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
830
GCPとGoの話/gcpug-osaka-6
lufia
0
490
調べながらGCPやってみた話/gcpug-osaka-3
lufia
1
470
REST is not only (web) API interface
lufia
1
930
Other Decks in Technology
See All in Technology
Visual StudioとかIDE関連小ネタ話
kosmosebi
1
370
AWSサービスアップデート 2024/12 Part3
nrinetcom
PRO
0
140
Azureの開発で辛いところ
re3turn
0
240
技術に触れたり、顔を出そう
maruto
1
140
comilioとCloudflare、そして未来へと向けて
oliver_diary
6
440
Goで実践するBFP
hiroyaterui
1
120
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
840
データ基盤におけるIaCの重要性とその運用
mtpooh
3
380
JAWS-UG20250116_iOSアプリエンジニアがAWSreInventに行ってきた(真面目編)
totokit4
0
140
商品レコメンドでのexplicit negative feedbackの活用
alpicola
1
340
PaaSの歴史と、 アプリケーションプラットフォームのこれから
jacopen
7
1.3k
ドメイン駆動設計の実践により事業の成長スピードと保守性を両立するショッピングクーポン
lycorptech_jp
PRO
9
860
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
34
1.6k
Become a Pro
speakerdeck
PRO
26
5.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Docker and Python
trallard
43
3.2k
Code Reviewing Like a Champion
maltzj
521
39k
For a Future-Friendly Web
brad_frost
176
9.5k
A designer walks into a library…
pauljervisheath
205
24k
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ΛྲྀߦΒ͍ͤͯ͜͏
͋Γ͕ͱ͏͍͟͝·ͨ͠