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
MedPeer_JapaxTaxi_MeetUp_Actioncable
Search
pipopotamasu
April 26, 2018
0
480
MedPeer_JapaxTaxi_MeetUp_Actioncable
pipopotamasu
April 26, 2018
Tweet
Share
More Decks by pipopotamasu
See All by pipopotamasu
How JS Works
pipopotamasu
0
170
vue-function-tester
pipopotamasu
2
1.1k
Dive into vue-test-utils ~~Road of 1.0.0~~
pipopotamasu
0
88
medpacker_introduction_20190523
pipopotamasu
0
480
Introduction of medpacker: RoR Frontend Boilerplate
pipopotamasu
0
4.7k
新サービス・JOURNAL(ジャーナル)開発秘話
pipopotamasu
2
210
メドピアにおけるライブラリアップデート_MedBeer_20180912.pdf
pipopotamasu
0
12k
MedPeer X みんなのウェディング合同勉強会
pipopotamasu
0
1k
UXBridge_vol3_pipopotamasu
pipopotamasu
2
860
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Designing for Performance
lara
604
68k
What's in a price? How to price your products and services
michaelherold
244
12k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Visualization
eitanlees
146
15k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Making Projects Easy
brettharned
116
6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Transcript
UnicornͰActionCableΛ ͓͏ͱͯ͠ϋϚΓ͔͚ͨ͜ͱ ϝυϐΞגࣜձࣾ ΤϯδχΞ ଜ্ େ
self_introduce.json { “name”: “ଜ্େ”, “age”: 26, “github”: “pipopotamasu”, “company”: “ϝυϐΞגࣜձࣾ”,
“tech”: [“Ruby”, “PHP”, “Vue.js”, “React”], “hobby”: [“ٿ”, “өը”], }
https://jp.vuejs.org/v2/cookbook/ creating-custom-scroll-directives.html
http://tech.medpeer.co.jp/
None
※ ࠓJSͷ͠·ͤΜ
ͱ͍͏Θ͚ͰൃදςʔϚ
UnicornͰActionCableΛ ͓͏ͱͯ͠ϋϚΓ͔͚ͨ͜ͱ
͜͜Ͱ࣭ʂ
ීஈRailsͬͯΔਓ (´ɾωɾ`)ϊγ
ActionCableͬͯΔਓ (ɾωɾ)ϊγ
ActionCableͱ • RailsΞϓϦέʔγϣϯͰWebSocketΛ࣮ݱ͢ ΔͨΊͷϑϨʔϜϫʔΫ • Rails5.0͔Βಋೖ
WebSocketͱ • ΫϥΠΞϯτͱαʔόʔͷํ௨৴Λί ετͰ࣮ݱ͢ΔͨΊͷΈ
WebSocketͱ • ΫϥΠΞϯτͱαʔόʔͷํ௨৴Λί ετͰ࣮ݱ͢ΔͨΊͷΈ • νϟοτΞϓϦΛΠϝʔδ͢ΔͱΘ͔Γ͢ ͍
WebSocketͱ ΫϥΠΞϯτͱαʔόʔ ؒͰ Websocket༻௨৴(ίωΫγϣϯ)Λཱ֬
WebSocketͱ ϢʔβA͕νϟοτΞϓϦͰͭͿ͘ ͜ΜʹͪΘ
WebSocketͱ WebsocketͷίωΫγϣϯΛ௨ͯ͡ αʔό ͜ΜʹͪΘ
WebSocketͱ αʔό͔ΒίωΫγϣϯΛར༻ͯ͠ ଞͷϢʔβʹPush(σʔλΛૹ৴)͢Δ ͜ΜʹͪΘ
WebSocketͱ ϢʔβBίωΫγϣϯΛ௨ͯ͡Ϣʔβ AͷϝοηʔδΛड͚औΔɻ ͜ΜʹͪΘ
γʔϜϨεʹ σʔλ௨৴͕Ͱ͖Δ
WebSocket͡Όͳ͍߹
௨ৗͷHTTPϦΫΤετͷ߹ ϢʔβA͕νϟοτΞϓϦͰͭͿ͘ ͜ΜʹͪΘ
௨ৗͷHTTPϦΫΤετͷ߹ HTTPϦΫΤετͰαʔό (ͦͯ͠ϝοηʔδΛอଘ) ͜ΜʹͪΘ
௨ৗͷHTTPϦΫΤετͷ߹ ϢʔβB৽͍͠ϝοηʔδ͕ͳ͍͔ɺ HTTPϦΫΤετΛ͛Δ
௨ৗͷHTTPϦΫΤετͷ߹ ϢʔβB৽͍͠ϝοηʔδ͕ͳ͍͔ɺ ͏ҰճHTTPϦΫΤετΛ͛Δ
௨ৗͷHTTPϦΫΤετͷ߹ ϢʔβB৽͍͠ϝοηʔδ͕ͳ͍͔ɺ ԿճHTTPϦΫΤετΛ͛Δ
௨ৗͷHTTPϦΫΤετͷ߹ ϢʔβB৽͍͠ϝοηʔδ͕ͳ͍͔ɺ ఆظతʹHTTPϦΫΤετΛ͛Δ(େͳ͍) ͜ΜʹͪΘ
௨ৗͷHTTPϦΫΤετͷ߹ ͋ͬͨ߹ϝοηʔδΛड͚औΔ ͜ΜʹͪΘ
WebSocketศར
͔͜͜ΒຊͰ͢
UnicornͰActionCableΛ ͓͏ͱͯ͠ϋϚΓ͔͚ͨ͜ͱ
ίωΫγϣϯʹΑΔ ϓϩηεރׇ
ࣄલࣝ
2ͭͷΞϓϦέʔγϣϯ αʔόΛհ
None
Unicornུ֓ • ΞϓϦέʔγϣϯαʔό • ϓϩηε্Ͱಈ࡞͢Δ • masterϓϩηεɺworkerϓϩηεͷ2छྨ͕͋ Γɺworkerϓϩηε(܈)͕ϦΫΤετΛॲཧ͢ Δ
Pumaུ֓ • ΞϓϦέʔγϣϯαʔό • εϨου্Ͱಈ࡞͢Δ • ෳͷϦΫΤετΛผʑͷεϨου(worker)Ͱ ฒྻॲཧ͢Δ
εϨουϕʔ εͳɺ QVNBͷํ͕ΑΓଟ͘ͷϦΫΤε τΛࡹ͚Δ
ϓϩηεϕʔεͳ ͷͰɺεϨου΄ͲϦΫΤετΛ ଟ͘ࡹ͚ͳ͍
ϝυϐΞ6OJDPSO Λ͍ͬͯΔ
• εϨουηʔϑΛߟ͑ͳͯ͘ྑ͍ • େྔΞΫηε࣌ͷॲཧ͕҆ఆ͍ͯ͠Δ
http://blog.willnet.in/entry/2015/02/24/155006 UnicornͱPumaͷൺֱ ҎԼͷURLʹ·ͱ·͍ͬͯ·͢
6OJDPSOͰ "DUJPO$BCMF͑Δ https://github.com/rails/rails/blob/master/ actioncable/README.md
͔͠͠…
Unicornུ֓ • ΞϓϦέʔγϣϯαʔό • ϓϩηε্Ͱಈ࡞͢Δ • masterϓϩηεɺworkerϓϩηεͷ2छྨ͕͋ Γɺworkerϓϩηε(܈)͕ϦΫΤετΛॲཧ͢ Δ
1HTTPϦΫΤετ = 1ϓϩηε
ͱ͍͏͜ͱWebSocketͰ…
1ίωΫγϣϯ = 1ϓϩηε
ίωΫγϣϯ͕େྔʹ࡞ΒΕͨΒ ϓϩηεރׇ͢ΔΜ͡ΌͶ?
ϓϩηεϕʔεͷUnicorn͡Ό ຊ൪ͰActionCable͑ͳ͘Ͷ?
ʘ(^o^)ʗ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠
͍ͯΑ…?
None
6OJDPSOͷϓϩηεͷ
։ൃڥͰͷίωΫγϣϯͷ
1ϓϩηεͰ2ͭͷίωΫγϣϯ ͕Ͱ͖͍ͯΔ…?
1ίωΫγϣϯ = 1ϓϩηε
1ίωΫγϣϯ = 1ϓϩηε
ৄ͘͠ௐͳ͚Ε…
None
·ͣίωΫγϣϯ࡞࣌ ͷॲཧΛݟͯΈΑ͏
https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/connection/base.rb
Unicornུ֓ • ΞϓϦέʔγϣϯαʔό • ϓϩηε্Ͱಈ࡞͢Δ • masterϓϩηεɺworkerϓϩηεͷ2छྨ͕͋ Γɺworkerϓϩηε(܈)͕ϦΫΤετΛॲཧ͢ Δ
Pumaུ֓ • ΞϓϦέʔγϣϯαʔό • εϨου্Ͱಈ࡞͢Δ • ෳͷϦΫΤετΛผʑͷεϨου(worker)Ͱ ฒྻॲཧ͢Δ
worker = ϓϩηεɾεϨου
worker_pool͋ͨΓ͕ոͦ͠͏
https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/base.rb
WorkerΫϥεͷίϯετϥΫλʹ 伴͕͋Γͦ͏…
https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb
https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb
https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb
https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb 3VCZͰεϨουηʔϑͳ ฒྻॲཧΛॻͨ͘Ίͷ(FN
εϨου࡞ͬͯͨ
݁
HTTPϦΫΤετͱҧ͍ɺ 1ίωΫγϣϯ = 1ϓϩηε Ͱͳ͍
UnicornεϨουϕʔεͰͳ͍͕ɺ εϨουΛ࡞ͬͯίωΫγϣϯΛ ࡞͍ͯ͠Δ
ίωΫγϣϯ͕ଟ͘ͳͬͯɺ (ॳͷ༧ΑΓ) ϓϩηεṧഭ͠ͳͦ͞͏
UnicornͰ ຊ൪ͰActionCable͑ͦ͏!
ʌ(•˶∇˶•)ů
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠
UnicornͰActionCableͷ༻ܦݧ ͋Δਓ͕͍ͨΒݟΛڭ͍͑ͯͩ͘͞
None