View
1.704
Download
3
Category
Preview:
Citation preview
Reactive Applications with akka.Net
Anthony Brown
@bruinbrown93
me@anthonyjbrown.co.uk
HI, I’m Anthony
Software engineer at Adbrain
me@anthonyjbrown.co.uk
@bruinbrown93
Computers have changed… A lot
Some of the changes
Faster processors More processor cores
More RAM Faster networks with more bandwidth
We need to make sure applications are responsive to user actions
Moore’s Law
Scale up no longer possible
What’s the options?
CPUs have more cores Networks are faster
Scale out is now possible
Scale out relies on doing lots of work simultaneously
To do work simultaneously, we need either parallelism or concurrency
Parallelism is easy for Embarrassingly parallel tasks
For more complex tasks, we need concurrency
Is there a difference?
Concurrency
Parallelism
Thread 1
Thread 2
Thread 1
Thread 2
Concurrency is hard
MULTITHREADING
THEORYPRACTICE
CHECK OUTMY MULTITHREADED CODE
HOW MANY THREADSDOES IT TAKE TO CHANGE A LIGHTBULB?
We don’t want to write multithreaded code
Use concurrency abstractions instead
You’ve probably used one Tasks
There’s another - actors
Why are tasks bad?
They’re not, they solve a different problem
Promote isolation over co-ordination
Actors are independent entities
Why does this matter?
We said we need applications to be responsive
What does it mean for an application to be responsive?
For an application to be responsive, it needs to work no matter what
the scenario
Heavy load
Service failure
If we want to manage these, we need loose coupling
Common language for these applications
Reactive reactivemanifesto.org
RESPONSIVE
RESILIENT ELASTIC
MESSAGE PASSING
Reactive applications React to their environment
using actors to write reactive applications
an actor is
A mailbox behaviour state
We saw that actors are strongly isolated, they encapsulate their
state
To modify the state, we have a behaviour which is responsible for
it
We invoke the behaviour by sending it a message
Messages are processed serially but on separate threads
An actor can
send a finite number of messages
An actor can
spawn a finite number of actors
An actor can
change how it responds to the next message
How can we write actors?
Using akka.Net
Step 1 Define an actor
class GreetingActor : ReceiveActor { public GreetingActor() { Receive<string>( s => Console.WriteLine(“Hello ” + s)); } }
Step 2 Create an actor system
var system = ActorSystem.Create(“GreeterSystem”);
Step 3 Spawn the actor
var greeterActor = system.ActorOf<GreeterActor>();
where is my actual actor?
AKKA.net
root actor
your
actors
Step 4 Talk to the actor
greeter.Tell(“DDDEA”);
What about F#?
Full F# API
Built upon Erlang foundations
let Actor count = actor { let! msg = mailbox.Receive () printfn “Message %i: %A” count msg return! actor (count+1) }
Resilience in distributed
systems
Cloud brings about failure
your users don’t want to see THIS
Need to isolate failures quickly and automatically recover from
them
How can we isolate errors?
Separate error channels
Service aService B
supervisor
Request
Response
user error
error action
Handling increased load in a
distributed system
Easiest way to scale is to make the servers bigger
Scale up has a limit, scale out doesn't
Scale out is easy with isolation
Actors give us isolation therefore scalability is easy with actors
Routers
Taking akka.Net to the next
level
Akka.Remote
Connecting 2 actor systems in a client-server architecture
Akka.Cluster
Takes remoting to the next level
Treat multiple machines as one actor system
Cluster aware routers
Cluster sharding
Akka.Persistence
Allows for easy CQRS and Event sourcing with actors
Akka.DistributedData
Allows for sharing data between actors with strong eventual
consistency
Where can I use akka.Net?
IoT applications
Job scheduling / cluster management
Gaming
User interfaces
Microservices deployments
akka.Net provides a solid foundation for the stronger constraints being
imposed today and in the future
Want to learn more?
akka.Net bootcamp github.com/petabridge/akka-bootcamp
Reactive applications with akka.Net MEAP soon
StackOverflow stackoverflow.com/tags/akka.net
Want to contribute?
Plenty of up for grabs issues github.com/akkadotnet/akka.net
gitter.im/akkadotnet/akka.net
Q & A
Recommended