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
440
MedPeer_JapaxTaxi_MeetUp_Actioncable
pipopotamasu
April 26, 2018
Tweet
Share
More Decks by pipopotamasu
See All by pipopotamasu
How JS Works
pipopotamasu
0
160
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
460
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
840
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
40
2.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
106
48k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Become a Pro
speakerdeck
PRO
24
4.9k
We Have a Design System, Now What?
morganepeng
50
7.2k
Automating Front-end Workflow
addyosmani
1365
200k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Being A Developer After 40
akosma
85
590k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Rails Girls Zürich Keynote
gr2m
93
13k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Fireside Chat
paigeccino
32
3k
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