Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Elixir/OTPを使った分散アプリケーション

kanmo
May 12, 2017

 Elixir/OTPを使った分散アプリケーション

#cm_osaka クラスメソッド大阪勉強会のスライド

kanmo

May 12, 2017
Tweet

More Decks by kanmo

Other Decks in Technology

Transcript

  1. ϝοηʔδड৴ # ϝοηʔδड৴ॲཧ
 defmodule Receiver do def loop do receive

    do {_, msg} -> IO.puts(msg <> “!!!”) end loop end end
  2. 5BTLBTZOD5BTLBXBJU # ผϓϩηεͰ࣮ࢪ͢Δؔ਺Λఆٛ func = fn -> Worker.start(url) end 1..10000

    |> Enum.map(fn _ -> Task.async(func) end) # ఆٛͨؔ͠਺Λ ౉͢ |> Enum.map(&Task.await(&1)) # ݁ՌΛड͚औΔ w ผϓϩηεͰॲཧΛͯͦ͠ͷ݁ՌΛ଴ͪड͚Δίʔ υΛ؆୯ʹॻ͚Δ ඇಉظͷฒߦॲཧ
  3. 5BTLBTZOD5BTLBXBJU # ผϓϩηεͰ࣮ࢪ͢Δؔ਺Λఆٛ func = fn -> Worker.start(url) end 1..10000

    |> Enum.map(fn _ -> Task.async(func) end) # ఆٛͨؔ͠਺Λ ౉͢ |> Enum.map(&Task.await(&1)) # ݁ՌΛड͚औΔ w ผϓϩηεͰॲཧΛͯͦ͠ͷ݁ՌΛ଴ͪड͚Δίʔ υΛ؆୯ʹॻ͚Δ ඇಉظͷฒߦॲཧ
  4. 5BTLBTZOD5BTLBXBJU # ผϓϩηεͰ࣮ࢪ͢Δؔ਺Λఆٛ func = fn -> Worker.start(url) end 1..10000

    |> Enum.map(fn _ -> Task.async(func) end) # ఆٛͨؔ͠਺Λ ౉͢ |> Enum.map(&Task.await(&1)) # ݁ՌΛड͚औΔ w ผϓϩηεͰॲཧΛͯͦ͠ͷ݁ՌΛ଴ͪड͚Δίʔ υΛ؆୯ʹॻ͚Δ ඇಉظͷฒߦॲཧ
  5. 5BTLBTZOD5BTLBXBJU # ผϓϩηεͰ࣮ࢪ͢Δؔ਺Λఆٛ func = fn -> Worker.start(url) end 1..10000

    |> Enum.map(fn _ -> Task.async(func) end) # ఆٛͨؔ͠਺Λ ౉͢ |> Enum.map(&Task.await(&1)) # ݁ՌΛड͚औΔ w ผϓϩηεͰॲཧΛͯͦ͠ͷ݁ՌΛ଴ͪड͚Δίʔ υΛ؆୯ʹॻ͚Δ ඇಉظͷฒߦॲཧ
  6. 051

  7. ؂ࢹઃఆ opts = [strategy: :one_for_all, max_restarts: 5, max_seconds: 5] supervise(children,

    opts) w POF@GPS@BMMͳͷͰϓϩηε͕Ϋϥογϡ͢Δͱଞͷϓϩ ηε΋શͯ࠶ىಈ͢Δ w ඵҎ಺ʹճ࠶ىಈ͢ΔͱΞϓϦέʔγϣϯ͕ఀࢭ͢Δ
  8. ׬੒ Supervisor Server SubSupervisor PoolSupervisor PoolSupervisor PoolServer WorkerSupervisor PoolServer ֎෦αΠτ"ͷϫʔΧʔ

    ͷঢ়ଶΛ؅ཧ͢Δ ֎෦αΠτ #ͷϫʔΧʔͷঢ়ଶΛ؅ཧ ؅ཧ͢Δ WorkerSupervisor Worker Worker Worker Worker Worker Worker
  9. ׬੒ Supervisor Server SubSupervisor PoolSupervisor PoolSupervisor PoolServer WorkerSupervisor PoolServer ֎෦αΠτ

    #ͷϫʔΧʔͷঢ়ଶΛ؅ཧ ؅ཧ͢Δ WorkerSupervisor Worker Worker Worker Worker Worker Worker
  10. DMVTUFSͷઃఆྫ [{kernel, [{distributed, [{sample, 5000, ['[email protected]', {'[email protected]', '[email protected]'}]}]}, {sync_nodes_mandatory, ['[email protected]',

    '[email protected]']}, {sync_nodes_timeout, 30000} ]}]. w EJTUSJCVUFEDMVTUFSΛߏ੒͢Δϊʔυ܈ɻ༏ઌ౓͸BɺCɺDͷॱ w TZOD@OPEFT@NBOEBUPSZɿ͜͜ʹઃఆͨ͠શͯͷϊʔυ͕ىಈ͢Δ·ͰΞϓϦέʔ γϣϯΛϩοΫ͢Δ w TZOD@OPEFT@UJNFPVUɿ͜ͷ࣌ؒ·Ͱʹࢦఆͨ͠ϊʔυ͕ىಈ͠ͳ͚Ε͹ҟৗऴ ྃ͢Δ