Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Reactive application with akka.NET & .NET Core

360 views

Published on

使用 Akka.NET 與 .NET Core 建立響應式應用程式

Published in: Software
  • Be the first to comment

Reactive application with akka.NET & .NET Core

  1. 1. www.dotnetconf.net
  2. 2. 介紹 Reactive & Actor Model 展示 Akka.NET 與 .NET Core 分享 Akka.NET 的心得 介紹 Akka.NET
  3. 3. (blackie1019.github.io) .NET JAVASCRIPT • 2017 ~ Current Microsoft MVP • 大內攻城(Software Engineering in .NET) – Organizer • Study4.TW – Member • A Polyglot/Polytheism Programmer - Believes in the art of finding the right tool for the job
  4. 4. 這場不會深入的討論如何把 Code 寫好寫滿
  5. 5. 主要是介紹 Akka.NET
  6. 6. 並透過實際展示,帶大家一 起認識 Akka.NET
  7. 7. 在真實的開發世界到底遇到 什麼需求? 功能需求與非功能需求
  8. 8. 非功能需求包括: 包括效能、質量、對外介 面與約束
  9. 9. https://tw.news.yahoo.com/%E5%B0%8F%E6%88%B4%E5%A5%AA%E9%87%91%E5%A4%A7%E9%BA%A5%E5%85%8B- %E9%80%81- %E7%B6%B2%E7%88%86%E9%80%99%E6%A8%A3%E6%90%AD%E9%85%8D%E6%9B%B4%E5%88%92%E7%AE%97- 045109008.html
  10. 10. https://www.eettaiwan.com/news/article/20170627NT01-Moores-Law-End-Reboots- Industry
  11. 11. 分散處理能從水平擴展(scale-out)獲得更好的效能
  12. 12. https://www.researchgate.net/figure/Amdahls- Law_fig2_309829008
  13. 13. http://slide.sports.sina.com.cn/k/slide_2_786_73435.html#p=1
  14. 14. http://i.imgur.com/mV9bFz7.gifhttp://img.fundiscuss.com/201707/fcdKNZcu.jpg
  15. 15. • 使用原子操作 (AO, Atomic Operations); • 使用不可變物件 (immutable objects)
  16. 16. https://www.reactivemanifesto.org/ Message Driven “Asynchronous message-passing” 達到模組隔離與委託處理提供負載 控制、彈性與流程控制 Responsive “SLA > Late Correct” 系統在任何情況下,都能及時響應 Resilient “Let it crash“ 系統在異常時,具有容錯性 Elastic “No central bottlenecks” 系統能依據需求彈性拓展
  17. 17. 什麼是 Actor Model – 是一種同時運算的概念模型
  18. 18. PRIVATE STATE Amount = $2 $10
  19. 19. ISOLATED ISOLATED ISOLATED 先進先出 IMMUATABLED DATA STRUCTURES 非同步 一次處理一個ADDRESS OF ACTOR 也可以傳送至非本機
  20. 20. 確認是否運行/活著 重啟
  21. 21. “Everything that exists is an object. Everything that happens is a function call.” - John Chambers
  22. 22. 萬物皆為 Actor,萬物皆由 訊息觸發
  23. 23. Actor是一個運算實體,回應 接受訊息,同時可發散的處 理不含有順序執行的操作, 因此可達到併行處理。
  24. 24. 達到二十年 99.9999999% (nine-nines, 九個九)的可用時間
  25. 25. https://www.pinterest.com/pin/662381057664258861/
  26. 26. 正式進入 Akka.NET
  27. 27. • Boeing • Bank of America • S&P Global • CitiGroup
  28. 28. 1973 Actor Model 發明此演算法 1987 Erlang 出現(未公開) 1997 Erlang 公開 2009 Akka(JVM) 出現 2015 Akka.NET v1.0 發佈 2017 Akka.NET v1.3.0 發佈 •Support .NET Core •Support .NET Standard 1.6 2018 Akka.NET v1.3.8 發佈 •Fully support Linux & .NET Core
  29. 29. *
  30. 30. https://dotnet.github.io/orleans/ https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable- actors-introduction http://proto.actor/
  31. 31. Akka.NET 開發與應用
  32. 32. Akka dotnet add package Akka
  33. 33. 兩種 Actor 建構方式 - generic version ActorSystem system = ActorSystem.Create("my-first-akka"); IActorRef typedActor = system.ActorOf<MyTypedActor>(); IActorRef untypedActor = system.ActorOf<MyUntypedActor>(); }
  34. 34. 兩種 Actor 建構方式 - nongeneric version ActorSystem system = ActorSystem.Create("my-first-akka"); Props typedActorProps = Akka.Actor.Props.Create<MyTypedActor>(); Props untypedActorProps = Akka.Actor.Props.Create<MyUntypedActor>(); IActorRef typedActor = system.ActorOf(typedActorProps); IActorRef untypedActor = system.ActorOf(untypedActorProps); } Props props1 = Akka.Actor Props.Create(typeof(MyTypedActor)); Props props2 = Akka.Actor Props.Create(() => new MyTypedActor("arg")); Props props3 = Akka.Actor Props.Create<MyTypedActor>(); Props props4 = Akka.Actor Props.Create(typeof(MyTypedActor), "arg"); 使用 Props 可協助定義 SupervisionStrategy 其他 Props 建構方式:
  35. 35. 兩種繼承類型 - UntypedActor public class MyUntypedActor : UntypedActor { protected override void OnReceive(object message) { var greeting = message as GreetingMessage; if (greeting != null) { GreetingMessageHandler(greeting); } } private void GreetingMessageHandler(GreetingMessage greeting) { Console.WriteLine($"Received a greeting: {greeting.Greeting}"); } }
  36. 36. 兩種繼承類型 - ReceiveActor public class MyTypedActor : ReceiveActor { public MyTypedActor() { Receive<GreetingMessage>(message => GreetingMessageHandler(message)); } private void GreetingMessageHandler(GreetingMessage greeting) { Console.WriteLine($"Received a greeting: {greeting.Greeting}"); } }
  37. 37. PreStartPostStart PostStopPreStart Stoep Msg
  38. 38. Context.Stop(Self) Context.Stop(childActorReference)
  39. 39. 接收PoisonPill訊息前的處理都結束才結束 Self.GraceStop(Timespan anytime); elf.Tell(Kill.Instance); Self.Tell(PoisonPill.Instance);
  40. 40. actorSystem.ActorOf() context.ActorOf() Top Level actors Child actors
  41. 41. akka://MyActorSystem/user/player-coordinator/John akka://MyActorSystem@localhost:8000/user/player-coordinator/John Protocol Actor system Address Path
  42. 42. MusicPlayerActor
  43. 43. • Resume 重新啟動並仍然保持其內部狀態 • Restart 重新啟動並但清空其內部狀態 • Stop 立即終止當前出問題的 Actor • Escalate 該層的 supervisor actor 自己會丟出錯誤,將問題再交由更上層的 Supervision 處理
  44. 44. https://youtu.be/CC2XdYlpmvo
  45. 45. RoundRobin Broadcast Random ConsistentHashing TailChopping ScatterGatherFirstCompleted SmallestMailbox
  46. 46. https://getakka.net/articles/actors/routers.html#roundrobin
  47. 47. https://getakka.net/articles/actors/routers.html#smallestmailb ox
  48. 48. https://getakka.net/articles/actors/routers.html#broadcast
  49. 49. • 在 CQRS 或是 Domain Driven Design https://getakka.net/articles/actors/routers.html#consistenthas hing
  50. 50. http://doc.akka.io/docs/akka/2.3.4/general/addressing.html
  51. 51. 在開發與使用時,完全不用去理會底層網路的建置
  52. 52. 排除單點故障/瓶頸 • 有多個節點能夠為請求提供服務,從而提高吞吐量 和容錯能力 https://getakka.net/articles/clustering/cluster-overview.html#cluster- gossip
  53. 53. • 分散與去中心化 • 可以建立點對點通信 • 解決單點故障 • 進而提高吞吐量和容錯能力 帶來的幫助
  54. 54. https://vimeo.com/193462577https://www.slideshare.net/riccardoscannicchio?utm_campaign =profiletracking&utm_medium=sssite&utm_source=ssslideview
  55. 55. https://github.com/IBM/Akka-cluster-deploy-kubernetes
  56. 56. http://zipkin.io Google Dapper paper https://www.youtube.com/watch?v=zv1PdDrisNY
  57. 57. https://youtu.be/x5uMBJg2AIk
  58. 58. https://octopus.com/ https://twitter.com/philiplaureano/status/7359760189937786 88
  59. 59. 在正式使用 Akka.NET 前那 些你應該知道但可能不知道 的事
  60. 60. https://github.com/akkadotnet/akka.net/issues/3506
  61. 61. • • • https://github.com/akkadotnet/akka.net/issues/2378
  62. 62. https://www.cpubenchmark.net/compare/Intel-i7-8850H-vs-Intel-Xeon-Platinum- 8173M/3247vs3182
  63. 63. 點到點整條線路都通順才是重點!
  64. 64. • Actors 不應該有任何阻擋(block),善用 event- driven • 不要在actors 傳遞可變物件(mutable objects) • 避免在 Actors 透過傳遞信息(messages)時同時傳 遞行為(behavior) • Top-level actors 是最內層的錯誤核心(Error Kernel), 管理者,善用樹狀繼承能更有效進行故障排除與 處理 https://getakka.net/articles/concepts/actor-systems.html#actor-best- practices
  65. 65. Monolithi c Applicatio n Microservic e Functio n Microservic e Microservic e Functio n Functio n Functio n Functio n
  66. 66. “To me, it is exciting to see principles that work so well at the microscopic level (programming) to also work at the macroscopic level (architecture).”https://www.linkedin.com/pulse/microservices-return-unix-philosophy-kenneth- chai/
  67. 67. https://tinyurl.com/y9jetp et
  68. 68. https://petabridge.com/bootcamp/ https://app.pluralsight.com/player?course=akka-dotnet-actor-model-building- concurrent-applications https://www.manning.com/books/reactive-applications-with-akka-net https://www.syncfusion.com/ebooks/akka_net_succinctly
  69. 69. http://getakka.net/ https://petabridge.com/bootcamp/ https://akka.io/ https://twitter.com/AkkaDotNET https://gitter.im/akkadotnet/akka.net
  70. 70. R-LADIES TAIPEI 台灣軟體工程學會

×