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

「ElixirがリアルタイムWebに強い」 というのは本当か?

09923d8b0c79423a289b7d5dc31a59e4?s=47 mururu
April 01, 2017

「ElixirがリアルタイムWebに強い」 というのは本当か?

Elixir Conf Japan 2017

09923d8b0c79423a289b7d5dc31a59e4?s=128

mururu

April 01, 2017
Tweet

More Decks by mururu

Other Decks in Technology

Transcript

  1. ʮElixir͕ϦΞϧλΠϜWebʹڧ͍ʯ ͱ͍͏ͷ͸ຊ౰͔ʁ Elixir Conf Japan 2017

  2. ࣗݾ঺հ Twitter: @mururururu Github: @mururu
 
 The Original Author: StringIO,

    ExUnit.CaptureIO
  3. ʮElixir͕ϦΞϧλΠϜWebʹڧ͍ʯ ͱ͍͏ͷ͸ຊ౰͔ʁ

  4. “ϦΞϧλΠϜɾ΢ΣϒʢReal-time webʣ͸ɺ Πϯλʔωοτ্ͷϢʔβʔͷॻ͖ࠐΈ΍ಈ޲ Λɺଈ͔࣌ͭେن໛ʹଞͷϢʔβʔͱڞ༗͢Δ ࢓૊Έͷ૯শɻ” - Wikipedia

  5. Node.js, Socket.IO

  6. • ϩϯάϙʔϦϯά • SSE • WebSocket

  7. • ίωΫγϣϯͷҡ࣋ • ૒ํ޲௨৴ • ௿஗Ԇ WebSocket $MJFOU $MJFOU Server

    $MJFOU
  8. • େྔͷίωΫγϣϯͷҡ࣋(c10k, c100k?) • ԟʑʹͯ͠εςʔτϑϧ • ௿஗Ԇ • ଱ো֐ੑ ՝୊

  9. BEAM - ErlangVM

  10. ܰྔϓϩηε

  11. ܰྔϓϩηε • N:MεϨουϞσϧ • minimum 309 words • ϝοηʔδύογϯά •

    Shared nothing • ܰྔϓϩηε͝ͱͷGC • ϓϦΤϯϓςΟϒͳεέʔδϡʔϦϯά 1 spawn fn -> 1 + 2 end spawn fn -> loop() end spawn dead
  12. ܰྔϓϩηε • N:MεϨουϞσϧ • minimum 309 words • ϝοηʔδύογϯά •

    Shared nothing • ܰྔϓϩηε͝ͱͷGC • ϓϦΤϯϓςΟϒͳεέʔδϡʔϦϯά 1 1 1 045ISFBE 045ISFBE
  13. ܰྔϓϩηε • N:MεϨουϞσϧ • minimum 309 words • ϝοηʔδύογϯά •

    Shared nothing • ܰྔϓϩηε͝ͱͷGC • ϓϦΤϯϓςΟϒͳεέʔδϡʔϦϯά 1 309 words
  14. • N:MεϨουϞσϧ • minimum 309 words • ϝοηʔδύογϯά • Shared

    nothing • ܰྔϓϩηε͝ͱͷGC • ϓϦΤϯϓςΟϒͳεέʔδϡʔϦϯά ܰྔϓϩηε 1 1 receive do {:get, key, caller} -> send caller, find(key) end
  15. ܰྔϓϩηε • N:MεϨουϞσϧ • minimum 309 words • ϝοηʔδύογϯά •

    Shared nothing • ܰྔϓϩηε͝ͱͷGC • ϓϦΤϯϓςΟϒͳεέʔδϡʔϦϯά 1 1 Copy
  16. ܰྔϓϩηε • N:MεϨουϞσϧ • minimum 309 words • ϝοηʔδύογϯά •

    Shared nothing • ܰྔϓϩηε͝ͱͷGC • ϓϦΤϯϓςΟϒͳεέʔδϡʔϦϯά 1 1 045ISFBE resume stopped
  17. • େྔͷίωΫγϣϯͷҡ࣋(c10k, c100k?) • ԟʑʹͯ͠εςʔτϑϧ • ௿஗Ԇ • ଱ো֐ੑ ՝୊

  18. େมͦ͏

  19. Phoenix Channel

  20. Phoenix Channel • ιϑτϦΞϧλΠϜͳ ʢWebʣΞϓϦέʔ γϣϯΛ༰қʹ࣮ݱ͢ΔϑϨʔϜϫʔΫ • ϓϥΨϒϧͳτϥϯεϙʔτ • ϓϥΨϒϧͳ

    PubSub όοΫΤϯυ
  21. Phoenix Channel • Phoenix.Socket • ΫϥΠΞϯτ͔Βͷड͚ޱ • Phoenix.Channel • τϐοΫ୯Ґͷνϟϯωϧͷ

    PubSub
  22. Phoenix.Socket defmodule HelloPhoenix.UserSocket do use Phoenix.Socket channel "room:*", HelloPhoenix.RoomChannel def

    connect(_params, socket) do {:ok, socket} end def id(_socket), do: nil end ग़య: http://www.phoenixframework.org/docs/channels
  23. Phoenix.Channel defmodule HelloPhoenix.RoomChannel do use Phoenix.Channel def join("room:lobby", _message, socket)

    do {:ok, socket} end def join("room:" <> _private_room_id, _params, _socket) do {:error, %{reason: "unauthorized"}} end def handle_in("new_msg", %{"body" => body}, socket) do broadcast! socket, "new_msg", %{body: body} {:noreply, socket} end end ग़య: http://www.phoenixframework.org/docs/channels
  24. $MJFOU gen_tcp, ranch, cowboy Phoenix.Socket ->
 Phoenix.Transports.WebSocket Phoenix.Channel -> Phoenix.Channel.Server

    Phoenix.PubSub.PG2 $MJFOU gen_tcp, ranch, cowboy Phoenix.Socket ->
 Phoenix.Transports.WebSocket Phoenix.Channel -> Phoenix.Channel.Server x topics x topics
  25. σϞ used: https://github.com/ koudelka/visualixir

  26. ·ͱΊ • ϦΞϧλΠϜWebʹ͓͚Δ՝୊ • ܰྔϓϩηε • ͦΕΛ༰қʹར༻Ͱ͖Δ Phenix Channel

  27. ʮElixir͕ϦΞϧλΠϜWebʹڧ͍ʯ ͱ͍͏ͷ͸ຊ౰͔ʁ Elixir Conf Japan 2017