SlideShare a Scribd company logo
1 of 105
www.dotnetconf.net
介紹
Reactive & Actor Model
展示
Akka.NET 與 .NET Core
分享
Akka.NET 的心得
介紹
Akka.NET
(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
這場不會深入的討論如何把
Code 寫好寫滿
主要是介紹 Akka.NET
並透過實際展示,帶大家一
起認識 Akka.NET
在真實的開發世界到底遇到
什麼需求?
功能需求與非功能需求
非功能需求包括:
包括效能、質量、對外介
面與約束
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
https://www.eettaiwan.com/news/article/20170627NT01-Moores-Law-End-Reboots-
Industry
分散處理能從水平擴展(scale-out)獲得更好的效能
https://www.researchgate.net/figure/Amdahls-
Law_fig2_309829008
http://slide.sports.sina.com.cn/k/slide_2_786_73435.html#p=1
http://i.imgur.com/mV9bFz7.gifhttp://img.fundiscuss.com/201707/fcdKNZcu.jpg
• 使用原子操作 (AO, Atomic Operations);
• 使用不可變物件 (immutable objects)
https://www.reactivemanifesto.org/
Message Driven
“Asynchronous message-passing”
達到模組隔離與委託處理提供負載
控制、彈性與流程控制
Responsive
“SLA > Late Correct”
系統在任何情況下,都能及時響應
Resilient
“Let it crash“
系統在異常時,具有容錯性
Elastic
“No central bottlenecks”
系統能依據需求彈性拓展
什麼是 Actor Model –
是一種同時運算的概念模型
PRIVATE STATE
Amount = $2 $10
ISOLATED ISOLATED
ISOLATED
先進先出
IMMUATABLED
DATA STRUCTURES
非同步
一次處理一個ADDRESS OF ACTOR
也可以傳送至非本機
確認是否運行/活著
重啟
“Everything that exists is
an object. Everything that
happens is a function
call.”
- John Chambers
萬物皆為 Actor,萬物皆由
訊息觸發
Actor是一個運算實體,回應
接受訊息,同時可發散的處
理不含有順序執行的操作,
因此可達到併行處理。
達到二十年 99.9999999% (nine-nines, 九個九)的可用時間
https://www.pinterest.com/pin/662381057664258861/
正式進入 Akka.NET
• Boeing
• Bank of America
• S&P Global
• CitiGroup
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
*
https://dotnet.github.io/orleans/
https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-
actors-introduction
http://proto.actor/
Akka.NET 開發與應用
Akka
dotnet add package Akka
兩種 Actor 建構方式 - generic version
ActorSystem system = ActorSystem.Create("my-first-akka");
IActorRef typedActor = system.ActorOf<MyTypedActor>();
IActorRef untypedActor = system.ActorOf<MyUntypedActor>(); }
兩種 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 建構方式:
兩種繼承類型 - 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}");
}
}
兩種繼承類型 - ReceiveActor
public class MyTypedActor : ReceiveActor {
public MyTypedActor() {
Receive<GreetingMessage>(message => GreetingMessageHandler(message));
}
private void GreetingMessageHandler(GreetingMessage greeting)
{
Console.WriteLine($"Received a greeting: {greeting.Greeting}");
}
}
PreStartPostStart
PostStopPreStart Stoep
Msg
Context.Stop(Self)
Context.Stop(childActorReference)
接收PoisonPill訊息前的處理都結束才結束
Self.GraceStop(Timespan anytime);
elf.Tell(Kill.Instance);
Self.Tell(PoisonPill.Instance);
actorSystem.ActorOf()
context.ActorOf()
Top Level actors
Child actors
akka://MyActorSystem/user/player-coordinator/John
akka://MyActorSystem@localhost:8000/user/player-coordinator/John
Protocol Actor system Address Path
MusicPlayerActor
• Resume
重新啟動並仍然保持其內部狀態
• Restart
重新啟動並但清空其內部狀態
• Stop
立即終止當前出問題的 Actor
• Escalate
該層的 supervisor actor 自己會丟出錯誤,將問題再交由更上層的
Supervision 處理
https://youtu.be/CC2XdYlpmvo
RoundRobin
Broadcast
Random
ConsistentHashing
TailChopping
ScatterGatherFirstCompleted
SmallestMailbox
https://getakka.net/articles/actors/routers.html#roundrobin
https://getakka.net/articles/actors/routers.html#smallestmailb
ox
https://getakka.net/articles/actors/routers.html#broadcast
• 在 CQRS 或是 Domain Driven Design
https://getakka.net/articles/actors/routers.html#consistenthas
hing
http://doc.akka.io/docs/akka/2.3.4/general/addressing.html
在開發與使用時,完全不用去理會底層網路的建置
排除單點故障/瓶頸
• 有多個節點能夠為請求提供服務,從而提高吞吐量
和容錯能力
https://getakka.net/articles/clustering/cluster-overview.html#cluster-
gossip
• 分散與去中心化
• 可以建立點對點通信
• 解決單點故障
• 進而提高吞吐量和容錯能力
帶來的幫助
https://vimeo.com/193462577https://www.slideshare.net/riccardoscannicchio?utm_campaign
=profiletracking&utm_medium=sssite&utm_source=ssslideview
https://github.com/IBM/Akka-cluster-deploy-kubernetes
http://zipkin.io
Google Dapper paper
https://www.youtube.com/watch?v=zv1PdDrisNY
https://youtu.be/x5uMBJg2AIk
https://octopus.com/
https://twitter.com/philiplaureano/status/7359760189937786
88
在正式使用 Akka.NET 前那
些你應該知道但可能不知道
的事
https://github.com/akkadotnet/akka.net/issues/3506
•
•
•
https://github.com/akkadotnet/akka.net/issues/2378
https://www.cpubenchmark.net/compare/Intel-i7-8850H-vs-Intel-Xeon-Platinum-
8173M/3247vs3182
點到點整條線路都通順才是重點!
• 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
Monolithi
c
Applicatio
n
Microservic
e
Functio
n
Microservic
e
Microservic
e
Functio
n
Functio
n
Functio
n
Functio
n
“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/
https://tinyurl.com/y9jetp
et
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
http://getakka.net/
https://petabridge.com/bootcamp/
https://akka.io/
https://twitter.com/AkkaDotNET
https://gitter.im/akkadotnet/akka.net
R-LADIES TAIPEI
台灣軟體工程學會

