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
450
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
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
What's new in Ruby 2.0
geeforr
343
31k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
GitHub's CSS Performance
jonrohan
1030
460k
Ruby is Unlike a Banana
tanoku
97
11k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
740
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
The World Runs on Bad Software
bkeepers
PRO
65
11k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Side Projects
sachag
452
42k
Statistics for Hackers
jakevdp
796
220k
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