Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MedPeer_JapaxTaxi_MeetUp_Actioncable

186afa3a28439f42c9c6717cc30966f9?s=47 pipopotamasu
April 26, 2018
270

 MedPeer_JapaxTaxi_MeetUp_Actioncable

186afa3a28439f42c9c6717cc30966f9?s=128

pipopotamasu

April 26, 2018
Tweet

Transcript

  1. UnicornͰActionCableΛ ࢖͓͏ͱͯ͠ϋϚΓ͔͚ͨ͜ͱ ϝυϐΞגࣜձࣾ ΤϯδχΞ ଜ্ େ࿨

  2. self_introduce.json { “name”: “ଜ্େ࿨”, “age”: 26, “github”: “pipopotamasu”, “company”: “ϝυϐΞגࣜձࣾ”,

    “tech”: [“Ruby”, “PHP”, “Vue.js”, “React”], “hobby”: [“໺ٿ”, “өը”], }
  3. https://jp.vuejs.org/v2/cookbook/ creating-custom-scroll-directives.html

  4. http://tech.medpeer.co.jp/

  5. None
  6. ※ ࠓ೔͸JSͷ࿩͸͠·ͤΜ

  7. ͱ͍͏Θ͚ͰൃදςʔϚ

  8. UnicornͰActionCableΛ ࢖͓͏ͱͯ͠ϋϚΓ͔͚ͨ͜ͱ

  9. ͜͜Ͱ࣭໰ʂ

  10. ීஈRails࢖ͬͯΔਓ (´ɾωɾ`)ϊγ

  11. ActionCable࢖ͬͯΔਓ (ɾωɾ)ϊγ

  12. ActionCableͱ͸ • RailsΞϓϦέʔγϣϯͰWebSocketΛ࣮ݱ͢ ΔͨΊͷϑϨʔϜϫʔΫ • Rails5.0͔Βಋೖ

  13. WebSocketͱ͸ • ΫϥΠΞϯτͱαʔόʔͷ૒ํ޲௨৴Λ௿ί ετͰ࣮ݱ͢ΔͨΊͷ࢓૊Έ

  14. WebSocketͱ͸ • ΫϥΠΞϯτͱαʔόʔͷ૒ํ޲௨৴Λ௿ί ετͰ࣮ݱ͢ΔͨΊͷ࢓૊Έ • νϟοτΞϓϦΛΠϝʔδ͢ΔͱΘ͔Γ΍͢ ͍

  15. WebSocketͱ͸ ΫϥΠΞϯτͱαʔόʔ ؒͰ Websocket༻௨৴(ίωΫγϣϯ)Λཱ֬

  16. WebSocketͱ͸ ϢʔβA͕νϟοτΞϓϦͰͭͿ΍͘ ͜ΜʹͪΘ

  17. WebSocketͱ͸ WebsocketͷίωΫγϣϯΛ௨ͯ͡ αʔό΁ ͜ΜʹͪΘ

  18. WebSocketͱ͸ αʔό͔ΒίωΫγϣϯΛར༻ͯ͠ ଞͷϢʔβʹPush(σʔλΛૹ৴)͢Δ ͜ΜʹͪΘ

  19. WebSocketͱ͸ ϢʔβB͸ίωΫγϣϯΛ௨ͯ͡Ϣʔβ AͷϝοηʔδΛड͚औΔɻ ͜ΜʹͪΘ

  20. γʔϜϨεʹ σʔλ௨৴͕Ͱ͖Δ

  21. WebSocket͡Όͳ͍৔߹

  22. ௨ৗͷHTTPϦΫΤετͷ৔߹ ϢʔβA͕νϟοτΞϓϦͰͭͿ΍͘ ͜ΜʹͪΘ

  23. ௨ৗͷHTTPϦΫΤετͷ৔߹ HTTPϦΫΤετͰαʔό΁ (ͦͯ͠ϝοηʔδΛอଘ) ͜ΜʹͪΘ

  24. ௨ৗͷHTTPϦΫΤετͷ৔߹ ϢʔβB͸৽͍͠ϝοηʔδ͕ͳ͍͔ɺ HTTPϦΫΤετΛ౤͛Δ

  25. ௨ৗͷHTTPϦΫΤετͷ৔߹ ϢʔβB͸৽͍͠ϝοηʔδ͕ͳ͍͔ɺ ΋͏ҰճHTTPϦΫΤετΛ౤͛Δ

  26. ௨ৗͷHTTPϦΫΤετͷ৔߹ ϢʔβB͸৽͍͠ϝοηʔδ͕ͳ͍͔ɺ Կճ΋HTTPϦΫΤετΛ౤͛Δ

  27. ௨ৗͷHTTPϦΫΤετͷ৔߹ ϢʔβB͸৽͍͠ϝοηʔδ͕ͳ͍͔ɺ ఆظతʹHTTPϦΫΤετΛ౤͛Δ(େ఍ͳ͍) ͜ΜʹͪΘ

  28. ௨ৗͷHTTPϦΫΤετͷ৔߹ ͋ͬͨ৔߹͸ϝοηʔδΛड͚औΔ ͜ΜʹͪΘ

  29. WebSocketศར

  30. ͔͜͜Βຊ୊Ͱ͢

  31. UnicornͰActionCableΛ ࢖͓͏ͱͯ͠ϋϚΓ͔͚ͨ͜ͱ

  32. ίωΫγϣϯʹΑΔ ϓϩηεރׇ໰୊

  33. ࣄલ஌ࣝ

  34. 2ͭͷΞϓϦέʔγϣϯ αʔόΛ঺հ

  35. None
  36. Unicornུ֓ • ΞϓϦέʔγϣϯαʔό • ϓϩηε্Ͱಈ࡞͢Δ • masterϓϩηεɺworkerϓϩηεͷ2छྨ͕͋ Γɺworkerϓϩηε(܈)͕ϦΫΤετΛॲཧ͢ Δ

  37. Pumaུ֓ • ΞϓϦέʔγϣϯαʔό • εϨου্Ͱಈ࡞͢Δ • ෳ਺ͷϦΫΤετΛผʑͷεϨου(worker)Ͱ ฒྻॲཧ͢Δ

  38. εϨουϕʔ εͳ෼ɺ QVNBͷํ͕ΑΓଟ͘ͷϦΫΤε τΛࡹ͚Δ

  39. ϓϩηεϕʔεͳ ͷͰɺεϨου΄ͲϦΫΤετΛ ଟ͘ࡹ͚ͳ͍

  40. ϝυϐΞ͸6OJDPSO Λ࢖͍ͬͯΔ

  41. • εϨουηʔϑΛߟ͑ͳͯ͘ྑ͍ • େྔΞΫηε࣌ͷॲཧ͕҆ఆ͍ͯ͠Δ

  42. http://blog.willnet.in/entry/2015/02/24/155006 UnicornͱPumaͷൺֱ͸ ҎԼͷURLʹ·ͱ·͍ͬͯ·͢

  43. 6OJDPSOͰ "DUJPO$BCMF࢖͑Δ https://github.com/rails/rails/blob/master/ actioncable/README.md

  44. ͔͠͠…

  45. Unicornུ֓ • ΞϓϦέʔγϣϯαʔό • ϓϩηε্Ͱಈ࡞͢Δ • masterϓϩηεɺworkerϓϩηεͷ2छྨ͕͋ Γɺworkerϓϩηε(܈)͕ϦΫΤετΛॲཧ͢ Δ

  46. 1HTTPϦΫΤετ = 1ϓϩηε

  47. ͱ͍͏͜ͱ͸WebSocketͰ͸…

  48. 1ίωΫγϣϯ = 1ϓϩηε

  49. ίωΫγϣϯ͕େྔʹ࡞ΒΕͨΒ ϓϩηεރׇ͢ΔΜ͡ΌͶ?

  50. ϓϩηεϕʔεͷUnicorn͡Ό ຊ൪ͰActionCable࢖͑ͳ͘Ͷ?

  51. ʘ(^o^)ʗ

  52. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

  53. ͍΍଴ͯΑ…?

  54. None
  55. 6OJDPSOͷϓϩηεͷ਺

  56. ։ൃ؀ڥͰͷίωΫγϣϯͷ਺

  57. 1ϓϩηεͰ2ͭͷίωΫγϣϯ ͕Ͱ͖͍ͯΔ…?

  58. 1ίωΫγϣϯ = 1ϓϩηε

  59. 1ίωΫγϣϯ = 1ϓϩηε

  60. ৄ͘͠ௐ΂ͳ͚Ε͹…

  61. None
  62. ·ͣ͸ίωΫγϣϯ࡞੒࣌ ͷॲཧΛݟͯΈΑ͏

  63. https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/connection/base.rb

  64. Unicornུ֓ • ΞϓϦέʔγϣϯαʔό • ϓϩηε্Ͱಈ࡞͢Δ • masterϓϩηεɺworkerϓϩηεͷ2छྨ͕͋ Γɺworkerϓϩηε(܈)͕ϦΫΤετΛॲཧ͢ Δ

  65. Pumaུ֓ • ΞϓϦέʔγϣϯαʔό • εϨου্Ͱಈ࡞͢Δ • ෳ਺ͷϦΫΤετΛผʑͷεϨου(worker)Ͱ ฒྻॲཧ͢Δ

  66. worker = ϓϩηεɾεϨου

  67. worker_pool͋ͨΓ͕ոͦ͠͏

  68. https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/base.rb

  69. WorkerΫϥεͷίϯετϥΫλʹ 伴͕͋Γͦ͏…

  70. https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb

  71. https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb

  72. https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb

  73. https://github.com/rails/rails/blob/master/ actioncable/lib/action_cable/server/worker.rb 3VCZͰεϨουηʔϑͳ ฒྻॲཧΛॻͨ͘Ίͷ(FN

  74. εϨου࡞ͬͯͨ

  75. ݁࿦

  76. HTTPϦΫΤετͱҧ͍ɺ 1ίωΫγϣϯ = 1ϓϩηε Ͱ͸ͳ͍

  77. Unicorn͸εϨουϕʔεͰ͸ͳ͍͕ɺ εϨουΛ࡞ͬͯίωΫγϣϯΛ ࡞੒͍ͯ͠Δ

  78. ίωΫγϣϯ͕ଟ͘ͳͬͯ΋ɺ (౰ॳͷ༧૝ΑΓ͸) ϓϩηε͸ṧഭ͠ͳͦ͞͏

  79. UnicornͰ΋
 ຊ൪ͰActionCable࢖͑ͦ͏!

  80. ʌ(•˶∇˶•)ů

  81. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

  82. UnicornͰActionCableͷ࢖༻ܦݧ ͋Δਓ͕͍ͨΒ஌ݟΛڭ͍͑ͯͩ͘͞

  83. None