More Related Content

What's hot

容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 
极速 Angular 开发:效能调校技巧 (ngChina 2019)
极速 Angular 开发:效能调校技巧 (ngChina 2019)极速 Angular 开发:效能调校技巧 (ngChina 2019)
极速 Angular 开发:效能调校技巧 (ngChina 2019)Will Huang
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17 SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17 twMVC
 
玩轉 .NET Interactive Notebooks 一次就上手
玩轉 .NET Interactive Notebooks 一次就上手玩轉 .NET Interactive Notebooks 一次就上手
玩轉 .NET Interactive Notebooks 一次就上手Poy Chang
 
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享Duran Hsieh
 
不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...
不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...
不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...Alan Tsai
 
Angular 7 全新功能探索 (Angular Taiwan 2018)
Angular 7 全新功能探索 (Angular Taiwan 2018)Angular 7 全新功能探索 (Angular Taiwan 2018)
Angular 7 全新功能探索 (Angular Taiwan 2018)Will Huang
 
PHP CodeIgniter 框架之美
PHP CodeIgniter 框架之美PHP CodeIgniter 框架之美
PHP CodeIgniter 框架之美Amigo 陳兆祥
 
我們與Azure DevOps的距離
我們與Azure DevOps的距離我們與Azure DevOps的距離
我們與Azure DevOps的距離Edward Kuo
 
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2Alan Tsai
 
Angular Conf 2018 - 原來 Angular 可以這樣玩設定
Angular Conf 2018 - 原來 Angular 可以這樣玩設定Angular Conf 2018 - 原來 Angular 可以這樣玩設定
Angular Conf 2018 - 原來 Angular 可以這樣玩設定Poy Chang
 
Micro-frontends with Angular 10 (Modern Web 2020)
Micro-frontends with Angular 10 (Modern Web 2020)Micro-frontends with Angular 10 (Modern Web 2020)
Micro-frontends with Angular 10 (Modern Web 2020)Will Huang
 
Angular 开发技巧 (2018 ngChina 开发者大会)
Angular 开发技巧 (2018 ngChina 开发者大会)Angular 开发技巧 (2018 ngChina 开发者大会)
Angular 开发技巧 (2018 ngChina 开发者大会)Will Huang
 
20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務
20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務
20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務Alan Tsai
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練22016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2Duran Hsieh
 
Vue 和 Angular 開發習慣
Vue 和 Angular 開發習慣Vue 和 Angular 開發習慣
Vue 和 Angular 開發習慣Poy Chang
 
Codeigniter 3.0 之 30 分鐘就上手
Codeigniter 3.0 之 30 分鐘就上手Codeigniter 3.0 之 30 分鐘就上手
Codeigniter 3.0 之 30 分鐘就上手Piece Chao
 
Angular js twmvc#17
Angular js twmvc#17Angular js twmvc#17
Angular js twmvc#17twMVC
 
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例Will Huang
 
Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Will Huang
 

What's hot (20)

容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 
极速 Angular 开发:效能调校技巧 (ngChina 2019)
极速 Angular 开发:效能调校技巧 (ngChina 2019)极速 Angular 开发:效能调校技巧 (ngChina 2019)
极速 Angular 开发:效能调校技巧 (ngChina 2019)
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17 SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17
 
