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

Actor Model meets the Kubernetes - CNDT 2019

Actor Model meets the Kubernetes - CNDT 2019

Shinichi Morimoto

July 22, 2019
Tweet

More Decks by Shinichi Morimoto

Other Decks in Technology

Transcript

  1. Actor Model meets the Kubernetes Cloud Native Days Tokyo 2019

    ৿ຊਅҰ @shnmorimotoʢFringe81גࣜձࣾʣ
  2. ࣗݾ঺հ • ໊લɿ৿ຊ ਅҰ • twitter: @shnmorimoto • github: github.com/shnmorimoto

    • ॴଐɿFringe81 גࣜձࣾ • ࢓ࣄɿ޿ࠂܥϓϩμΫτɾόοΫΤϯυΤϯδχΞ • ྖҬɿScala, Elm, Azure, Kubernetes
  3. εςʔτϨεͳΞϓϦέʔγϣϯ "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS ɾ ɾ ɾ

    -# 4DBMF0VU*O ͷ੍໿ͳ͠ ো֐ͷ෮چ ΋؆୯ • εςʔτϨεͳΞϓϦέʔ γϣϯ • ঢ়ଶΛ࣋ͨͳ͍ • ো֐͕ى͖ͯ΋ɺ෮چ͸ָ • εέʔϦϯάͷ੍໿΋ͳ͠ • ࣮ݱͰ͖Δࣄ͸ඇৗʹݶΒ ΕΔ
  4. εςʔτϨεͳΞϓϦέʔγϣϯ + DB "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    %# ඞཁͳঢ়ଶΛ %#ʹอଘ͢Δʂ ௨ৗɺ༗༻ͳΞϓϦέʔγϣϯΛ࡞੒͢ΔͨΊʹ͸ঢ়ଶΛ%# ౳ʹ࣋ͭඞཁ͕͋Δ ͜ΕͰશ͕ͯ໰୊ͳ͘ղܾʁ
  5. εςʔτϨεͳΞϓϦέʔγϣϯ + DB "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    %# ঢ়ଶΛߋ৽͢ΔͨΊʹ-PDL -PDL͕ղআ͞ΕΔ·Ͱ ଴ͭඞཁ͕͋Δ Ϩεϙϯε͕஗͘ͳΔ ಉ͡ঢ়ଶΛෳ਺͔Βߋ৽͠Α͏ͱͨ͠ࡍʹɺϨεϙϯε͕஗͘ͳΔʂ ʢঢ়ଶߋ৽͕ෳࡶͳ৔߹͸%FBE-PDL΋ൃੜ͢Δʜʣ ಉҰͷঢ়ଶΛಉ࣌ʹߋ৽͢Δέʔε
  6. εςʔτϨεͳΞϓϦέʔγϣϯ + KVS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    ,74 ඞཁͳঢ়ଶΛ ,74ʹอଘ͢Δʂ Ϩεϙϯε͕໰୊ʹͳΔͳΒɺ,74ʹ͢Ε͹ྑ͍ʂ ͜ΕͰશ͕ͯ໰୊ͳ͘ղܾʁ ଎͍ͧ͒ʂʂʂ
  7. εςʔτϨεͳΞϓϦέʔγϣϯ + KVS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    ,74 ߋ৽࣌ʹ-PDL͕͔͔Βͳ͍ͷͰɺঢ়ଶͷෆ੔߹͕͓͖ΔՄೳ ੑ͕͋Δ ಉҰͷঢ়ଶΛಉ࣌ʹߋ৽͢Δέʔε ʢઌʹʣঢ়ଶΛߋ৽ʂ ʢޙʹʣঢ়ଶΛߋ৽ʂ 8*/
  8. εςʔτϨεͳΞϓϦέʔγϣϯ + DB/KVS + ??? "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO

    4FSWFS -# ౰વɺղܾ͢Δखஈ͸৭ʑ͋Δ͕ɺߏ੒͸ෳࡶʹͳΒ͟ΔΛ ಘͳ͍ ಉҰͷঢ়ଶΛಉ࣌ʹߋ৽͢Δέʔε ԿΒ͔ͷ ιϦϡʔγϣ ϯʁʁʁʁ
  9. εςʔτϑϧͳΞϓϦέʔγϣϯ "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -# ঢ়ଶ ঢ়ଶ

    ঢ়ଶ ঢ়ଶ • εςʔτϑϧͳΞϓϦέʔγϣϯ • ঢ়ଶΛ࣋ͭ • ঢ়ଶͷߋ৽͕γϯϓϧʂ • ঢ়ଶΛΞϓϦέʔγϣϯʹ࣋ͭʹ ͸ʁʁʁ • ঢ়ଶΛߋ৽͢ΔͨΊʹద੾ʹScaling/ Balancing͢Δํ๏͸ʁʁʁ • ΞϓϦέʔγϣϯΛ࠶ىಈͨ͠Βঢ় ଶ͕ফ͑ͳ͍ʁʁʁ
  10. Actor Model • ฒߦγεςϜͷϞσϧͷҰछ • ActorʢΞΫλʔʣͱ͍͏֓೦Λಋೖ͠ɺฒߦγεςϜΛ؆қʹѻ͏͜ͱ͕ Ͱ͖Δʢޙड़ʣ • Erlang͕Actor ModelΛ࠾༻͍ͯ͠Δ

    • Java/ScalaͰ΋Akkaͱ͍͏πʔϧΩοτΛར༻͢Δ͜ͱͰ࣮ݱͰ͖Δ ΞΫλʔϞσϧʢӳBDUPSNPEFMʣͱ͸ɺ೥ɺΧʔϧɾώϡʔΠοτɺ1FUFS #JTIPQɺ3JDIBSE4UFJHFS͕ൃදͨ͠ฒߦܭࢉͷ਺ֶతϞσϧͷҰछɻ ग़యϑϦʔඦՊࣄయʰ΢ΟΩϖσΟΞʢ8JLJQFEJBʣʱ ຊηογϣϯͰ͸"LLBΛྫʹऔΓɺ"DUPS.PEFMʹ͍ͭͯઆ໌͠·͢
  11. • Java/Scala޲͚ʹActor ModelΛ࣮ݱ͢ΔπʔϧΩοτ • LightbendࣾʹΑͬͯ։ൃ͞Εɺݱࡏ͸ΦʔϓϯιʔεͰ։ൃ͕ଓ͚ΒΕ͍ͯΔ • ԼهΛ؆қʹ࣮ݱͰ͖Δ • Actor Model

    • SupervisorʹΑΔো֐ִ཭ɾ෮چʹ༏ΕͨγεςϜͷߏங • ΫϥελϦϯά • ετϦʔϜॲཧ • etc … Akka - ֓ཁ
  12. +7. "DUPS Akka Actor "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS

    "DUPS "DUPS w ঢ়ଶΛ࣋ͭ w ͦΕͧΕͷ"DUPSͰϩδοΫΛ࣋ͭ w ̍ͭ̍ͭͷ"DUPS͕ϓϩηεͷΑ͏ʹৼΔ෣͏ FY  $POGFSFODF/BNF$MPVE/BUJWF %BZT5PLZP  %BUF FY  $POGFSFODF/BNF$MPVE/BUJWF %BZT'VLVPLB  %BUF ෳ਺ͷ"DUPS͕Ծ૝ϓϩηεͷΑ͏ʹՔಇ͢Δ
  13. +7. "DUPS Akka Actor "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS

    "DUPS "DUPS $POGFSFODF໊͸ʁ $MPVE/BUJWF %BZT5PLZP ͦΕͧΕͷ"DUPSؒ͸ϝοηʔδΛ௨ͯ͠ඇಉظʹॲཧΛߦ͏
  14. "DUPS Akka Actor "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS

    "DUPS ɾݸʑͷ"DUPS͸ΞυϨεΛ͓࣋ͬͯΓɺͦͷΞυϨεѼʹϝοηʔδΛૹ৴͢Δɻ ɾϝʔϧϘοΫεͷΑ͏ͳΩϡʔΛ͓࣋ͬͯΓɺಧ͍ͨϝοηʔδʹ͍ͭͯॱ࣍ॲཧΛߦ͏ +7.
  15. "DUPS Akka Actor - Supervisionʢิʣ "DUPS "DUPS "DUPS "DUPS ਌

    ࢠ ଙ • Actor͸ࣗ਎ͷࢠͱͳ ΔActorΛੜ੒Ͱ͖Δ • ActorؒͰͷ਌ࢠؔ ܎ɺҰछͷπϦʔߏ ଄Λߏ੒Ͱ͖Δ
  16. "DUPS "DUPS "DUPS "DUPS "DUPS ਌ ࢠ ଙ • ਌Actor͸ࢠActorͷ؂

    ಜऀʢSupervisorʣͱ ͳΔ • ࢠActorʹ໰୊͕ൃੜ ͨ͠৔߹ʹఀࢭ΍࠶ى ಈ౳ͷॲཧΛߦ͏ ؂ࢹ ؂ࢹ Akka Actor - Supervisionʢิʣ
  17. "DUPS "DUPS "DUPS "DUPS "DUPS ਌ ࢠ ଙ • ਌Actor͸ࢠActorʹ໰୊͕ൃੜ͢

    ΔͱઓུʹԊͬͯରԠ • ఀࢭ • ࠶ىಈʢActorΛ࠶ੜ੒͢Δʣ • ΤεΧϨʔγϣϯ ໰୊͕ൃੜ "DUPS͕ઓུʹԊͬͯɺରԠ Akka Actor - Supervisionʢิʣ
  18. ActorͷScaling/Balancing /PEF /PEF /PEF -# ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ˞࣮ࡍʹ͸΋ͬͱଟ͘ͷ"DUPS͕

    Քಇ͢Δ͜ͱʹͳΔ /PEFؒʹ౉ͬͯɺ"DUPSΛల ։͢Δʹ͸ʁ ͲͷΑ͏ʹɺͲͷ/PEFʹͲͷ ঢ়ଶ͕͋Δ͔Λ஌Δ͜ͱ͕Ͱ͖ Δʁ
  19. ͦΕͧΕຖʹϢχʔΫͳࣝผࢠ Λ"DUPSΛ&OUJUZͱݺͿ Akka Cluster Sharding +7. +7. +7. +7. 4IBSE

    4IBSE 4IBSE 4IBSE 4IBSE 4IBSE ୯ମͷϊʔυ্ͷ"DUPS $MVTUFS্Ͱ4IBSEJOH͞Εͨ"DUPS &OUJUZΛ4IBSEʹ෼͚ɺ4IBSEΛ ෳ਺ͷϊʔυʹ෼ࢄͤ͞Δ͜ͱ͕Ͱ ͖Δ
  20. Akka Cluster Sharding +7. +7. +7. +7. 4IBSE 4IBSE 4IBSE

    4IBSE 4IBSE 4IBSE ୯ମͷϊʔυ্ͷ"DUPS $MVTUFS্Ͱ4IBSEJOH͞Εͨ"DUPS ಉҰͷࣝผࢠΛ΋ͭ&OUJUZ͸ $MVTUFSʹҰՕॴ͔͠ଘࡏ͠ͳ͍͜ ͱΛอূ 4IBSEʹ9999ͱ͍͏ࣝผࢠ Λ࣋ͭ&OUJUZ͕͍ͨΒɺଞͷ 4IBSEʹ͸ಉ͡&OUJUZ͸ଘࡏ͠ ͳ͍
  21. Akka Cluster Sharding +7. +7. +7. +7. 4IBSE 4IBSE 4IBSE

    4IBSE 4IBSE 4IBSE ୯ମͷϊʔυ্ͷ"DUPS $MVTUFS্Ͱ4IBSEJOH͞Εͨ"DUPS Ͳ͜ͷ4IBSEʹԿͷ&OUJUZ͕ଘࡏ ͢Δͷ͔΋؅ཧ͞Ε͍ͯΔ 4IBSEʹ9999ͱ͍͏&OUJUZ ͕ଘࡏ͢Δ
  22. • ϊʔυؒͰClusterΛߏங͢Δ͜ͱ͕Ͱ͖Δ • ͜Ε·Ͱͷػೳ͸ϩʔΧϧͱಉ͡Α͏ʹѻ͏͜ͱ͕Ͱ͖ΔʢTransparencyʣ • ϝοηʔδύογϯά • Supervision(؂ಜ) • Akka

    Cluster (Sharding)Λར༻͢Δ͜ͱͰ • ActorͷҰҙੑΛอূɿCluster಺ͰEntity͕Ұҙʹଘࡏ͢Δ͜ͱΛอূ͢Δ • ActorͷҐஔΛ؅ཧɿCluster಺ͰEntityͷҐஔΛ؅ཧ͍ͯ͠ΔͷͰɺͲͷshardʹ͍Δͷ͔͕෼͔Δ • ϊʔυ͕௥Ճ͞ΕΔͱγϟʔυΛࣗಈతʹϦόϥϯε͢Δ͜ͱ͕Ͱ͖Δ • ৽نʹϊʔυΛ௥Ճ͢Δʹ͸ɺSeedϊʔυͷ৘ใΛ஌͍ͬͯΔඞཁ͕͋Δʢͨͩ͠ɺAkka Clusterʹ͸ Service Discoveryͷػೳ͸ͳ͍ʣ Akka Cluster - ·ͱΊ
  23. /PEF /PEF /PEF ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS "LLB$MVTUFS "DUPSͷঢ়ଶ͕ফ͑ͳ͍ʁ ϊʔυʹো֐͕

    ൃੜʂ ϊʔυʹো֐͕ى͖ͨΓɺ"QQMJDBUJPO͕མͪͨΒ"DUPSͷঢ় ଶ͸ফ͑ͯ͠·͏ɻͨͩ͠"DUPSΛӬଓԽ͢Δํ๏͕༻ҙ͞Ε ͍ͯΔɻ ActorͷӬଓԽ
  24. &WFOU4PVSDJOH͸"LLB 1FSTJTUFODFͷػೳͰ࣮ݱՄೳ "DUPS ActorͷӬଓԽ %#,74 %#,74ʹอଘ͢Δͷ͸ɺঢ়ଶͰ͸ͳ͘ɺΠϕϯτΛ อଘ͢Δʢ&WFOU4PVSDJOHʣ อଘ͢Δͷ͸ঢ়ଶΛมߋͨ͠Πϕϯτ ঢ়ଶ 

    $POGFSFODF /BNF$MPVE /BUJWF%BZT 5PLZP  5JDLFU νέοτΛຕొ࿥ νέοτ͕ຕചΕͨ νέοτ͕ຕചΕͨ ɾ ɾ ɾ
  25. "DUPS ActorͷӬଓԽ %#,74 ো֐࣌ʹ͸ΠϕϯτΛશͯಡΈࠐΈɺঢ়ଶΛ෮ݩ͢Δ ঢ়ଶ  $POGFSFODF /BNF$MPVE /BUJWF%BZT 5PLZP

     5JDLFU νέοτΛຕొ࿥ νέοτ͕ຕചΕͨ νέοτ͕ຕചΕͨ ɾ ɾ ɾ Πϕϯτ͔Βঢ়ଶΛ෮ݩ͢Δ
  26. εςʔτϨεͳΞϓϦέʔγϣϯ + DBʢ࠶ܝʣ "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    %# ঢ়ଶΛߋ৽͢ΔͨΊʹ-PDL -PDL͕ղআ͞ΕΔ·Ͱ ଴ͭඞཁ͕͋Δ Ϩεϙϯε͕஗͘ͳΔ ಉ͡ঢ়ଶΛෳ਺͔Βߋ৽͠Α͏ͱͨ͠ࡍʹɺϨεϙϯε͕஗͘ͳΔʂ ʢঢ়ଶߋ৽͕ෳࡶͳ৔߹͸%FBE-PDL΋ൃੜ͢Δʜʣ ಉҰͷঢ়ଶΛಉ࣌ʹߋ৽͢Δέʔε
  27. /PEF /PEF /PEF ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS "LLB$MVTUFS %#,74 εςʔτϑϧͳΞϓϦέʔγϣϯ

    "LLB1FSTJTUFODF &WFOU4PVSDJOH ঢ়ଶΛߋ৽ʂ "DUPSͷঢ়ଶΛ ߋ৽͢Δϝοηʔδ "LLB"DUPS "LLB$MVTUFS 4IBSEJOH  "LLB 1FSTJTUFODFͰεςʔτϑϧͳΞϓϦέʔγϣϯΛߏ੒Ͱ͖Δ
  28. 7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    Akka Cluster on k8s - ֓ཁ
  29. 7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    ͭͷ1PEͭͷ"LLB$MVTUFSͷϊʔυͱͳΔ Akka Cluster on k8s - ֓ཁ
  30. 7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    "LLB$MVTUFS ,VCFSOFUFT ΞϓϦέʔγϣϯଆͷΫϥελϦϯά͸"LLB$MVTUFSɺ ΠϯϑϥଆͷΫϥελϦϯά͸,VCFSOFUFTͰ؅ཧ Akka Cluster on k8s - ֓ཁ
  31. 7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    ΞϓϦέʔγϣϯଆ͸"DUPS$MVTUFSͰ"DUPSͷεέʔϦϯά Akka Cluster on k8s - εέʔϦϯά
  32. 7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    ো֐ ΦʔτώʔϦϯά 1PEଆͷো֐͸1PEͷΦʔτώʔϦϯάͰରԠ Akka Cluster on k8s - ো֐෮چ
  33. 7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    "DUPSଆͷ$SBTI͸"DUPSͷ4VQFSWJTJPOͰରԠ $SBTI 4VQFSWJTJPOͰରԠ Akka Cluster on k8s - ো֐෮چ
  34. +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

    k8s - Node௥Ճ "LLB$MVTUFSʹ͸,VCFSOFUFTͱͷ࿈ܞػೳ͕༻ҙ͞Ε͍ͯΔ +7. 1PE ৽نϊʔυ LT"1*
  35. +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

    k8s - Node௥Ճ ,VCFSOFUFTͷ"1*ʹ໰͍߹ΘͤΔࣄͰɺ $MVTUFS಺ͷ1PEͷѼઌΛ஌Δ͜ͱ͕Ͱ͖Δ +7. 1PE ৽نϊʔυ LT"1* $MVTUFSͷ1PEͷѼઌΛ໰͍߹ Θͤ
  36. +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

    k8s - Node௥Ճ $MVTUFS಺ͷ1PEʹ޲͚ͯɺ+PJOϝοηʔδΛૹΔ +7. 1PE ৽نϊʔυ LT"1* ໰͍߹Θͤͨ݁Ռ͔Βϊʔυ΁ +PJOϝοηʔδΛ͓͘Δ
  37. +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

    k8s - Node௥Ճ "LLB$MVTUFSʹ͸ͳ͔ͬͨɺ4FSWJDF%JTDPWFSͷػೳΛ LT͕ิ׬ͯ͘͠ΕΔ +7. 1PE ৽نϊʔυ LT"1*
  38. • Akka ClusterͷΈ͚ͩͰ͸ରԠͰ͖ͳ͔ͬͨ఺ΛKubernetes͕ Χόʔͯ͘͠ΕΔ • Akka Cluster͔ΒݟͨNodeͷScaleOut/In • Akka Cluster͔Βݟͨϊʔυͷো֐෮چ

    • Akka Cluster͔ΒݟͨଞϊʔυͷService Discovery • PodʹKubernetes API΁ͷΞΫηεݖݶΛ෇༩͢Δඞཁ͕͋Δ Akka Cluster On k8s - ·ͱΊ
  39. • ʢຊདྷ֎෦DV/KVSʹ͍࣋ͬͯΔʣঢ়ଶΛΞϓϦέʔγϣϯʹ͍࣋ͬͯΔͷ͕ɺεςʔτϑϧ ͳΞϓϦέʔγϣϯ • εςʔτϑϧͳΞϓϦέʔγϣϯ͸ଈԠੑ͕ߴ͍ • εςʔτϑϧͳΞϓϦέʔγϣϯΛߏ੒͢ΔͨΊʹActor ModelʢAkkaʣ͕͋Δ • Akka

    Actor + Akka ClusterʢShardingʣ+ Akka PersistenceͰεςʔτϑϧͳΞϓϦέʔ γϣϯΛ؆୯ʹߏ੒Ͱ͖Δ • ActorͷӬଓԽʹ͸Event SourcingΛར༻͢Δ • ΞϓϦέʔγϣϯ૚ʹActor ModelɺΠϯϑϥ૚ʹKubernetesΛ૊Έ߹ΘͤΔ͜ͱͰɺ Actor Model͚ͩͰ͸ରԠͰ͖ͳ͔ͬͨ͜ͱΛิ׬͢Δ͜ͱ͕Ͱ͖Δ ·ͱΊ
  40. • Using Akka Cluster for a payment service - Scala

    Matsuri 2019 • https://speakerdeck.com/negokaz/using-akka-cluster-for-a-payment-service • How to build an Event-Sourcing system using Akka with EKS - Scala Matsuri 2019 • https://speakerdeck.com/j5ik2o/how-to-build-an-event-sourcing-system-using-akka-with-eks • Managing an Akka Cluster on Kubernetes - Scala Days LAUSANNE 2019 • https://portal.klewel.com/watch/webcast/scala-days-2019/talk/23/ • White Paper: The Benefits Of Using Akka With Kubernetes • https://www.lightbend.com/blog/new-white-paper-the-benefits-of-using-akka-with-kubernetes ࢀߟ