Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
& the actor model
What is Akka?
A toolkit that provides:
simple concurrency
resiliency
elasticity
high performance
What is an actor?
Receive and send messages
Define behavior for
next message
Create other actors
The Actor model of computation
processing - behavior
storage - state model
I/O - messages
Key things to understand
messages processed sequentially
multiple actors can be working at the same time
actors are not th...
A very simple actor
class MyActor extends Actor with ActorLogging {
def receive = {
case msg ⇒
log.info(“Received: {}”, ms...
Creating actors in an actor system
Everything begins here:
val system = ActorSystem("example")
val myActor = system.actorO...
Messages
Can be any object
Should be immutable
Should be serializable
Ideally define a protocol for communication
Protocol
“a system of rules that explain the
correct conduct and procedures to
be followed in formal situations”
— Merriam...
Message protocols
Define the interaction between actors
Specify clear boundaries
Encode success and failure clearly
Message protocols
trait Response
case class Success(res: Array[Byte]) extends Response
case class Failure(err: String) ext...
Actor System
Actor System
system.actorOf(Props[A], name = “A”)
Actor System
context.actorOf(Props[C], name = “C”)
Actor System
A is now the supervisor for D
Actor System
An exception occurs in D
Actor System
A declares a ‘Restart’ for the given exception.
Actor System
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10,
withinTimeRange = 1 minute) {
case _...
Actor System
Extras
● Supervisors
○ provide exception handling
○ “let it crash”
○ orthogonal to actor behavior
● Location transparency
...
Extras
● Mailboxes
● Routing
○ e.g., round-robin, smallest mailbox, etc.
● Dispatching
○ essentially how to allocate threa...
Thank you!
Ha terminado este documento.
Descárguela y léala sin conexión.
Próximo SlideShare
Introducing Akka
Siguiente
Próximo SlideShare
Introducing Akka
Siguiente
Descargar para leer sin conexión y ver en pantalla completa.

Compartir

Akka - A Brief Intro

Descargar para leer sin conexión

Just a short intro I gave to an internal audience last year.

Akka - A Brief Intro

  1. 1. & the actor model
  2. 2. What is Akka? A toolkit that provides: simple concurrency resiliency elasticity high performance
  3. 3. What is an actor? Receive and send messages Define behavior for next message Create other actors
  4. 4. The Actor model of computation processing - behavior storage - state model I/O - messages
  5. 5. Key things to understand messages processed sequentially multiple actors can be working at the same time actors are not threads an actor can block (but should minimize it) no shared state
  6. 6. A very simple actor class MyActor extends Actor with ActorLogging { def receive = { case msg ⇒ log.info(“Received: {}”, msg) } }
  7. 7. Creating actors in an actor system Everything begins here: val system = ActorSystem("example") val myActor = system.actorOf(Props[MyActor], name = “myActor”) myActor ! “a boring message”
  8. 8. Messages Can be any object Should be immutable Should be serializable Ideally define a protocol for communication
  9. 9. Protocol “a system of rules that explain the correct conduct and procedures to be followed in formal situations” — Merriam-Webster
  10. 10. Message protocols Define the interaction between actors Specify clear boundaries Encode success and failure clearly
  11. 11. Message protocols trait Response case class Success(res: Array[Byte]) extends Response case class Failure(err: String) extends Response
  12. 12. Actor System
  13. 13. Actor System system.actorOf(Props[A], name = “A”)
  14. 14. Actor System context.actorOf(Props[C], name = “C”)
  15. 15. Actor System A is now the supervisor for D
  16. 16. Actor System An exception occurs in D
  17. 17. Actor System A declares a ‘Restart’ for the given exception.
  18. 18. Actor System override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: SomeException ⇒ Restart case _: Exception ⇒ Escalate }
  19. 19. Actor System
  20. 20. Extras ● Supervisors ○ provide exception handling ○ “let it crash” ○ orthogonal to actor behavior ● Location transparency ○ abstracts the idea of “where” an actor lives
  21. 21. Extras ● Mailboxes ● Routing ○ e.g., round-robin, smallest mailbox, etc. ● Dispatching ○ essentially how to allocate thread resources
  22. 22. Thank you!
  • huiwenhan

    Nov. 5, 2016
  • nachogiljaldo

    Jan. 16, 2016
  • joobn

    Jul. 26, 2015

Just a short intro I gave to an internal audience last year.

Vistas

Total de vistas

1.859

En Slideshare

0

De embebidos

0

Número de embebidos

21

Acciones

Descargas

111

Compartidos

0

Comentarios

0

Me gusta

3

×