玩轉 .NET Interactive Notebooks 一次就上手
玩轉 .NET Interactive Notebooks 一次就上手玩轉 .NET Interactive Notebooks 一次就上手
玩轉 .NET Interactive Notebooks 一次就上手
 
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
 
不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...
不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...
不會 Javascript 沒關係,用 Blazor 來解決前端需求 - 成為 Full Stack .NET 開發者吧 - .NET Conf 2020...
 
Angular 7 全新功能探索 (Angular Taiwan 2018)
Angular 7 全新功能探索 (Angular Taiwan 2018)Angular 7 全新功能探索 (Angular Taiwan 2018)
Angular 7 全新功能探索 (Angular Taiwan 2018)
 
PHP CodeIgniter 框架之美
PHP CodeIgniter 框架之美PHP CodeIgniter 框架之美
PHP CodeIgniter 框架之美
 
我們與Azure DevOps的距離
我們與Azure DevOps的距離我們與Azure DevOps的距離
我們與Azure DevOps的距離
 
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
Visual Studio 開發密技大補帖 | Study4.TW 2021 小聚#2
 
Angular Conf 2018 - 原來 Angular 可以這樣玩設定
Angular Conf 2018 - 原來 Angular 可以這樣玩設定Angular Conf 2018 - 原來 Angular 可以這樣玩設定
Angular Conf 2018 - 原來 Angular 可以這樣玩設定
 
Micro-frontends with Angular 10 (Modern Web 2020)
Micro-frontends with Angular 10 (Modern Web 2020)Micro-frontends with Angular 10 (Modern Web 2020)
Micro-frontends with Angular 10 (Modern Web 2020)
 
Angular 开发技巧 (2018 ngChina 开发者大会)
Angular 开发技巧 (2018 ngChina 开发者大会)Angular 开发技巧 (2018 ngChina 开发者大会)
Angular 开发技巧 (2018 ngChina 开发者大会)
 
20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務
20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務
20200425 GlobalAzure-Azure API Management-協助邁向Open API及Micro Service架構的好用服務
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練22016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
 
Vue 和 Angular 開發習慣
Vue 和 Angular 開發習慣Vue 和 Angular 開發習慣
Vue 和 Angular 開發習慣
 
Codeigniter 3.0 之 30 分鐘就上手
Codeigniter 3.0 之 30 分鐘就上手Codeigniter 3.0 之 30 分鐘就上手
Codeigniter 3.0 之 30 分鐘就上手
 
Angular js twmvc#17
Angular js twmvc#17Angular js twmvc#17
Angular js twmvc#17
 
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
 
Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)
 

Similar to Reactive application with akka.NET & .NET Core

Ecma script edition5-小试
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试lydiafly
 
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)Will Huang
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introductionotakustay
 
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練42015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4Duran Hsieh
 
Javascript primer plus
Javascript primer plusJavascript primer plus
Javascript primer plusDongxu Yao
 
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式Will Huang
 
Javascript之昨是今非
Javascript之昨是今非Javascript之昨是今非
Javascript之昨是今非Tony Deng
 
Struts Mitac(1)
Struts Mitac(1)Struts Mitac(1)
Struts Mitac(1)wangjiaz
 
Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文Guo Albert
 
一拍一产品背后的故事(React实战)
一拍一产品背后的故事(React实战)一拍一产品背后的故事(React实战)
一拍一产品背后的故事(React实战)Kejun Zhang
 
信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressAppzhoujg
 
Django development
Django developmentDjango development
Django developmentloveyudu
 
Struts学习笔记
Struts学习笔记Struts学习笔记
Struts学习笔记yiditushe
 
RxJS 6 新手入門
RxJS 6 新手入門RxJS 6 新手入門
RxJS 6 新手入門Will Huang
 
Java Script 引擎技术
Java Script 引擎技术Java Script 引擎技术
Java Script 引擎技术bigqiang zou
 
Web development with zend framework
Web development with zend frameworkWeb development with zend framework
Web development with zend frameworkthinkinlamp
 

Similar to Reactive application with akka.NET & .NET Core (20)

Ecma script edition5-小试
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试
 
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introduction
 
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練42015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
 
Javascript primer plus
Javascript primer plusJavascript primer plus
Javascript primer plus
 
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
 
Javascript之昨是今非
Javascript之昨是今非Javascript之昨是今非
Javascript之昨是今非
 
Struts Mitac(1)
Struts Mitac(1)Struts Mitac(1)
Struts Mitac(1)
 
Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文
 
一拍一产品背后的故事(React实战)
一拍一产品背后的故事(React实战)一拍一产品背后的故事(React实战)
一拍一产品背后的故事(React实战)
 
信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp信息系统开发平台OpenExpressApp
信息系统开发平台OpenExpressApp
 
Django development
Django developmentDjango development
Django development
 
Js培训
Js培训Js培训
Js培训
 
Struts学习笔记
Struts学习笔记Struts学习笔记
Struts学习笔记
 
