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
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
210
メドピアにおけるライブラリアップデート_MedBeer_20180912.pdf
pipopotamasu
0
12k
MedPeer X みんなのウェディング合同勉強会
pipopotamasu
0
1k
UXBridge_vol3_pipopotamasu
pipopotamasu
2
850
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
33
3k
Gamification - CAS2011
davidbonilla
80
5.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Done Done
chrislema
181
16k
The Cult of Friendly URLs
andyhume
78
6.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Documentation Writing (for coders)
carmenintech
66
4.5k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Designing for Performance
lara
604
68k
The Invisible Side of Design
smashingmag
298
50k
Building Applications with DynamoDB
mza
91
6.1k
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