SlideShare a Scribd company logo
1 of 25
Actor Model in .NET - Akka.NET
Konrad Dusza
@voltcode
Actor model in .NET - Akka.NetVoltcode
Agenda
● Actor model - history and definition
● What to expect from an actor framework? Why is it useful?
● Akka.NET showcase with examples
● Akka.NET current state and the future
Actor model in .NET - Akka.NetVoltcode
1973 - Concept formulated by Carl Hewitt et al.:
“A universal modular ACTOR formalism for artificial intelligence”
1986 - Gul Agha, doctoral dissertation
"Actors: A Model of Concurrent Computation in Distributed Systems"
1986 - Joe Armstrong and others in Ericsson - Erlang programming language and
VM. Current version of Erlang/OTP is 19.1 (2016.09)
2009 - initial release of Akka framework (JVM, Scala) by Typesafe (currently
Lightbend)
2014.02 - initial release of Akka.NET - Aaron Stannard, Roger Alsing
Actor model - 40+ year old!
Actor model in .NET - Akka.NetVoltcode
Actors communicate by exchanging messages
asynchronously
Actors have internal state that is invisible from the
outside, no shared mutable state
Actors can decide to change their state upon reception
of a message - behavior specification
Each actor processes immutable messages sequentially
- one message at a time*
Actor model - “concurrent object-oriented programming”
Actor
State
Behavior
Messages
Actor model in .NET - Akka.NetVoltcode
Actor model - “concurrent object-oriented programming”
Actors can create child actors
Actors are identified by addresses
Actors have mailboxes, where messages arrive
By default, messages are processed in the order
in which they arrived
/Anakin
Come to
the dark
side!
/Anakin/Luke /Anakin/Leia
Actor model in .NET - Akka.NetVoltcode
Actor model - benefits
No deadlocks!
No shared state!
No global mutable state!
Fault isolation - “let it crash”!
Encapsulation!
Actor model in .NET - Akka.NetVoltcode
Actor frameworks - features
● “Green” threads
● Supervision tree
● Remote deployment
● Routing
● Clustering
● Distributed Pub-sub
● Conflict-free Replicated Data Types (CRDTs)
● Hot code reloading
Actor model in .NET - Akka.NetVoltcode
Akka.NET - modules
(as of version 1.1.2)
● Akka
● Akka.Remote
● Akka.Cluster
○ Akka.Cluster.Sharding
○ Akka.Cluster.PubSub
○ Akka.Cluster.Singleton
○ Akka.Cluster.DData (in progress)
● Akka.Persistence
● Akka.Streams
● Akka.TestKit
○ MultiNodeTestKit
Voltcode Actor model in .NET - Akka.NetVoltcode
Hello actor
We need an ActorSystem in our application
Create a class and inherit from UntypedActor, ReceiveActor or TypedActor
Add/register message handling to the actor.
Deploy actors using actor system (or indirectly via router)
Tell, don't ask. Ask only if you really must. You may also forward or set
ReceiveTimeout.
Voltcode Actor model in .NET - Akka.NetVoltcode
State machines
Actors can choose to modify their behavior as a result of message
Akka provides several methods that facilitate switching handlers’ registrations:
Become(Action newBehaviorDefinition)
BecomeStacked(Action newBehaviorDefinition)
UnbecomeStacked()
Second option in Akka is a more advanced state machine implementation: FSM
More options at a cost of readability
Stashing provides a mechanism to withhold messages until Actor is able to process them (often used with
Become):
Inherit from IWithUnboundedStash and provide :
IStash Stash { get; set; }
Stash.Stash()
Stash.Prepend(IEnumerable<Envelope> envelopes )
Stash.Unstash()
Stash.UnstashAll() (with conditional overload)
Stash.ClearStash()
Code sample!
SampleLocal
Voltcode Actor model in .NET - Akka.NetVoltcode
Error handling, supervision and monitoring
Be clear about failures, do not hide them under the carpet aka “Let it crash” philosophy.
Exception inside an actor does not propagate automatically to parent. Instead of killing the actor permanently, it causes its
restart.
Actor can die for real in several other ways (PoisonPill, Kill, Stop() GracefulStop(timeToWait)).
Two types of supervision for such cases are available OOTB:
● Parental supervision (implicit)
○ Parent reacts to children failures
● Unrelated actors supervision (explicit watching)
○ Register via Watch
○ Terminated message on death
○ DeathPactException
/parent
/child1
/doctor /patient
Watch
Code sample!
SampleSupervision
Voltcode Actor model in .NET - Akka.NetVoltcode
Routing
A router is a special kind of actor that does not interpret messages, only passes them between
sender and routees.
Router can be instantiated in code and via HOCON configuration
Router can process more than 1 message at once (!)
Built-in routers:
● Broadcast
● Random
● Round-robin
● Consistent hashing
● TailChopping
● ScatterGatherFirstCompleted
● SmallestMailbox
Pools can be resized dynamically using resizer & providing upper and lower bound of number of routees
Code sample!
SampleRouting
Voltcode Actor model in .NET - Akka.NetVoltcode
Remote actors - Akka.Remote
All tools work with remote actors!
● Addressing - addressing scheme supports remote actors,
IActorRefs work the same
● Supervision - you can watch a remote actor!
● Routing - you can routeto remote actors!
● Deployment - you can deploy actors to remote processes!
Remote actor address must be extended with extra information -
hostname, port, remote actor system
Watch on remote actors reacts to graceful stopping and to network
failures (disassociation of remote nodes)
Code sample!
SampleRemote
Voltcode Actor model in .NET - Akka.NetVoltcode
Cluster is
● Mesh network
● Fault-tolerant
● Elastic
● Decentralized
● P2P
● Without a single point of failure
● Without a single point of bottleneck
Clustering
n1
n2
n3
n4
n5
Voltcode Actor model in .NET - Akka.NetVoltcode
Clustering
Aimed towards high availability and partition
tolerance (AP in CAP)
● There are ways to provide more consistency!
Two types of nodes - seed and non-seed
● Seed nodes - well-known starting nodes
● Non seed
Nodes create and maintain the cluster using gossip
protocol (P2P)
● New nodes discovery
● Dead nodes removal
● Detecting changes in nodes availability
Seed Non-s1
Non-s2
Code sample!
SampleCluster
1
2
2
3
Voltcode Actor model in .NET - Akka.NetVoltcode
Clustering - usage
Business requirements:
● Elasticity (unpredictable load)
● Real-time (high perf., latency kills business)
Examples:
● Multiplayer games
● IoT
● Real-time analytics
● Marketing automation
● Complex event processing (CEP)
● Alerting & monitoring
● Recommendation engines
● Dynamic pricing
● Distributed caching
Voltcode Actor model in .NET - Akka.NetVoltcode
Clustering - distributed pub-sub
Special “mediator” actors
Subscribe with:
Publish with:
var mediator = DistributedPubSub.Get(Context.System).Mediator;
mediator.Tell(new Subscribe("topic", Self));
Receive<SubscribeAck>(_ => Become(Subscribed));
var mediator = DistributedPubSub.Get(Context.System).Mediator;
mediator.Tell(new Publish("topic", new MyMessage()));
Alternatively: use Send,
SendToAll or groups within
topics
Subscribe/SubscribeAck is
mirrored by
Unsubscribe/UnsubscribeAck.
Alternatively : use Put/Remove
API to register using actor path
instead of topic name
Voltcode Actor model in .NET - Akka.NetVoltcode
Clustering - additional tools
Sharding
(requires Akka.Persistence)
Singleton
Cluster.Client
Distributed Data (CRDTs)
Voltcode Actor model in .NET - Akka.NetVoltcode
Testing
Akka utilities for testing:
TestKit - basic actor messaging testing.
MultiNodeTestKit - extension of the above to create multi-node tests
Plugins for popular unit test frameworks are available (XUnit, NUnit, VSUnit, etc.)
Code sample!
SampleTest
Voltcode Actor model in .NET - Akka.NetVoltcode
Akka.Persistence
Enable state persistence for stateful actors
● By default - persist changes to state in an incremental way, without mutations - ES
● Optional - persist state snapshots
Actor state recovery is done using:
● Message replay
● Snapshots restore
Storage backend is pluggable (MySql, PostgreSQL, MS SQL, MongoDB, … ), in-memory option is also available.
Additional features:
● At-least-once delivery using AtLeastOnceDelivery mixin for PersistentActor
● Event adapters - schema versioning support (“upcasting”), domain and data model separation
Voltcode Actor model in .NET - Akka.NetVoltcode
Akka.Streams
Manipulate data streams in a reactive fashion with back-pressure support
(slowing down producers to avoid OOMs). Akka.Streams doesn’t use actors explicitly , but uses Akka internals
One way to look at it is an ETL framework for asynchronous data processing with strategies to cope with overload.
At the moment it does not automatically distribute stream processing through network-connected nodes, however such
composition can be achieved with manual effort. Gearpump (JVM) is an example of a framework built on top of Akka for real-time
big data engine.
Core Concepts (from Akka.NET docs):
● Stream - An active process that involves moving and transforming data
● Materializer - makes stream run
● Graph - A description of a stream processing topology, defining the pathways through which elements shall flow when the
stream is running.
● Processing Stage - The common name for all building blocks that build up a Graph
○ Source - producer with 1 output, emits data elements whenever downstream is ready to receive
○ Sink - consumer with 1 input, requests and accepts data, may slow down upstream producers
○ Flow - processor with 1 output, 1 input, connects up- and downstream by transforming elements flowing through it
○ RunnableGraph - A Flow that has both ends "attached" to a Source and Sink respectively, and is ready to be run().
Code sample!
SampleStream
Actor model in .NET - Akka.NetVoltcode
Akka.NET - performance, scalability
Local perf
2m+ msg/sec per core (95m / 48 core) - Opteron 2.3 GHz in 2015 Akka.NET
using ping pong test
4.5m+ msg/sec per core in ReceiveActorThroughputSpec test (recent
Akka.NET on build machine)
Remote perf
~50k msg/sec per single connection (with Akka 1.1)
Mostly driven by underlying TCP transport (Helios), to be rewritten for Akka 1.5
(100k+/sec).
Largest .NET cluster in prod - “hundreds” of nodes (in JVM ~2600 nodes)
Actor model in .NET - Akka.NetVoltcode
Akka.NET - future
Move libraries out of beta:
Akka.Cluster.Tools
Akka.Persistence
Akka.Streams
New libraries:
Distributed Data
.NET Core support (1.5)
Wire as the default serializer (1.5)
TLS networking
Actor model in .NET - Akka.NetVoltcode
Resources
Code samples available under:
https://github.com/voltcode/AkkaNetSamples
Find out more about Akka.NET and the Actor Model:
http://getakka.net
https://github.com/akkadotnet/akka.net/
https://gitter.im/akkadotnet/akka.net
https://petabridge.com/bootcamp/
http://petabridge.com/blog
http://bartoszsypytkowski.com/
Many resources available for Akka (Lightbend documentation)
actor model, clusters in general (Erlang, Riak - basho)
Book(Scala) : Reactive Messaging Patterns with the Actor Model
Actor model in .NET - Akka.NetVoltcode
Questions?
Feel free to contact me under @voltcode