Python系列4
Python系列4Python系列4
Python系列4
 
RxJS 6 新手入門
RxJS 6 新手入門RxJS 6 新手入門
RxJS 6 新手入門
 
Berserk js
Berserk jsBerserk js
Berserk js
 
Dev307
Dev307Dev307
Dev307
 
Java Script 引擎技术
Java Script 引擎技术Java Script 引擎技术
Java Script 引擎技术
 
Web development with zend framework
Web development with zend frameworkWeb development with zend framework
Web development with zend framework
 

More from Chen-Tien Tsai

關於軟體工程師職涯的那些事
關於軟體工程師職涯的那些事關於軟體工程師職涯的那些事
關於軟體工程師職涯的那些事Chen-Tien Tsai
 
.NET Security Application/Web Development - Part IV
.NET Security Application/Web Development - Part IV.NET Security Application/Web Development - Part IV
.NET Security Application/Web Development - Part IVChen-Tien Tsai
 
.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part III.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part IIIChen-Tien Tsai
 
.NET Security Application/Web Development - Part II
.NET Security Application/Web Development - Part II.NET Security Application/Web Development - Part II
.NET Security Application/Web Development - Part IIChen-Tien Tsai
 
.NET Security Application/Web Development - Part I
.NET Security Application/Web Development - Part I.NET Security Application/Web Development - Part I
.NET Security Application/Web Development - Part IChen-Tien Tsai
 
.NET Security Application/Web Development - Overview
.NET Security Application/Web Development - Overview.NET Security Application/Web Development - Overview
.NET Security Application/Web Development - OverviewChen-Tien Tsai
 
Designing distributedsystems cht6
Designing distributedsystems cht6Designing distributedsystems cht6
Designing distributedsystems cht6Chen-Tien Tsai
 
The Cloud - What's different
The Cloud - What's differentThe Cloud - What's different
The Cloud - What's differentChen-Tien Tsai
 
How to be a professional speaker
How to be a professional speakerHow to be a professional speaker
How to be a professional speakerChen-Tien Tsai
 
響應式程式開發之 .NET Core 應用 
響應式程式開發之 .NET Core 應用 響應式程式開發之 .NET Core 應用 
響應式程式開發之 .NET Core 應用 Chen-Tien Tsai
 
Artifacts management with DevOps
Artifacts management with DevOpsArtifacts management with DevOps
Artifacts management with DevOpsChen-Tien Tsai
 
Web optimization with service woker
Web optimization with service wokerWeb optimization with service woker
Web optimization with service wokerChen-Tien Tsai
 
GCPUG.TW Meetup #25 - ASP.NET Core with GCP
GCPUG.TW Meetup #25 - ASP.NET Core with GCPGCPUG.TW Meetup #25 - ASP.NET Core with GCP
GCPUG.TW Meetup #25 - ASP.NET Core with GCPChen-Tien Tsai
 
.NET Study Group - ASP.NET Core with GCP
.NET Study Group - ASP.NET Core with GCP.NET Study Group - ASP.NET Core with GCP
.NET Study Group - ASP.NET Core with GCPChen-Tien Tsai
 
Webpack and Web Performance Optimization
Webpack and Web Performance OptimizationWebpack and Web Performance Optimization
Webpack and Web Performance OptimizationChen-Tien Tsai
 
DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactChen-Tien Tsai
 
Website Auto scraping with Autoit and .Net HttpRequest
Website Auto scraping with Autoit and .Net HttpRequestWebsite Auto scraping with Autoit and .Net HttpRequest
Website Auto scraping with Autoit and .Net HttpRequestChen-Tien Tsai
 
C# 2 to 5 short Introduction
C# 2 to 5 short IntroductionC# 2 to 5 short Introduction
C# 2 to 5 short IntroductionChen-Tien Tsai
 

More from Chen-Tien Tsai (20)

關於軟體工程師職涯的那些事
關於軟體工程師職涯的那些事關於軟體工程師職涯的那些事
關於軟體工程師職涯的那些事
 
.NET Security Application/Web Development - Part IV
.NET Security Application/Web Development - Part IV.NET Security Application/Web Development - Part IV
.NET Security Application/Web Development - Part IV
 
.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part III.NET Security Application/Web Development - Part III
.NET Security Application/Web Development - Part III
 
.NET Security Application/Web Development - Part II
.NET Security Application/Web Development - Part II.NET Security Application/Web Development - Part II
.NET Security Application/Web Development - Part II
 
.NET Security Application/Web Development - Part I
.NET Security Application/Web Development - Part I.NET Security Application/Web Development - Part I
.NET Security Application/Web Development - Part I
 
.NET Security Application/Web Development - Overview
.NET Security Application/Web Development - Overview.NET Security Application/Web Development - Overview
.NET Security Application/Web Development - Overview
 
Designing distributedsystems cht6
Designing distributedsystems cht6Designing distributedsystems cht6
Designing distributedsystems cht6
 
