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
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
150
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
830
Storage Browser for Amazon S3
miu_crescent
1
130
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
120
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
.NET 9 のパフォーマンス改善
nenonaninu
0
500
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
1
230
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
420
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
生成AIのガバナンスの全体像と現実解
fnifni
1
180
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
520
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
328
21k
GraphQLとの向き合い方2022年版
quramy
44
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Six Lessons from altMBA
skipperchong
27
3.5k
Visualization
eitanlees
146
15k
Become a Pro
speakerdeck
PRO
26
5k
Making Projects Easy
brettharned
116
5.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Designing for humans not robots
tammielis
250
25k
Music & Morning Musume
bryan
46
6.2k
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ΛྲྀߦΒ͍ͤͯ͜͏
͋Γ͕ͱ͏͍͟͝·ͨ͠