Upload
apcera
View
708
Download
0
Embed Size (px)
Citation preview
Actor Pattern and NATSCharlie Strawn and Steven Osborne
Basic Outline
● Introduction to Actor Model● Similarities to decoupled pub-sub● Simple NATS-Akka connector● NATS Actor implementation
Actor Model
Actor Model
The actor model is comprised of a system of actors. An actor is a primitive that embodies
1. Processing2. Storage3. Communication
In an actor system everything is an actor. Actor people love the “one ant is no ant” analogy: One actor is no actor - they come in systems.
Actor Model
When an actor receives a message it can
1. Send messages to other actors2. Create new actors3. Designate the behavior to be used for the next message it receives
This is the real key. The actor is always doing work reacting to some message.
Actor Model - Key points
● Actors can live anywhere. ● There is no shared state among actors. Let it crash.● Each actor has an address at which it receives messages. ● There is a many-to-many relationship between actors and addresses.● Messages are delivered at most once.● Actors process messages serially.
Actor Model - Key points
● The model is inherently concurrent (yey!) so keep computation lightweight and consistent
● Throughput is king● Each actor processes messages serially - so avoid blocking (except for
unavoidable ops like I/O)● The unit of concurrency is actor - so all computation within the actor is serial.
If the actor has too much work and needs more processing power it creates and messages other actors.
Good synopsis...
If we’ve piqued your interest in actors but find our summary lacking content - check out this video from Carl Hewitt - the original designer of the Actor Model.
https://www.youtube.com/watch?v=7erJ1DV_Tlo
Or just do the sane thing and search youtube for “the actor model”. It’s the first one.
Akka
● Akka is Java/Scala library that implements the actor model. Akka is especially well suited to an EventBus style implementation of pub sub. http://doc.akka.io/docs/akka/current/scala/event-bus.html
● 1-to-1 Message to Event● Effective Akka
Ok, great, isn’t this a NATS talk?
NATS is clearly not an actor model - it’s a communication protocol. That being said, it upholds many of the basic tenants embraced by the actor model.
● Decoupled sender/receiver (i.e. publisher-subscriber)● Publishers and subscribers can live anywhere● Messages are delivered at most once● Lightweight and high throughput
NATS-Akka
Let’s take the low hanging fruit here - we should be able to connect NATS to an existing actor model implementation. Better yet, let’s take the lowest of the fruit - NATS connector framework (in Java) to Akka (also Java).
Lets combine the speed and simplicity of NATS with the speed and simplicity of Akka.
NATS-Akka-Connector
Demo!
Akka Clustering
● Akka has a built-in clustering module - but it’s based on complicated on somewhat complicated tcp routing configuration.
● With NATS as the communication point between nodes - clustering akka is simple.
Connecting to an actor system is cool, but...
What if the actor system was built on top of NATS?
Then multi-node would be a cinch. Setup would be quick. Message latency would be low. Actor Systems could span languages (i.e. have java actors that interacts with legacy apis, go actors to do some heavy lifting, and some rust actors to just be awesome).
Let’s try it out
Demo!
https://github.com/sosborne/nats-actor/tree/actor
More work
● Actually implement akka clustering using NATS as the message transport across cluster nodes
● Multi-node go nats-actor implementation● More languages for nats-actor (maybe rust? Shameless plug…)
Thanks!
Some good resources
http://doc.akka.io/docs/akka/current/scala/event-bus.html
https://github.com/vrcod/akka-sample-twitter-streaming
http://akka.io/
http://www.brianstorti.com/the-actor-model/