The Cloud - What's different
The Cloud - What's differentThe Cloud - What's different
The Cloud - What's different
 
How to be a professional speaker
How to be a professional speakerHow to be a professional speaker
How to be a professional speaker
 
Agile tutorial
Agile tutorialAgile tutorial
Agile tutorial
 
響應式程式開發之 .NET Core 應用 
響應式程式開發之 .NET Core 應用 響應式程式開發之 .NET Core 應用 
響應式程式開發之 .NET Core 應用 
 
Artifacts management with DevOps
Artifacts management with DevOpsArtifacts management with DevOps
Artifacts management with DevOps
 
Web optimization with service woker
Web optimization with service wokerWeb optimization with service woker
Web optimization with service woker
 
GCPUG.TW Meetup #25 - ASP.NET Core with GCP
GCPUG.TW Meetup #25 - ASP.NET Core with GCPGCPUG.TW Meetup #25 - ASP.NET Core with GCP
GCPUG.TW Meetup #25 - ASP.NET Core with GCP
 
.NET Study Group - ASP.NET Core with GCP
.NET Study Group - ASP.NET Core with GCP.NET Study Group - ASP.NET Core with GCP
.NET Study Group - ASP.NET Core with GCP
 
Webpack and Web Performance Optimization
Webpack and Web Performance OptimizationWebpack and Web Performance Optimization
Webpack and Web Performance Optimization
 
DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
 
Website Auto scraping with Autoit and .Net HttpRequest
Website Auto scraping with Autoit and .Net HttpRequestWebsite Auto scraping with Autoit and .Net HttpRequest
Website Auto scraping with Autoit and .Net HttpRequest
 
C# 2 to 5 short Introduction
C# 2 to 5 short IntroductionC# 2 to 5 short Introduction
C# 2 to 5 short Introduction
 
Docker - fundamental
Docker  - fundamentalDocker  - fundamental
Docker - fundamental
 

Reactive application with akka.NET & .NET Core