More Related Content

What's hot

A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelMykhailo Kotsur
 
Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015Anthony Brown
 
Full-Stack, Message-oriented Programming w/ Akka.NET Actors
Full-Stack, Message-oriented Programming w/ Akka.NET ActorsFull-Stack, Message-oriented Programming w/ Akka.NET Actors
Full-Stack, Message-oriented Programming w/ Akka.NET Actorspetabridge
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachEmre Akış
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyDror Bereznitsky
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8Johan Andrén
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to AkkaKnoldus Inc.
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETDavid Hoerster
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
Akka Cluster in Production
Akka Cluster in ProductionAkka Cluster in Production
Akka Cluster in Productionbilyushonak
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster OpenCredo
 
Actor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupActor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupApcera
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelMassimo Bonanni
 
Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?David Hoerster
 
CQRS + ES with Scala and Akka
CQRS + ES with Scala and AkkaCQRS + ES with Scala and Akka
CQRS + ES with Scala and AkkaBharadwaj N
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Creating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnetCreating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnetDavid Hoerster
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsNLJUG
 

What's hot (20)

A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor model
 
Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015
 
Full-Stack, Message-oriented Programming w/ Akka.NET Actors
Full-Stack, Message-oriented Programming w/ Akka.NET ActorsFull-Stack, Message-oriented Programming w/ Akka.NET Actors
Full-Stack, Message-oriented Programming w/ Akka.NET Actors
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency Approach
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better Concurrency
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8
 
