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.4k
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
パッケージ設計の黒魔術/Kyoto.go#63
lufia
3
440
最近変わった開発時のあれこれ/features-of-recent-go
lufia
0
890
GCPとGoの話/gcpug-osaka-6
lufia
0
500
調べながらGCPやってみた話/gcpug-osaka-3
lufia
1
500
REST is not only (web) API interface
lufia
1
990
Other Decks in Technology
See All in Technology
Apache Spark もくもく会
taka_aki
0
140
AWSを利用する上で知っておきたい名前解決のはなし(10分版)
nagisa53
10
3.2k
Modern Linux
oracle4engineer
PRO
0
160
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
10
75k
Unlocking the Power of AI Agents with LINE Bot MCP Server
linedevth
0
120
EncryptedSharedPreferences が deprecated になっちゃった!どうしよう! / Oh no! EncryptedSharedPreferences has been deprecated! What should I do?
yanzm
0
490
2025/09/16 仕様駆動開発とAI-DLCが導くAI駆動開発の新フェーズ
masahiro_okamura
0
140
【NoMapsTECH 2025】AI Edge Computing Workshop
akit37
0
230
「何となくテストする」を卒業するためにプロダクトが動く仕組みを理解しよう
kawabeaver
0
440
Oracle Cloud Infrastructure IaaS 新機能アップデート 2025/06 - 2025/08
oracle4engineer
PRO
0
110
「全員プロダクトマネージャー」を実現する、Cursorによる仕様検討の自動運転
applism118
22
12k
株式会社ログラス - 会社説明資料【エンジニア】/ Loglass Engineer
loglass2019
4
65k
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
530
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
RailsConf 2023
tenderlove
30
1.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
YesSQL, Process and Tooling at Scale
rocio
173
14k
Designing for Performance
lara
610
69k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
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ΛྲྀߦΒ͍ͤͯ͜͏
͋Γ͕ͱ͏͍͟͝·ͨ͠