Editor's Notes

  1. 11:10 – 12:00 [1-2 mins] Opening & Self-briefing [3-5 mins] Why Distributed & Actor Pattern [35 mins] Akka.NET What is Key features Akka.NET basic concept [10 mins ]How it works Put it into REAL : Integrating with .NET Core(Console) Put it into REAL : How to test it [5 mins] Supervision [5 mins] Routers Put it into REAL : Integrating with HA [5 mins] Akka.Remote [5 mins] Akka.Cluster [5 mins] Akka.NET & MVC Akka.NET and Container Put it into REAL : Integrating with React & SignalR(Web) [10 mins] Others Real things Top tips Benefit and comparison
  2. 效能需求(performance requirement) 質量屬性(quality attribute) 對外介面(external interface) 約束(constraint) 原文網址:https://itw01.com/YBRRED3.html
  3. 把問題丟給台下
  4. While there are several approaches to implementing a multithreaded, concurrent, scalable, and distributed system, the actor model paradigm is recently (re)emerging. As we are going to see, this is not a new approach, but certainly a good one that is worth exploring. When building applications, we can now effectively concentrate on making systems in a different way compared to the past. Today we can effectively utilize resources to work together and constitute a single application platform. This obviously brings a lot of new opportunities, and with them some challenges—as usually nothing comes for “free.” Everything got bigger, distributed, and parallelized! Building concurrent system is hard Building distributed system is also hard Building robust resilient application is very hard.
  5. https://www.slideshare.net/GlobalLogicUkraine/take-a-look-at-akkajava-english-version
  6. https://yuchungchuang.wordpress.com/2018/07/24/c-%E5%A4%9A%E5%9F%B7%E8%A1%8C%E7%B7%923-%E4%BA%92%E6%96%A5%E9%8E%96-mutex/
  7. 執行緒安全是編程中的術語,指某個函數、函數庫在多執行緒環境中被調用時,能夠正確地處理多個執行緒之間的共享變量,使程序功能正確完成。 避免發生共用 使用可重入 (Reentrancy) 技術: 把靜態變數及全域變數全部改為區域變數 (區域變數通常放在 stack 區, 可以順利避免共用). 使用執行緒自身的儲存空間 (TLS, Thread Local Storage): 所以每一個執行緒都不同, 都有自己的一份拷貝. (C11 支援加上 keyword _Thread_local 來將變數移到 TLS; C++11 改用 keyword thread_local; gnu 或者其他 C++ compiler 則用 keyword __thread) 當無法避免共用時, 採用鎖定 (同步) 機制 使用互斥鎖 (Mutex, Mutual Exclusion): 利用序列化機制 (serialization) 來保證任一時間點都只有一個執行緒讀或寫共用資料. 但是多個 mutex 一起運作時需要小心仔細的對待, 不恰當的實作可能引起一些負作用, 如: deadlocks, livelocks, resource starvation. 使用原子操作 (AO, Atomic Operations): 在存取共用資料時禁止被其他執行緒打斷. 一般實作上需要一些新的硬體指令來支援, 它是實作執行緒鎖定的元件, 也是前一項 mutex 實作的基礎. 現代的多核 CPU (x86, MIPS, ARMv6 and later) 都至少有支援一對指令可以協助完成 AO 動作 (可能只支援部份 AO). 單核 CPU 在 OS 核心的部份可以用中斷鎖定 (disable/enable interrupt) 來支援 AO 的需求. 但是如果是在用戶空間 (user-space) 卻是不可以可能是不可行, 詳細請參考: Emulated atomic operations and real-time scheduling. 使用不可變物件 (immutable objects): 物件構建 (construct) 之後即無法改變內容. 要實作改變時, 是以重新構建 (re-construct) 來取代修改現有之內容.
  8. 轉換一下話題,來談談質量 響應式系統具備靈活性,鬆耦合和可擴展性。這使得它們更容易去開發、修改。而對 Error 與 Exception 有更大的容忍,並且當狀況發生時它們會更優雅地應對而不是讓直接系統崩潰。反應式系統有著高度的響應性,並會給用戶有效的交互反饋。 響應式系统是: Responsive 響應式(reacts to events at the speed of environment) 系統在任何情況下,都能及時響應,在可靠的時間(SLA)內提供訊息且有穩定品質的服務。 Resilient 韌性、堅固, 具有容錯性(Fault-tolerant) 系統在失敗時,發出對應的訊息.這可使系統仍然保有 Responsive 特性。這是由 replication (複製), containment (容忍), isolation (隔離)以及 delegation (委託)的方式達成的。系統的任何組件發生問題時,可以隔離此部份,並獨立恢復,過程中不會影響整個系統。 Elastic 彈性(Easy Scale up/down and out) 即時量測效能,可透過演算法增加或減少服務的資源分配,滿足不同工作負載量的系統要求。 Message Driven 訊息驅動(modular, pipelined, asynchronous) 組件之間透過非同步訊息傳遞方式互相溝通,用以確保 loose coupling (鬆耦合), isolation (隔離), location transparency (與區域無關)、failures as messages提供錯誤訊息的委託處理機制的特性。 能給予負載控制
  9. 一個訊息處理的演算法. 參與者模型推崇的哲學是「一切皆是參與者」,這與物件導向程式設計的「一切皆是物件」類似,但是物件導向程式設計通常是順序執行的,而參與者模型是並列執行的。 同時運算 => Concurrent Computation 概念模型 => Conceptual Model 1973 提出來的
  10. IMMUATABLED 不變資料 ACTOR ONLY PROCESS 1 MESSAGE AT A TIME
  11. 容錯 Fault Tolerance
  12. R語言的定義
  13. R語言的定義
  14. 參與者是一個運算實體,回應接受到的訊息,同時並列的: 傳送有限數量的訊息給其他參與者; 建立有限數量的新參與者; 指定接受到下一個訊息時的行為。 以上操作不含有順序執行的假設,因此可以並列進行。
  15. 訊息接收者是通過位址區分的,有時也被稱作「郵件位址」。因此參與者只能和它擁有位址的參與者通訊。它可以通過接受到的資訊取得位址,或者取得它建立的參與者的位址。 參與者模型的特徵是,參與者內部或之間進行平行計算,參與者可以動態建立,參與者位址包含在訊息中,互動只有通過直接的異步訊息通訊,不限制訊息到達的順序。 Erlang 曾在 AXD301 ATM 機器上達到二十年 99.9999999% (nine-nines, 九個九)的可用時間。更能在不關機的情況下,直接修正有錯誤的程式碼,而且不影響到正常使用的使用者
  16. https://www.brianstorti.com/the-actor-model/
  17. It is a Actor Model base, Distributed by Default and built-in Supervision & monitoring can build powerful concurrent & distributed applications for more Reactive. Akka.NET simplify the building of scalable, concurrent, high-throughput and low latency systems. An elite group of projects who joined .NET Foundation on 2017
  18. is a world leader in building distributed systems and distributed systems tools in the .NET ecosystem; we serve our customers by providing them with professional-grade open source software packages, proprietary tooling, consulting, training, and support. Founded in 2015 in Los Angeles, California, Petabridge has been rapidly growing over the past 3 years. In 2017 we relocated from Los Angeles to Houston, Texas. Our customers span the globe, ranging from Fortune 500 companies like Boeing, Bank of America, S&P Global, and CitiGroup to early stage startups; we help them succeed by developing better, more resilient systems on the backs of open source technologies we develop such as Akka.NET, NBench, and others.
  19. 2014 Early version of Akka.NET is development
  20. Simplify the building of scalable, concurrent, high-throughput and low latency systems. 開源(Open Source) 不用手動管理執行緒,技術架構與實體 CPU核心架構解耦 能實作更高層次的抽象層 actors, messages, FSMs Asynchronous 高效能* ~ 50 million messages per second per machine 1GB heap memory =~ 2. million actors Load balancing / routing requests to child actors 支援 Scaling up 支援 Scaling out Location transparency Remote deployment using configuration 支援容錯與彈性的錯誤處理 Self-healing Supervisory Hierarchies and fault isolation 可作為套件(package)、 框架 (framework) 或架構(Architecture) 使用
  21. Bank of America, SNL Financial, Schneider Electric, Boeing, and others.  https://www.lightbend.com/case-studies/uks-online-gaming-leader-bets-big-on-reactive-to-drive-real-time-personalization
  22. Actor contains all the computations. Actors can communicate only through messages. Actors can change their state or behavior. Actors can send messages to other actors. Actors can create a finite number of child actors.
  23. Demo Features Akka.NET Hello world UntypedActor and ReceiveActor(TypeActor) Tell, Ask, Forward
  24. By using Props, we can define a SupervisionStrategy,
  25. By using Props, we can define a SupervisionStrategy,
  26. The difference in this case is that when the actor encounters this kind of message, an exception will be thrown (ActorKilledExeption). This can be pretty useful if we want to show in logs that the actor was terminated. The usage of this seems to be rare, but it’s good to know. 
  27. PoisonPill是一種特殊的消息(系統消息),它指示演員在收到此類消息後自行關閉。但是,只有在接收PoisonPill消息之前執行作為郵箱一部分的所有消息後,actor才會停止。之後發出的消息(如果有的話)將拋出錯誤(因為實際上,actor不再存在) The difference in this case is that when the actor encounters this kind of message, an exception will be thrown (ActorKilledExeption). This can be pretty useful if we want to show in logs that the actor was terminated. The usage of this seems to be rare, but it’s good to know. 
  28. Demo Features Actor LifeCycle Stop & GracefulStop Actor
  29. Protocol  akka://  Defines the communication protocol Akka.NET uses to communicate between actors. This is especially useful when it comes to the remote deployments of actors. For instance, we can define the use of the tcp protocol, such as akka.tcp or akka.udp.  Actor system  my-first-akka  The name of the ActorSystem to which the actor belongs.  Address  @localhost:8000  In case of remote deployment of actors (actors running on another system), there is a possibility to also add the address location of that system.  Path  player-coordinator/John  Refers to the path of this actor in the hierarchy. 
  30. ActorContext (or just Context, as this is how the actor base library exposes it) exposes contextual information for the actor and the current message. It provides more information, such as: factory methods to create child actors (in the same way the ActorSystem does), lifecycle monitoring, supervised children, and so on. 
  31. Resume  Resuming a subordinate means that the subactor will be restarted, but it still keeps its internal state. This means the actor, after resuming, will keep doing its work from the point it stopped.  Resuming an actor also means resuming all of its own subordinates. This is a chained operation!  Restart  This would completely clear out any subordinate’s internal state. However, the messages that are in the queue remain intact!  This also means all of the subordinates’ created actors will be restarted.  Stop  Stops the subordinate permanently.  Escalate  This means the supervisor actor is not handling the error itself, but the handling of it is escalated to the supervisor’s parent actor.  The supervisor actor is failing itself! 
  32. OneForOneStrategy: This strategy will apply the directive only to the failing actor that has thrown an error. No other actors are affected.  AllForOneStrategy: This strategy applies the directive to all of its children. This is particularly useful if the children actors are dependent on each other, so that the failure of one brings the logical failure of others. 
  33. Multiple Actor and Actor's data ActorSystem path Actor behavior - Become() Supervision
  34. 大部份Routing 策略 Pool 與 Group 兩種都支援
  35. ConsistentHash can be very useful when dealing with Commands in the sense of CQRS or [Domain Driven Design].
  36. Demo Features Round Robin Random routing Shortest Mailbox queue Consistent Hashing  Broadcast
  37. Akka.NET remoting enables communication between ActorSystems deployed on different application processes. This might include a different process on a single machine, or a completely different server.  By default, Akka.NET uses the DotNetty library for the TCP transport. The responsibilities of the transport in Akka.NET are as follows:  IP addressing and ports: All Akka.NET endpoints (client and servers) have to be accessible by an IP address and port.  Message delivery: Should enable the delivery of messages from ActorSystem A to ActorSystem B.  Message framing: Distinguishes individual messages within a network stream.  Disconnect and error reporting: Tells Akka.Remote when a disconnect or transport error occurred.  Preserving message order (optimal): Some transports (like UDP) make no such guarantees, but in general, it's recommended that the underlying transport preserve the write order of messages on the read side.  DNS resolution (optional): Be able to resolve the DNS. 
  38. Demo Features Akka.Remote Akka Configuration(hocon file)
  39. 容錯:群集優雅地從故障(尤其是網絡分區)中恢復。 彈性:簇本身俱有彈性,可根據需要向上/向下擴展。 分散:可以在整個集群中同時運行給定微服務或應用程序狀態的多個相等副本 點對點:新節點可以聯繫現有對等體,獲得有關其他對等體的通知,並在不進行任何配置更改的情況下將自身完全集成到網絡中。 沒有單點故障/瓶頸:多個節點能夠為請求提供服務,從而提高吞吐量和容錯能力。 Fault-tolerant: clusters recover from failures (especially network partitions) elegantly. Elastic: clusters are inherently elastic, and can scale up/down as needed. Decentralized: it's possible to have multiple equal replicas of a given microservice or piece of application state running simultaneously throughout a cluster Peer-to-peer: New nodes can contact existing peers, be notified about other peers, and fully integrate themselves into the network without any configuration changes. No single point of failure/bottleneck: multiple nodes are able to service requests, increasing throughput and fault-tolerance.
  40. 容錯:群集優雅地從故障(尤其是網絡分區)中恢復。 彈性:簇本身俱有彈性,可根據需要向上/向下擴展。 分散:可以在整個集群中同時運行給定微服務或應用程序狀態的多個相等副本 點對點:新節點可以聯繫現有對等體,獲得有關其他對等體的通知,並在不進行任何配置更改的情況下將自身完全集成到網絡中。 沒有單點故障/瓶頸:多個節點能夠為請求提供服務,從而提高吞吐量和容錯能力。 Fault-tolerant: clusters recover from failures (especially network partitions) elegantly. Elastic: clusters are inherently elastic, and can scale up/down as needed. Decentralized: it's possible to have multiple equal replicas of a given microservice or piece of application state running simultaneously throughout a cluster Peer-to-peer: New nodes can contact existing peers, be notified about other peers, and fully integrate themselves into the network without any configuration changes. No single point of failure/bottleneck: multiple nodes are able to service requests, increasing throughput and fault-tolerance.
  41. Demo Features Actor.Cluster combine multiple Actor System Load Actor System and cluster setting from configuration(hocon file) Need Akka.Remote Use HOCON
  42. Demo Features Actor model integrate with ASP.NET Core
  43. Demo Features Client generate game data to Web from Akka.Remote Use Akka.Scheduler to fire game data when target interval ASP.NET Core build multiple Actors ASP.NET Core use IHostedService play as console Use SignalR push data to Client Change Akka.Serializer from Json.NET to Hyperion
  44. Akka: A free and open-source toolkit and runtime simplifying the construction of concurrent and distributed applications on the JVM. Kubernetes: An open-source system for automating deployment, scaling, and management of containers. Docker: Container building,shipping and running platform sbt: The interactive build tool for Scala Scala: A general-purpose programming language providing support for functional programming and a strong static type system.
  45. Disruptor使用1個線程1的消費者模型, 其中Actors使用N:M模型,也就是說,您可以擁有盡可能多的角色,並且他們將分佈在固定數量的線程中(通常每個核心1個)。 BatchHandler接口為onEndOfBatch()提供了額外的(非常重要的)回調。 這允許緩慢的消費者,例如那些進行I / O的用戶將事件一起分批以提高吞吐量。 可以在其他Actor框架中進行批處理,但是由於幾乎所有其他框架在批處理結束時都不提供回調,因此需要使用超時來確定批處理的結束,從而導致延遲較差。
  46. https://petabridge.com/blog/top-7-akkadotnet-stumbling-blocks/ Making message classes mutable Losing sleep over Disassociated messages Sending MASSIVE messages over Akka.Remote Executing long-running actions inside an actor’s Receive method Using ActorSelection instead of IActorRef Over-dependence on Dependency Injection frameworks Confusing the procedural async / awaitmodel with actors
  47. Actors should be like nice co-workers: do their job efficiently without bothering everyone else needlessly and avoid hogging resources. Translated to programming this means to process events and generate responses (or more requests) in an event-driven manner. Actors should not block (i.e. passively wait while occupying a Thread) on some external entity—which might be a lock, a network socket, etc.—unless it is unavoidable; in the latter case see below. Do not pass mutable objects between actors. In order to ensure that, prefer immutable messages. If the encapsulation of actors is broken by exposing their mutable state to the outside, you are back in normal .NET concurrency land with all the drawbacks. Actors are made to be containers for behavior and state, embracing this means to not routinely send behavior within messages. One of the risks is to accidentally share mutable state between actors, and this violation of the actor model unfortunately breaks all the properties which make programming in actors such a nice experience. Top-level actors are the innermost part of your Error Kernel, so create them sparingly and prefer truly hierarchical systems. This has benefits with respect to fault-handling (both considering the granularity of configuration and the performance) and it also reduces the strain on the guardian actor, which is a single point of contention if over-used.
  48. https://rogerjohansson.blog/2016/03/13/random-things-learned-building-akka-net-part-1/