Actor Model in Reason

Actor Model in Reason

Febd813a64ed871a144f4947d57ba156?s=128

Yuki YAMADA

August 02, 2018
Tweet

Transcript

  1. ©2018 Wantedly, Inc. Actor Model in Reason Meguro.es #16 02.Aug.2018

    - Yuki Yamada
  2. ©2018 Wantedly, Inc. Self Introduction

  3. ©2018 Wantedly, Inc. Yuki Yamada @yamadayuki I’m an Engineer @

    Wantedly I write JS, Golang, Ruby, Swift … etc. Now I focus on Frontend Engineering at Feed squad. Self Introduction
  4. ©2018 Wantedly, Inc. Actor Model

  5. ©2018 Wantedly, Inc. Actor Model Actor Model ΞΫλʔͱ͍͏ঢ়ଶΛอͪॲཧΛ͢ΔΦϒδΣΫτ ͦΕͧΕ͕ Mailbox

    ͱ͍͏ΩϡʔͱΞυϨεΛ͍࣋ͬͯΔ ΞΫλʔୡ͸ͦΕͧΕࣗ෼ͷॲཧΛߦ͍ͭͭඞཁ͕͋Ε͹ଞ ͷΞΫλʔʹϝοηʔδΛૹͬͯॲཧΛ͓ئ͍͢Δ ͦΕͧΕͷॲཧ͸ඇಉظͰ࣮ߦ͞ΕΔͨΊɺฒߦॲཧͷͨΊ ͷϩοΫ΍ಉظ͕ෆཁʹͳΔ ݴޠϨϕϧͰ͸ Erlang ϥΠϒϥϦͰ͸ Akka (JVM) ͕୅දྫ
  6. ©2018 Wantedly, Inc. JavaScript Ͱ΋΍ͬͯΈ͍ͨ Actor Model

  7. ©2018 Wantedly, Inc. Ͱ΋ී௨ͷ JavaScript Ͱ ͏·͘Ͱ͖Δؾ͕͠ͳ͍ Actor Model

  8. ©2018 Wantedly, Inc. 1. OCaml • Statically typed, Functional, Pattern

    Matching 2. Erlang • Actor Model, Functional, Pattern Matching 3. JavaScript • Fun, Insanely flexible Actor Model
  9. ©2018 Wantedly, Inc. ؔ਺ܕݴޠͰ Pattern Matching ͷ ԸܙΛड͚ͭͭ Actor Model

    ΍Γ͍ͨ Actor Model
  10. ©2018 Wantedly, Inc. Actor Model

  11. ©2018 Wantedly, Inc. Actor Model Roppongi.js #1 ͰLT͠·ͨ͠ BuckleScript ϕʔεͰܕݕࠪͰ͖Δɺ

    Facebook ۘ੡ͷAltJS BuckleScript ͸ OCaml ΛίϯύΠϧ ͯ͠ JavaScript ʹ͢Δ΍ͭ https://speakerdeck.com/yamadayuki/react-with-reason
  12. ©2018 Wantedly, Inc. Actor Model ؔ਺ܕݴޠͰ Pattern Matching ͷ ԸܙΛड͚ͭͭ

    Actor Model Ͱ͖ͦ͏
  13. ©2018 Wantedly, Inc. Actor Model in Reason

  14. ©2018 Wantedly, Inc. Actor Model in Reason JS Ͱ Actor

    Model ncthbrt/nact , ncthbrt/reason-nact “Nact is redux but for the server.” Akka ΍ Erlang ͷΞϓϩʔνΛࢀߟʹ Node.js Ͱ΋ Actor Model ͕࣮ݱͰ͖ΔΑ͏ʹ࡞ΒΕͨϥΠϒϥϦ DENQUE (https://github.com/Salakar/denque) ͱ Promise ϕʔεͰ࣮૷͞Ε͍ͯΔ Timeout ΍ Supervision ΋αϙʔτ͞Ε͍ͯΔ JavaScript ͔Β΋ Reason/BuckleScript ͔Β΋࢖͑Δ
  15. ©2018 Wantedly, Inc. Actor Model in Reason Getting Started ѫࡰΛฦͯ͘͠ΕΔΞΫλʔͷੜ੒

    “spawnStateless” ͱ͍͏ؔ਺ͰΞΫλʔ͕ੜ੒ Ͱ͖Δ ΞΫλʔʹରͯ͠ “dispatch” ͱ͍͏ؔ਺Ͱϝο ηʔδΛૹΔ͜ͱͰɺॲཧΛ࣮ߦͤ͞Δ͜ͱ͕ Ͱ͖Δ
  16. ©2018 Wantedly, Inc. Actor Model in Reason spawnStateless “Stateless” ͱ

    suffix ͕͍͍ͭͯΔ͚ͩ͋ͬͯɺ ͜ͷؔ਺Ͱ͸ State Λ࣋ͬͨΞΫλʔΛੜ੒Ͱ ͖ͳ͍ ͦͷͨΊɺ࣮ߦͯ͠΄͍͠ॲཧ͚ͩΛ೚ͤΔ͜ ͱ͔͠Ͱ͖ͳ͍ɻ࣮ߦͨ݁͠ՌͩͬͨΓΛ࣍ʹ ࢖͍ճ͢ͱ͔͸Ͱ͖ͳ͍
  17. ©2018 Wantedly, Inc. Actor Model in Reason spawn ݟͨ໨ “Stateless”

    ͷ suffix ͕औΕ͚ͨͩ ͜ͷؔ਺Ͱ͸ State Λ࣋ͬͨΞΫλʔΛੜ੒Ͱ ͖Δ ӈͷίʔυ͸ counter ͷ࣮૷ amount Λࢦఆͯ͠૿΍͢ྔΛϝοηʔδͰૹ Δͱɺ͍·ͷঢ়ଶͷ amount ʹՃࢉ͞Εͯίϯ ιʔϧʹग़ྗ͞ΕΔɻ
  18. ©2018 Wantedly, Inc. Actor Model in Reason spawn ॲཧΛهड़͢Δؔ਺ͷୈ1Ҿ਺ʹ State

    ͕౉ͬͯ ͘ΔͷͰɺͦΕΛར༻ͯ͠ॲཧΛߦ͑Δ 12ߦ໨͸͜ͷΞΫλʔ͕ॳظԽ͞Εͨ࣌఺Ͱͷ initial state Λฦ͍ͯ͠Δ ͳͷͰ state ʹ͸ {amount: int} ͱ͍͏ํ͕౉ͬ ͯ͘Δ
  19. ©2018 Wantedly, Inc. Actor Model in Reason Communication ΞΫλʔಉ࢜Ͱ௨৴͢Δͱ͖ɺྫ͑͹ϝοηʔ δͷૹΓओ͕ඞཁͳ৔߹͕͋Δ

    ϝοηʔδΛૹΔͱ͖ʹࣗ෼ࣗ਎Λϝοηʔδ ʹՃ͑Δ͜ͱͰɺϝοηʔδΛड͚औͬͨଆͰ ΋ૹΓओΛ஌Δ͜ͱ͕Ͱ͖Δ ΞΫλʔࣗମ͸ actorRef(msgType) ͷΑ͏ͳ ܕʹͳΔͷͰɺϝοηʔδͷܕΛఆٛ͢Δ࣌ʹ ར༻͢Δ
  20. ©2018 Wantedly, Inc. Actor Model in Reason Communication pong ͔Β

    ping ʹϝοηʔδΛૹΔͱ͜Ζ 7ߦ໨Ͱ sender(ping or pong) ʹରͯ͠ ctx.self Λϝοηʔδʹ֨ೲͯ͠ૹΔΑ͏ʹͳͬ ͍ͯΔ ctx.self ͸ΞΫλʔࣗ਎ʹͳ͍ͬͯͯɺϝοηʔ δΛड͚औΔଆͰ΋ૹΓओ͕Θ͔Δ “<-<” ͱ͍͏ͷ͸ಠࣗʹఆٛ͞ΕͨΦϖϨʔλͰ dispatch ͷγϣʔτϋϯυ
  21. ©2018 Wantedly, Inc. Actor Model in Reason Supervision ΋͠ΞΫλʔ͕Ϋϥογϡͨ͠৔߹ɺඇಉظॲ ཧͷҰ࿈ͷྲྀΕΛࢭΊͳ͍ͨΊʹ΋෮׆ͤ͞Δ

    ඞཁ͕͋Δ Ϋϥογϡͨ͠ͱ͖ʹ෮׆Ͱ͖ΔΑ͏ʹ supervisor Λ༻ҙ͢Δ͜ͱͰɺࣗಈతʹΞΫ λʔΛ෮׆ͤ͞ΒΕΔ
  22. ©2018 Wantedly, Inc. DEMO Actor Model in Reason

  23. ©2018 Wantedly, Inc. 1. νϟοτͷΑ͏ͳΠϕϯτϕʔεͷαʔό 2. ඇಉظδϣϒΩϡʔγεςϜ Actor Model in

    Reason Actor Model ͷ࢖͍ॴ
  24. ©2018 Wantedly, Inc. JSͰϓϩτλΠϐϯάͰ͖Δʂ Actor Model in Reason

  25. ©2018 Wantedly, Inc. 1. Actor Model Λ࢖ͬͯඇಉظॲཧΛ͍͍ײ͡ʹ 2. nact ͸

    Reason Ͱهड़Ͱ͖ΔͷͰܕͷԸܙ͕͋Δ 3. Reason ָ͍͠ Actor Model in Reason ·ͱΊ
  26. ©2018 Wantedly, Inc. Actor Model in Reason Meguro.es #16 02.Aug.2018

    - Yuki Yamada Fin.