Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MedPeer_JapaxTaxi_MeetUp_Actioncable
Search
pipopotamasu
April 26, 2018
0
470
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
87
medpacker_introduction_20190523
pipopotamasu
0
470
Introduction of medpacker: RoR Frontend Boilerplate
pipopotamasu
0
4.6k
新サービス・JOURNAL(ジャーナル)開発秘話
pipopotamasu
2
200
メドピアにおけるライブラリアップデート_MedBeer_20180912.pdf
pipopotamasu
0
12k
MedPeer X みんなのウェディング合同勉強会
pipopotamasu
0
1k
UXBridge_vol3_pipopotamasu
pipopotamasu
2
850
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
470
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Facilitating Awesome Meetings
lara
50
6.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Rails Girls Zürich Keynote
gr2m
94
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
17k
Thoughts on Productivity
jonyablonski
67
4.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
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