einführung in das actor model mit akka.net
TRANSCRIPT
![Page 1: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/1.jpg)
Einführung in das Actor Model mit .net
akka.net
![Page 2: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/2.jpg)
Über mich
Software Engineer, Principal @ Progress Software [email protected] @eigeneachse Sprecher auf Konferenzen und User Groups Freier Autor für donetpro
Ralph Waldenmaier
![Page 3: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/3.jpg)
Ziel
Enwticklung von Anwendungen Skalierbar Fehlertolerant Selbst heilend Verteilt
Was ist das Actor Model Was ist akka.net
![Page 4: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/4.jpg)
Actor Model – Die Theorie
Quelle: https://de.wikipedia.org/wiki/Actor_Model
Wikipedia (https://de.wikipedia.org/wiki/Actor_Model):
„Das Actor Model (deutsch Aktorenmodell) ist in der Informatik ein Modell für nebenläufige Rechnungen bzw. Programme. Diese werden in nebenläufige Einheiten, sog. Aktoren, unterteilt, die ausschließlich über Nachrichtenaustausch kommunizieren.“
1973 Carl Hewitt, Peter Bishop und Richard Steiger Implementierungen
Erlang Scala C#
![Page 5: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/5.jpg)
Actor Model – Die Theorie #2
Quelle: https://de.wikipedia.org/wiki/Actor_Model
“An island of sanity in a sea of concurrency”“Shared nothing”“Black box”“Location transparent”“Distributable by design”
Drei Grundsätze Send: Nachrichten an sich selbst oder andere Aktoren verschicken Create: Neue Aktoren erzeugen Behavior: Das eigene Verhalten ändern
![Page 6: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/6.jpg)
Wer nutzt das?
WhatsApp (Erlang) RabbitMQ (Erlang) CouchDB (Erlang) LinkedIn.com (JVM Akka) Walmart.com (JVM Akka) Bank of America Merrill Lynch (Akka.net) Halo ( Project Orleans )
![Page 7: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/7.jpg)
Wofür verwende ich das?
Alternative zu Threading Message routing State machines CQRS / Event Driven Design IoT Singleton
![Page 8: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/8.jpg)
.net Entwicklung heute
ServiceBLL
DAOTelerik Data Access
DB
DAO2RestHandler
WebApi
![Page 9: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/9.jpg)
ServiceBLL
DAOTelerik Data
Access
DB
DAO2RestHandler
WebApi
ServiceBLL
DAOTelerik Data
Access
DB
DAO2RestHandler
WebApi
CPU 2
MSMQ
Server 1 Server 2
Skalierung
Parallel LINQ TPL – async/await Threads
WCF WebAPI MSMQ / RabbitMQ / Azure Queues
Elastic?
![Page 10: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/10.jpg)
ActorXActorYActorZCPU 2
Server 1 Server 2
Skalierung mit akka.net
Elastic!
Akka.Actor
Akka.Remote
Akka.Cluster
ActorXActorYActorZ
![Page 11: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/11.jpg)
Akka.net
Initial Entwickelt von Roger Johansson und Aaron Stannard OpenSource ( Apache 2 License ) Orientiert sich an den Features der JVM Akka Implementierung ~ 5 core Entwickler ~ 70 github contributor Akka.net Version 1.0 – Q1/2015
Aktuell 1.04 C# und F# API .net und Mono ~ 50 mio msg/sec auf einer Maschine ~ 2,5 millionen actors / GB RAM Reactive Manifesto ( Responsive, Resilient, Elastic, Message Driven )
akka.net
![Page 12: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/12.jpg)
Wie funktioniert ein Actor?
Quelle: http://getakka.net/docs/concepts/actors
![Page 13: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/13.jpg)
Actor Lifecycle
Actor initialize
s
Starting
Actor is up and
now able to
process message
s
Receiving
Actor cleans up
Stopping
Actor is dead
Terminated
Actor is going to restart
Restarting
PreStart()
PostRestart()
PreRestart()PostStop()
PostStop()
![Page 14: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/14.jpg)
DispatcherTh
read
Poo
l
Actor1
Actor1
Actor2
Actor2 Actor3
Actor4 Actor4
Actor1
Actor3 Actor4
Actor2
Actor1
Actor3
Actor2
Time
ThreadPoolDispatcher ( default, max concurrency ) TaskDispatcher ( TPL ) CurrentSynchronizationContextDispatcher ( UI sync ) …
![Page 15: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/15.jpg)
Demo Akka.Actor
Hello World Actor System ReceiveActor ActorRef
Server 1
ActorXActorYActorZ
![Page 16: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/16.jpg)
Demo Akka.Remote #1
Chat app ActorSelection RemoteActorRefProvider Akka.Remote
ActorXActorYActorZ
ActorXActorYActorZ
![Page 17: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/17.jpg)
Demo Akka.Remote #2
Remote deployment Remote daemon
Akka.Remote
ActorXActorYActorZ
ActorXActorYActorZActorA*
![Page 18: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/18.jpg)
Router
Leitet Nachrichten an „routee“ Actors weiter Group vs. Pool Router
RoundRobinRouter ScatterGatherFirstCompletedRouter
BroadcastRouter ConsistentHashingRouter SmallestMailboxRouter Elastische pools
![Page 19: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/19.jpg)
Router konfiguration
akka.actor.deployment { /some-pool { router = round-robin-pool nr-of-instances = 5 }}
// Hocon configvar router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance),
"some-pool");
// Code configvar router = system.ActorOf(Props.Create<Worker>().WithRouter(
new RoundRobinPool(5)), "some-pool");
![Page 20: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/20.jpg)
RoundRobinRouter
12
1
2
3
34
4
Router
Routee1
Routee2
Routee3
Eingang Ausgang
![Page 21: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/21.jpg)
ScatterGatherFirstCompleted
1
2
3
Router
Routee1
Routee2
Routee3
Eingang Ausgang
Sender?
!
![Page 22: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/22.jpg)
Elastische pools
akka.actor.deployment {
/my-router {
router = round-robin-pool resizer
{ enabled = on lower-bound = 1 upper-bound = 10 messages-per-resize = 10ramp-up-rate = 0.2pressure-threshold = 1backoff-threshold = 0.3…
} }
}
![Page 23: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/23.jpg)
Demo Akka.Routing
RoundRobin Deployment configuration
![Page 24: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/24.jpg)
Supervision
Jeder Actor wird durch einen anderen Actor überwacht, welcher entscheidet, wie im Fehlerfall zu reagieren ist.
Restart Teminate Ignore and Resume Escalate an eigenen Supervisor Selbstheilung
![Page 25: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/25.jpg)
ErrorHandling – OneForOne
Quelle: http://getakka.net/docs/concepts/supervision
![Page 26: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/26.jpg)
ErrorHandling – AllForOne
Quelle: http://getakka.net/docs/concepts/supervision
![Page 27: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/27.jpg)
Error handling
protected override SupervisorStrategy SupervisorStrategy(){
return new OneForOneStrategy( // oder AllForOneStrategymaxNumberOfRetries: 10,duration: TimeSpan.FromSeconds(30),decider: x =>{
if (x is ArithmeticException) return Directive.Resume;else if (x is NotSupportedException) return Directive.Stop; else if (x is ArgumentOutOfRangeException) return Directive.Escalate; else return Directive.Restart;
});}
![Page 28: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/28.jpg)
Switchable Behavior
private void Lebendig(){ …//other code if (this.lebenspunkte <= 0) this.Become(Tot); …}private void Tot(){ Receive<Wiederbeleben>(() => { this.lebenspunkte = this.maxLebenspunkte;
this.Become(Lebendig); }); }
![Page 29: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/29.jpg)
Weitere Features
Cluster Cluster Sharding Dependency Injection – Autofac Persistence Finite State Machines F# API
![Page 30: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/30.jpg)
Wie gehts weiter?
http://getakka.net/ https://github.com/akkadotnet/akka.net/tree/dev/src/examples https://gitter.im/akkadotnet/akka.net
https://petabridge.com/bootcamp/ (kostenlos) https://petabridge.com/
![Page 31: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/31.jpg)
Q & A
![Page 32: Einführung in das Actor Model mit Akka.net](https://reader031.vdocuments.mx/reader031/viewer/2022021422/587080da1a28ab57368b6595/html5/thumbnails/32.jpg)
http://www.dotnet-developer-conference.de/ 30. November bis 02. Dezember 2015 Pullman Hotel Köln Frühbucher
Bis 16. Oktober