Akka framework
Akka frameworkAkka framework
Akka framework
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to Akka
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NET
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Akka Cluster in Production
Akka Cluster in ProductionAkka Cluster in Production
Akka Cluster in Production
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster
 
Actor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupActor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder Meetup
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
 
Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?
 
CQRS + ES with Scala and Akka
CQRS + ES with Scala and AkkaCQRS + ES with Scala and Akka
CQRS + ES with Scala and Akka
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Creating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnetCreating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnet
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based Applications
 
Akka - A Brief Intro
Akka - A Brief IntroAkka - A Brief Intro
Akka - A Brief Intro
 

Similar to Actor model in .NET - Akka.NET

Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustEvan Chan
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETpetabridge
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache sparkRahul Kumar
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den HoekRubiX BV
 
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
Strata Singapore: GearpumpReal time DAG-Processing with Akka at ScaleStrata Singapore: GearpumpReal time DAG-Processing with Akka at Scale
Strata Singapore: Gearpump Real time DAG-Processing with Akka at ScaleSean Zhong
 
Event Sourcing and beyond with Akka.NET Persistence
Event Sourcing and beyond with Akka.NET PersistenceEvent Sourcing and beyond with Akka.NET Persistence
Event Sourcing and beyond with Akka.NET PersistenceKonrad Dusza
 
