Actor Model meets the Kubernetes - CNDT 2019

Actor Model meets the Kubernetes - CNDT 2019

1b963e66060bcc77b7ed647f5b6ff3a7?s=128

Shinichi Morimoto

July 22, 2019
Tweet

Transcript

  1. 1.

    Actor Model meets the Kubernetes Cloud Native Days Tokyo 2019

    ৿ຊਅҰ @shnmorimotoʢFringe81גࣜձࣾʣ
  2. 2.

    ࣗݾ঺հ • ໊લɿ৿ຊ ਅҰ • twitter: @shnmorimoto • github: github.com/shnmorimoto

    • ॴଐɿFringe81 גࣜձࣾ • ࢓ࣄɿ޿ࠂܥϓϩμΫτɾόοΫΤϯυΤϯδχΞ • ྖҬɿScala, Elm, Azure, Kubernetes
  3. 5.

    εςʔτϨεͳΞϓϦέʔγϣϯ "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS ɾ ɾ ɾ

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

    εςʔτϨεͳΞϓϦέʔγϣϯ + DB "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

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

    εςʔτϨεͳΞϓϦέʔγϣϯ + DB "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

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

    εςʔτϨεͳΞϓϦέʔγϣϯ + KVS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    ,74 ඞཁͳঢ়ଶΛ ,74ʹอଘ͢Δʂ Ϩεϙϯε͕໰୊ʹͳΔͳΒɺ,74ʹ͢Ε͹ྑ͍ʂ ͜ΕͰશ͕ͯ໰୊ͳ͘ղܾʁ ଎͍ͧ͒ʂʂʂ
  7. 9.

    εςʔτϨεͳΞϓϦέʔγϣϯ + KVS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

    ,74 ߋ৽࣌ʹ-PDL͕͔͔Βͳ͍ͷͰɺঢ়ଶͷෆ੔߹͕͓͖ΔՄೳ ੑ͕͋Δ ಉҰͷঢ়ଶΛಉ࣌ʹߋ৽͢Δέʔε ʢઌʹʣঢ়ଶΛߋ৽ʂ ʢޙʹʣঢ়ଶΛߋ৽ʂ 8*/
  8. 10.

    εςʔτϨεͳΞϓϦέʔγϣϯ + DB/KVS + ??? "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO

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

    εςʔτϑϧͳΞϓϦέʔγϣϯ "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -# ঢ়ଶ ঢ়ଶ

    ঢ়ଶ ঢ়ଶ • εςʔτϑϧͳΞϓϦέʔγϣϯ • ঢ়ଶΛ࣋ͭ • ঢ়ଶͷߋ৽͕γϯϓϧʂ • ঢ়ଶΛΞϓϦέʔγϣϯʹ࣋ͭʹ ͸ʁʁʁ • ঢ়ଶΛߋ৽͢ΔͨΊʹద੾ʹScaling/ Balancing͢Δํ๏͸ʁʁʁ • ΞϓϦέʔγϣϯΛ࠶ىಈͨ͠Βঢ় ଶ͕ফ͑ͳ͍ʁʁʁ
  10. 16.

    Actor Model • ฒߦγεςϜͷϞσϧͷҰछ • ActorʢΞΫλʔʣͱ͍͏֓೦Λಋೖ͠ɺฒߦγεςϜΛ؆қʹѻ͏͜ͱ͕ Ͱ͖Δʢޙड़ʣ • Erlang͕Actor ModelΛ࠾༻͍ͯ͠Δ

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

    • Java/Scala޲͚ʹActor ModelΛ࣮ݱ͢ΔπʔϧΩοτ • LightbendࣾʹΑͬͯ։ൃ͞Εɺݱࡏ͸ΦʔϓϯιʔεͰ։ൃ͕ଓ͚ΒΕ͍ͯΔ • ԼهΛ؆қʹ࣮ݱͰ͖Δ • Actor Model

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

    +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. 20.

    +7. "DUPS Akka Actor "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS

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

    "DUPS Akka Actor "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS "DUPS

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

    "DUPS Akka Actor - Supervisionʢิʣ "DUPS "DUPS "DUPS "DUPS ਌

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

    "DUPS "DUPS "DUPS "DUPS "DUPS ਌ ࢠ ଙ • ਌Actor͸ࢠActorͷ؂

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

    "DUPS "DUPS "DUPS "DUPS "DUPS ਌ ࢠ ଙ • ਌Actor͸ࢠActorʹ໰୊͕ൃੜ͢

    ΔͱઓུʹԊͬͯରԠ • ఀࢭ • ࠶ىಈʢActorΛ࠶ੜ੒͢Δʣ • ΤεΧϨʔγϣϯ ໰୊͕ൃੜ "DUPS͕ઓུʹԊͬͯɺରԠ Akka Actor - Supervisionʢิʣ
  18. 27.

    ActorͷScaling/Balancing /PEF /PEF /PEF -# ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ˞࣮ࡍʹ͸΋ͬͱଟ͘ͷ"DUPS͕

    Քಇ͢Δ͜ͱʹͳΔ /PEFؒʹ౉ͬͯɺ"DUPSΛల ։͢Δʹ͸ʁ ͲͷΑ͏ʹɺͲͷ/PEFʹͲͷ ঢ়ଶ͕͋Δ͔Λ஌Δ͜ͱ͕Ͱ͖ Δʁ
  19. 32.

    ͦΕͧΕຖʹϢχʔΫͳࣝผࢠ Λ"DUPSΛ&OUJUZͱݺͿ Akka Cluster Sharding +7. +7. +7. +7. 4IBSE

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

    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. 34.

    Akka Cluster Sharding +7. +7. +7. +7. 4IBSE 4IBSE 4IBSE

    4IBSE 4IBSE 4IBSE ୯ମͷϊʔυ্ͷ"DUPS $MVTUFS্Ͱ4IBSEJOH͞Εͨ"DUPS Ͳ͜ͷ4IBSEʹԿͷ&OUJUZ͕ଘࡏ ͢Δͷ͔΋؅ཧ͞Ε͍ͯΔ 4IBSEʹ9999ͱ͍͏&OUJUZ ͕ଘࡏ͢Δ
  22. 37.

    • ϊʔυؒͰClusterΛߏங͢Δ͜ͱ͕Ͱ͖Δ • ͜Ε·Ͱͷػೳ͸ϩʔΧϧͱಉ͡Α͏ʹѻ͏͜ͱ͕Ͱ͖ΔʢTransparencyʣ • ϝοηʔδύογϯά • Supervision(؂ಜ) • Akka

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

    /PEF /PEF /PEF ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS "LLB$MVTUFS "DUPSͷঢ়ଶ͕ফ͑ͳ͍ʁ ϊʔυʹো֐͕

    ൃੜʂ ϊʔυʹো֐͕ى͖ͨΓɺ"QQMJDBUJPO͕མͪͨΒ"DUPSͷঢ় ଶ͸ফ͑ͯ͠·͏ɻͨͩ͠"DUPSΛӬଓԽ͢Δํ๏͕༻ҙ͞Ε ͍ͯΔɻ ActorͷӬଓԽ
  24. 41.

    &WFOU4PVSDJOH͸"LLB 1FSTJTUFODFͷػೳͰ࣮ݱՄೳ "DUPS ActorͷӬଓԽ %#,74 %#,74ʹอଘ͢Δͷ͸ɺঢ়ଶͰ͸ͳ͘ɺΠϕϯτΛ อଘ͢Δʢ&WFOU4PVSDJOHʣ อଘ͢Δͷ͸ঢ়ଶΛมߋͨ͠Πϕϯτ ঢ়ଶ 

    $POGFSFODF /BNF$MPVE /BUJWF%BZT 5PLZP  5JDLFU νέοτΛຕొ࿥ νέοτ͕ຕചΕͨ νέοτ͕ຕചΕͨ ɾ ɾ ɾ
  25. 42.

    "DUPS ActorͷӬଓԽ %#,74 ো֐࣌ʹ͸ΠϕϯτΛશͯಡΈࠐΈɺঢ়ଶΛ෮ݩ͢Δ ঢ়ଶ  $POGFSFODF /BNF$MPVE /BUJWF%BZT 5PLZP

     5JDLFU νέοτΛຕొ࿥ νέοτ͕ຕചΕͨ νέοτ͕ຕചΕͨ ɾ ɾ ɾ Πϕϯτ͔Βঢ়ଶΛ෮ݩ͢Δ
  26. 43.

    εςʔτϨεͳΞϓϦέʔγϣϯ + DBʢ࠶ܝʣ "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS "QQMJDBUJPO 4FSWFS -#

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

    /PEF /PEF /PEF ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS ঢ়ଶ"DUPS "LLB$MVTUFS %#,74 εςʔτϑϧͳΞϓϦέʔγϣϯ

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

    7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    Akka Cluster on k8s - ֓ཁ
  29. 52.

    7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

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

    7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

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

    7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

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

    7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

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

    7. 7. 1PE +7. 1PE +7. 1PE +7. 1PE +7.

    "DUPSଆͷ$SBTI͸"DUPSͷ4VQFSWJTJPOͰରԠ $SBTI 4VQFSWJTJPOͰରԠ Akka Cluster on k8s - ো֐෮چ
  34. 58.

    +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

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

    +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

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

    +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

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

    +7. +7. +7. 1PE 1PE 1PE "LLB$MVTUFS Akka Cluster On

    k8s - Node௥Ճ "LLB$MVTUFSʹ͸ͳ͔ͬͨɺ4FSWJDF%JTDPWFSͷػೳΛ LT͕ิ׬ͯ͘͠ΕΔ +7. 1PE ৽نϊʔυ LT"1*
  38. 62.

    • Akka ClusterͷΈ͚ͩͰ͸ରԠͰ͖ͳ͔ͬͨ఺ΛKubernetes͕ Χόʔͯ͘͠ΕΔ • Akka Cluster͔ΒݟͨNodeͷScaleOut/In • Akka Cluster͔Βݟͨϊʔυͷো֐෮چ

    • Akka Cluster͔ΒݟͨଞϊʔυͷService Discovery • PodʹKubernetes API΁ͷΞΫηεݖݶΛ෇༩͢Δඞཁ͕͋Δ Akka Cluster On k8s - ·ͱΊ
  39. 63.
  40. 64.

    • ʢຊདྷ֎෦DV/KVSʹ͍࣋ͬͯΔʣঢ়ଶΛΞϓϦέʔγϣϯʹ͍࣋ͬͯΔͷ͕ɺεςʔτϑϧ ͳΞϓϦέʔγϣϯ • εςʔτϑϧͳΞϓϦέʔγϣϯ͸ଈԠੑ͕ߴ͍ • εςʔτϑϧͳΞϓϦέʔγϣϯΛߏ੒͢ΔͨΊʹActor ModelʢAkkaʣ͕͋Δ • Akka

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

    • 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 ࢀߟ