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
今から、 今だからこそ始める Terraform で Azure 管理 / Managing Azure with Terraform: The Perfect Time to Start
nnstt1
0
240
ABWGのRe:Cap!
hm5ug
1
120
2025年のARグラスの潮流
kotauchisunsun
0
800
新卒1年目、はじめてのアプリケーションサーバー【IBM WebSphere Liberty】
ktgrryt
0
130
WantedlyでのKotlin Multiplatformの導入と課題 / Kotlin Multiplatform Implementation and Challenges at Wantedly
kubode
0
250
CDKのコードレビューを楽にするパッケージcdk-mentorを作ってみた/cdk-mentor
tomoki10
0
210
.NET 最新アップデート ~ AI とクラウド時代のアプリモダナイゼーション
chack411
0
200
RubyでKubernetesプログラミング
sat
PRO
4
160
Goで実践するBFP
hiroyaterui
1
120
完全自律型AIエージェントとAgentic Workflow〜ワークフロー構築という現実解
pharma_x_tech
0
350
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
170
re:Invent 2024のふりかえり
beli68
0
110
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
96
5.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Gamification - CAS2011
davidbonilla
80
5.1k
Agile that works and the tools we love
rasmusluckow
328
21k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
19
2.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Adopting Sorbet at Scale
ufuk
74
9.2k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
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ΛྲྀߦΒ͍ͤͯ͜͏
͋Γ͕ͱ͏͍͟͝·ͨ͠