Actor-based concurrency in a modern Java Enterprise
Actor-based concurrency in a modern Java EnterpriseActor-based concurrency in a modern Java Enterprise
Actor-based concurrency in a modern Java EnterpriseAlexander Lukyanchikov
 
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...StreamNative
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
Introduction to Apache Apex and writing a big data streaming application
Introduction to Apache Apex and writing a big data streaming application  Introduction to Apache Apex and writing a big data streaming application
Introduction to Apache Apex and writing a big data streaming application Apache Apex
 
Akka-intro-training-public.pdf
Akka-intro-training-public.pdfAkka-intro-training-public.pdf
Akka-intro-training-public.pdfBernardDeffarges
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Raymond Roestenburg
 
Scorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain FrameworkScorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain FrameworkAlex Chepurnoy
 
Big data Argentina meetup 2020-09: Intro to presto on docker
Big data Argentina meetup 2020-09: Intro to presto on dockerBig data Argentina meetup 2020-09: Intro to presto on docker
Big data Argentina meetup 2020-09: Intro to presto on dockerFederico Palladoro
 
Intro to Apache Apex @ Women in Big Data
Intro to Apache Apex @ Women in Big DataIntro to Apache Apex @ Women in Big Data
Intro to Apache Apex @ Women in Big DataApache Apex
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developersTaras Fedorov
 
Gatling - Stress test tool
Gatling - Stress test toolGatling - Stress test tool
Gatling - Stress test toolKnoldus Inc.
 
Developing Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaDeveloping Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaJoe Stein
 

Similar to Actor model in .NET - Akka.NET (20)

Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to Rust
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache spark
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
 
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
Strata Singapore: GearpumpReal time DAG-Processing with Akka at ScaleStrata Singapore: GearpumpReal time DAG-Processing with Akka at Scale
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
 
Event Sourcing and beyond with Akka.NET Persistence
Event Sourcing and beyond with Akka.NET PersistenceEvent Sourcing and beyond with Akka.NET Persistence
Event Sourcing and beyond with Akka.NET Persistence
 
Actor-based concurrency in a modern Java Enterprise
Actor-based concurrency in a modern Java EnterpriseActor-based concurrency in a modern Java Enterprise
Actor-based concurrency in a modern Java Enterprise
 
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...Deploying Machine Learning Models with Pulsar Functions  - Pulsar Summit Asia...
Deploying Machine Learning Models with Pulsar Functions - Pulsar Summit Asia...
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Reactors.io
Reactors.ioReactors.io
Reactors.io
 
Introduction to Apache Apex and writing a big data streaming application
Introduction to Apache Apex and writing a big data streaming application  Introduction to Apache Apex and writing a big data streaming application
Introduction to Apache Apex and writing a big data streaming application
 
Akka-intro-training-public.pdf
Akka-intro-training-public.pdfAkka-intro-training-public.pdf
Akka-intro-training-public.pdf
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
 
Scorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain FrameworkScorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain Framework
 
Big data Argentina meetup 2020-09: Intro to presto on docker
Big data Argentina meetup 2020-09: Intro to presto on dockerBig data Argentina meetup 2020-09: Intro to presto on docker
Big data Argentina meetup 2020-09: Intro to presto on docker
 
Intro to Apache Apex @ Women in Big Data
Intro to Apache Apex @ Women in Big DataIntro to Apache Apex @ Women in Big Data
Intro to Apache Apex @ Women in Big Data
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developers
 
Gatling - Stress test tool
Gatling - Stress test toolGatling - Stress test tool
Gatling - Stress test tool
 
Developing Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaDeveloping Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache Kafka
 

Recently uploaded

Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 

Recently uploaded (20)

Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 

Actor model in .NET - Akka.NET

  • 1. Actor Model in .NET - Akka.NET Konrad Dusza @voltcode
  • 2. Actor model in .NET - Akka.NetVoltcode Agenda ● Actor model - history and definition ● What to expect from an actor framework? Why is it useful? ● Akka.NET showcase with examples ● Akka.NET current state and the future
  • 3. Actor model in .NET - Akka.NetVoltcode 1973 - Concept formulated by Carl Hewitt et al.: “A universal modular ACTOR formalism for artificial intelligence” 1986 - Gul Agha, doctoral dissertation "Actors: A Model of Concurrent Computation in Distributed Systems" 1986 - Joe Armstrong and others in Ericsson - Erlang programming language and VM. Current version of Erlang/OTP is 19.1 (2016.09) 2009 - initial release of Akka framework (JVM, Scala) by Typesafe (currently Lightbend) 2014.02 - initial release of Akka.NET - Aaron Stannard, Roger Alsing Actor model - 40+ year old!
  • 4. Actor model in .NET - Akka.NetVoltcode Actors communicate by exchanging messages asynchronously Actors have internal state that is invisible from the outside, no shared mutable state Actors can decide to change their state upon reception of a message - behavior specification Each actor processes immutable messages sequentially - one message at a time* Actor model - “concurrent object-oriented programming” Actor State Behavior Messages
  • 5. Actor model in .NET - Akka.NetVoltcode Actor model - “concurrent object-oriented programming” Actors can create child actors Actors are identified by addresses Actors have mailboxes, where messages arrive By default, messages are processed in the order in which they arrived /Anakin Come to the dark side! /Anakin/Luke /Anakin/Leia
  • 6. Actor model in .NET - Akka.NetVoltcode Actor model - benefits No deadlocks! No shared state! No global mutable state! Fault isolation - “let it crash”! Encapsulation!
  • 7. Actor model in .NET - Akka.NetVoltcode Actor frameworks - features ● “Green” threads ● Supervision tree ● Remote deployment ● Routing ● Clustering ● Distributed Pub-sub ● Conflict-free Replicated Data Types (CRDTs) ● Hot code reloading
  • 8. Actor model in .NET - Akka.NetVoltcode Akka.NET - modules (as of version 1.1.2) ● Akka ● Akka.Remote ● Akka.Cluster ○ Akka.Cluster.Sharding ○ Akka.Cluster.PubSub ○ Akka.Cluster.Singleton ○ Akka.Cluster.DData (in progress) ● Akka.Persistence ● Akka.Streams ● Akka.TestKit ○ MultiNodeTestKit
  • 9. Voltcode Actor model in .NET - Akka.NetVoltcode Hello actor We need an ActorSystem in our application Create a class and inherit from UntypedActor, ReceiveActor or TypedActor Add/register message handling to the actor. Deploy actors using actor system (or indirectly via router) Tell, don't ask. Ask only if you really must. You may also forward or set ReceiveTimeout.
  • 10. Voltcode Actor model in .NET - Akka.NetVoltcode State machines Actors can choose to modify their behavior as a result of message Akka provides several methods that facilitate switching handlers’ registrations: Become(Action newBehaviorDefinition) BecomeStacked(Action newBehaviorDefinition) UnbecomeStacked() Second option in Akka is a more advanced state machine implementation: FSM More options at a cost of readability Stashing provides a mechanism to withhold messages until Actor is able to process them (often used with Become): Inherit from IWithUnboundedStash and provide : IStash Stash { get; set; } Stash.Stash() Stash.Prepend(IEnumerable<Envelope> envelopes ) Stash.Unstash() Stash.UnstashAll() (with conditional overload) Stash.ClearStash() Code sample! SampleLocal
  • 11. Voltcode Actor model in .NET - Akka.NetVoltcode Error handling, supervision and monitoring Be clear about failures, do not hide them under the carpet aka “Let it crash” philosophy. Exception inside an actor does not propagate automatically to parent. Instead of killing the actor permanently, it causes its restart. Actor can die for real in several other ways (PoisonPill, Kill, Stop() GracefulStop(timeToWait)). Two types of supervision for such cases are available OOTB: ● Parental supervision (implicit) ○ Parent reacts to children failures ● Unrelated actors supervision (explicit watching) ○ Register via Watch ○ Terminated message on death ○ DeathPactException /parent /child1 /doctor /patient Watch Code sample! SampleSupervision
  • 12. Voltcode Actor model in .NET - Akka.NetVoltcode Routing A router is a special kind of actor that does not interpret messages, only passes them between sender and routees. Router can be instantiated in code and via HOCON configuration Router can process more than 1 message at once (!) Built-in routers: ● Broadcast ● Random ● Round-robin ● Consistent hashing ● TailChopping ● ScatterGatherFirstCompleted ● SmallestMailbox Pools can be resized dynamically using resizer & providing upper and lower bound of number of routees Code sample! SampleRouting
  • 13. Voltcode Actor model in .NET - Akka.NetVoltcode Remote actors - Akka.Remote All tools work with remote actors! ● Addressing - addressing scheme supports remote actors, IActorRefs work the same ● Supervision - you can watch a remote actor! ● Routing - you can routeto remote actors! ● Deployment - you can deploy actors to remote processes! Remote actor address must be extended with extra information - hostname, port, remote actor system Watch on remote actors reacts to graceful stopping and to network failures (disassociation of remote nodes) Code sample! SampleRemote
  • 14. Voltcode Actor model in .NET - Akka.NetVoltcode Cluster is ● Mesh network ● Fault-tolerant ● Elastic ● Decentralized ● P2P ● Without a single point of failure ● Without a single point of bottleneck Clustering n1 n2 n3 n4 n5
  • 15. Voltcode Actor model in .NET - Akka.NetVoltcode Clustering Aimed towards high availability and partition tolerance (AP in CAP) ● There are ways to provide more consistency! Two types of nodes - seed and non-seed ● Seed nodes - well-known starting nodes ● Non seed Nodes create and maintain the cluster using gossip protocol (P2P) ● New nodes discovery ● Dead nodes removal ● Detecting changes in nodes availability Seed Non-s1 Non-s2 Code sample! SampleCluster 1 2 2 3
  • 16. Voltcode Actor model in .NET - Akka.NetVoltcode Clustering - usage Business requirements: ● Elasticity (unpredictable load) ● Real-time (high perf., latency kills business) Examples: ● Multiplayer games ● IoT ● Real-time analytics ● Marketing automation ● Complex event processing (CEP) ● Alerting & monitoring ● Recommendation engines ● Dynamic pricing ● Distributed caching
  • 17. Voltcode Actor model in .NET - Akka.NetVoltcode Clustering - distributed pub-sub Special “mediator” actors Subscribe with: Publish with: var mediator = DistributedPubSub.Get(Context.System).Mediator; mediator.Tell(new Subscribe("topic", Self)); Receive<SubscribeAck>(_ => Become(Subscribed)); var mediator = DistributedPubSub.Get(Context.System).Mediator; mediator.Tell(new Publish("topic", new MyMessage())); Alternatively: use Send, SendToAll or groups within topics Subscribe/SubscribeAck is mirrored by Unsubscribe/UnsubscribeAck. Alternatively : use Put/Remove API to register using actor path instead of topic name
  • 18. Voltcode Actor model in .NET - Akka.NetVoltcode Clustering - additional tools Sharding (requires Akka.Persistence) Singleton Cluster.Client Distributed Data (CRDTs)
  • 19. Voltcode Actor model in .NET - Akka.NetVoltcode Testing Akka utilities for testing: TestKit - basic actor messaging testing. MultiNodeTestKit - extension of the above to create multi-node tests Plugins for popular unit test frameworks are available (XUnit, NUnit, VSUnit, etc.) Code sample! SampleTest
  • 20. Voltcode Actor model in .NET - Akka.NetVoltcode Akka.Persistence Enable state persistence for stateful actors ● By default - persist changes to state in an incremental way, without mutations - ES ● Optional - persist state snapshots Actor state recovery is done using: ● Message replay ● Snapshots restore Storage backend is pluggable (MySql, PostgreSQL, MS SQL, MongoDB, … ), in-memory option is also available. Additional features: ● At-least-once delivery using AtLeastOnceDelivery mixin for PersistentActor ● Event adapters - schema versioning support (“upcasting”), domain and data model separation
  • 21. Voltcode Actor model in .NET - Akka.NetVoltcode Akka.Streams Manipulate data streams in a reactive fashion with back-pressure support (slowing down producers to avoid OOMs). Akka.Streams doesn’t use actors explicitly , but uses Akka internals One way to look at it is an ETL framework for asynchronous data processing with strategies to cope with overload. At the moment it does not automatically distribute stream processing through network-connected nodes, however such composition can be achieved with manual effort. Gearpump (JVM) is an example of a framework built on top of Akka for real-time big data engine. Core Concepts (from Akka.NET docs): ● Stream - An active process that involves moving and transforming data ● Materializer - makes stream run ● Graph - A description of a stream processing topology, defining the pathways through which elements shall flow when the stream is running. ● Processing Stage - The common name for all building blocks that build up a Graph ○ Source - producer with 1 output, emits data elements whenever downstream is ready to receive ○ Sink - consumer with 1 input, requests and accepts data, may slow down upstream producers ○ Flow - processor with 1 output, 1 input, connects up- and downstream by transforming elements flowing through it ○ RunnableGraph - A Flow that has both ends "attached" to a Source and Sink respectively, and is ready to be run(). Code sample! SampleStream
  • 22. Actor model in .NET - Akka.NetVoltcode Akka.NET - performance, scalability Local perf 2m+ msg/sec per core (95m / 48 core) - Opteron 2.3 GHz in 2015 Akka.NET using ping pong test 4.5m+ msg/sec per core in ReceiveActorThroughputSpec test (recent Akka.NET on build machine) Remote perf ~50k msg/sec per single connection (with Akka 1.1) Mostly driven by underlying TCP transport (Helios), to be rewritten for Akka 1.5 (100k+/sec). Largest .NET cluster in prod - “hundreds” of nodes (in JVM ~2600 nodes)
  • 23. Actor model in .NET - Akka.NetVoltcode Akka.NET - future Move libraries out of beta: Akka.Cluster.Tools Akka.Persistence Akka.Streams New libraries: Distributed Data .NET Core support (1.5) Wire as the default serializer (1.5) TLS networking
  • 24. Actor model in .NET - Akka.NetVoltcode Resources Code samples available under: https://github.com/voltcode/AkkaNetSamples Find out more about Akka.NET and the Actor Model: http://getakka.net https://github.com/akkadotnet/akka.net/ https://gitter.im/akkadotnet/akka.net https://petabridge.com/bootcamp/ http://petabridge.com/blog http://bartoszsypytkowski.com/ Many resources available for Akka (Lightbend documentation) actor model, clusters in general (Erlang, Riak - basho) Book(Scala) : Reactive Messaging Patterns with the Actor Model
  • 25. Actor model in .NET - Akka.NetVoltcode Questions? Feel free to contact me under @voltcode