Akka in action  JAX London 2012   Heiko Seeberger
What is scalability?
What is scalability?• Ability of a system to handle growing work or
What is scalability?• Ability of a system to handle growing work or• its ability to be enlarged to accommodate growth.
Why should wecare about scalability?
Because of the human nature
So how can we build  scalable systems?
Scaling up
Concurrency Scaling up
Scaling out
DistributionScaling out
So how can we easily build    scalable systems?
Akka’s vision
Akka’s vision• Simpler concurrency (scale up)
Akka’s vision• Simpler concurrency (scale up)• Simpler distribution (scale out)
Akka’s vision• Simpler concurrency (scale up)• Simpler distribution (scale out)• Simpler fault-tolerance (self healing)
Akka’s vision• Simpler concurrency (scale up)• Simpler distribution (scale out)• Simpler fault-tolerance (self healing)• A...
The Akka toolkit
The Akka toolkit• Akka runs on the JVM
The Akka toolkit• Akka runs on the JVM• Akka can be used from Java and Scala
The Akka toolkit• Akka runs on the JVM• Akka can be used from Java and Scala• Akka can be integrated with common infrastru...
What’s inside the toolbox?
What’s inside the toolbox?• Actors
What’s inside the toolbox?• Actors• Agents
What’s inside the toolbox?• Actors• Agents• Dataflow concurrency
What’s inside the toolbox?• Actors• Agents• Dataflow concurrency• STM
What is an actor?
What is an actor?• Carl Hewitt (1973): Fundamental unit of computation
What is an actor?• Carl Hewitt (1973): Fundamental unit of computation  •   Behavior - react on messages it receives
What is an actor?• Carl Hewitt (1973): Fundamental unit of computation  •   Behavior - react on messages it receives  •   ...
What is an actor?• Carl Hewitt (1973): Fundamental unit of computation  •   Behavior - react on messages it receives  •   ...
What is an actor?• Carl Hewitt (1973): Fundamental unit of computation  •   Behavior - react on messages it receives  •   ...
Other notions of an actor
Other notions of an actor• Implementation of message passing concurrency
Other notions of an actor• Implementation of message passing concurrency• Isolated lightweight processes
Other notions of an actor• Implementation of message passing concurrency• Isolated lightweight processes• Asynchronous and...
The Akka Actor
The Akka Actor
The Akka Actor
The Akka Actor
Receive messages
Receive messagespublic class Hello extends UntypedActor {    @Override    public void onReceive(Object message) {      Sys...
Receive messagespublic class Hello extends UntypedActor {    public int count = 0;    @Override    public void onReceive(O...
Receive messagespublic class Hello extends UntypedActor {    public int count = 0;          One at a time    @Override    ...
Send messages
Send messages  ActorRef hello = ...  hello.tell("Hi!");
Send messagesAsynchronous and   ActorRef hello = ...   hello.tell("Hi!");   nonblocking
The Akka ActorSystem
The Akka ActorSystem
The Akka ActorSystem
Create an actor system
Create an actor system   ActorSystem system =     ActorSystem.create("hello");
Create a top-level actor
Create a top-level actor ActorRef hello =   system.actorOf(new Props(new Hello()));
Create a child actor
Create a child actorActorRef child =  context().actorOf(new Props(new Child()));
Embrace failure
Embrace failure• Let it crash!
Embrace failure• Let it crash!• Supervision: Like in real life, parents supervise their children
Embrace failure• Let it crash!• Supervision: Like in real life, parents supervise their children• Depending on the parent’...
HakkyHour demo
The HakkyHour bar
The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada
The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada• Our actors: guests, waiters, head waiter, barkeepers
The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada• Our actors: guests, waiters, head waiter, barkeepers• Our m...
The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada• Our actors: guests, waiters, head waiter, barkeepers• Our m...
HakkyHour actor system
HakkyHour messages
HakkyHour messages
HakkyHour messages
HakkyHour messages
HakkyHour messages
HakkyHour messages
HakkyHour messages
Live demo ...
Why does Akka make building  scalable systems easy?
Benefits of using Akka actors
Benefits of using Akka actors• You don’t have to deal with concurrency details
Benefits of using Akka actors• You don’t have to deal with concurrency details• You can manage failures easily
Benefits of using Akka actors• You don’t have to deal with concurrency details• You can manage failures easily• Distributio...
Questions?
Thank you!Twitter: @hseeberger
Akka in Action: Heiko Seeburger
Upcoming SlideShare
Loading in …5
×

Akka in Action: Heiko Seeburger

2,545 views

Published on

Scalable systems make us face challenges like concurrency, distribution, fault tolerance, elasticity, etc. Akka not only steps up to meet these, but it makes writing scalable software particularly easy. We will demo Akka's most important tool, the actor model, using a vivid example and live coding.

Akka in Action: Heiko Seeburger

  1. 1. Akka in action JAX London 2012 Heiko Seeberger
  2. 2. What is scalability?
  3. 3. What is scalability?• Ability of a system to handle growing work or
  4. 4. What is scalability?• Ability of a system to handle growing work or• its ability to be enlarged to accommodate growth.
  5. 5. Why should wecare about scalability?
  6. 6. Because of the human nature
  7. 7. So how can we build scalable systems?
  8. 8. Scaling up
  9. 9. Concurrency Scaling up
  10. 10. Scaling out
  11. 11. DistributionScaling out
  12. 12. So how can we easily build scalable systems?
  13. 13. Akka’s vision
  14. 14. Akka’s vision• Simpler concurrency (scale up)
  15. 15. Akka’s vision• Simpler concurrency (scale up)• Simpler distribution (scale out)
  16. 16. Akka’s vision• Simpler concurrency (scale up)• Simpler distribution (scale out)• Simpler fault-tolerance (self healing)
  17. 17. Akka’s vision• Simpler concurrency (scale up)• Simpler distribution (scale out)• Simpler fault-tolerance (self healing)• All of that with a single unified programming model
  18. 18. The Akka toolkit
  19. 19. The Akka toolkit• Akka runs on the JVM
  20. 20. The Akka toolkit• Akka runs on the JVM• Akka can be used from Java and Scala
  21. 21. The Akka toolkit• Akka runs on the JVM• Akka can be used from Java and Scala• Akka can be integrated with common infrastructure, e.g. Spring, Camel, ZeroMQ, etc.
  22. 22. What’s inside the toolbox?
  23. 23. What’s inside the toolbox?• Actors
  24. 24. What’s inside the toolbox?• Actors• Agents
  25. 25. What’s inside the toolbox?• Actors• Agents• Dataflow concurrency
  26. 26. What’s inside the toolbox?• Actors• Agents• Dataflow concurrency• STM
  27. 27. What is an actor?
  28. 28. What is an actor?• Carl Hewitt (1973): Fundamental unit of computation
  29. 29. What is an actor?• Carl Hewitt (1973): Fundamental unit of computation • Behavior - react on messages it receives
  30. 30. What is an actor?• Carl Hewitt (1973): Fundamental unit of computation • Behavior - react on messages it receives • State - shielded from the rest of the world, no need for synchronization
  31. 31. What is an actor?• Carl Hewitt (1973): Fundamental unit of computation • Behavior - react on messages it receives • State - shielded from the rest of the world, no need for synchronization • Communication - interact with other actors exclusively via messages
  32. 32. What is an actor?• Carl Hewitt (1973): Fundamental unit of computation • Behavior - react on messages it receives • State - shielded from the rest of the world, no need for synchronization • Communication - interact with other actors exclusively via messages• “One actor is no actor” - they come in systems
  33. 33. Other notions of an actor
  34. 34. Other notions of an actor• Implementation of message passing concurrency
  35. 35. Other notions of an actor• Implementation of message passing concurrency• Isolated lightweight processes
  36. 36. Other notions of an actor• Implementation of message passing concurrency• Isolated lightweight processes• Asynchronous and non-blocking
  37. 37. The Akka Actor
  38. 38. The Akka Actor
  39. 39. The Akka Actor
  40. 40. The Akka Actor
  41. 41. Receive messages
  42. 42. Receive messagespublic class Hello extends UntypedActor { @Override public void onReceive(Object message) { System.out.println("Hello, world!"); }}
  43. 43. Receive messagespublic class Hello extends UntypedActor { public int count = 0; @Override public void onReceive(Object message) { count += 1; System.out.println( "Hello for the " + count + " time!" ); }}
  44. 44. Receive messagespublic class Hello extends UntypedActor { public int count = 0; One at a time @Override public void onReceive(Object message) { count += 1; System.out.println( "Hello for the " + count + " time!" ); }}
  45. 45. Send messages
  46. 46. Send messages ActorRef hello = ... hello.tell("Hi!");
  47. 47. Send messagesAsynchronous and ActorRef hello = ... hello.tell("Hi!"); nonblocking
  48. 48. The Akka ActorSystem
  49. 49. The Akka ActorSystem
  50. 50. The Akka ActorSystem
  51. 51. Create an actor system
  52. 52. Create an actor system ActorSystem system = ActorSystem.create("hello");
  53. 53. Create a top-level actor
  54. 54. Create a top-level actor ActorRef hello = system.actorOf(new Props(new Hello()));
  55. 55. Create a child actor
  56. 56. Create a child actorActorRef child = context().actorOf(new Props(new Child()));
  57. 57. Embrace failure
  58. 58. Embrace failure• Let it crash!
  59. 59. Embrace failure• Let it crash!• Supervision: Like in real life, parents supervise their children
  60. 60. Embrace failure• Let it crash!• Supervision: Like in real life, parents supervise their children• Depending on the parent’s supervisor strategy, failing actors can get stopped, restarted or resumed
  61. 61. HakkyHour demo
  62. 62. The HakkyHour bar
  63. 63. The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada
  64. 64. The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada• Our actors: guests, waiters, head waiter, barkeepers
  65. 65. The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada• Our actors: guests, waiters, head waiter, barkeepers• Our messages: Order, drink served, complaint, etc.
  66. 66. The HakkyHour bar• Our drinks: Akkarita, MaiPlay, PinaScalada• Our actors: guests, waiters, head waiter, barkeepers• Our messages: Order, drink served, complaint, etc.• Our failures: Guest drunk, waiter frustrated
  67. 67. HakkyHour actor system
  68. 68. HakkyHour messages
  69. 69. HakkyHour messages
  70. 70. HakkyHour messages
  71. 71. HakkyHour messages
  72. 72. HakkyHour messages
  73. 73. HakkyHour messages
  74. 74. HakkyHour messages
  75. 75. Live demo ...
  76. 76. Why does Akka make building scalable systems easy?
  77. 77. Benefits of using Akka actors
  78. 78. Benefits of using Akka actors• You don’t have to deal with concurrency details
  79. 79. Benefits of using Akka actors• You don’t have to deal with concurrency details• You can manage failures easily
  80. 80. Benefits of using Akka actors• You don’t have to deal with concurrency details• You can manage failures easily• Distribution is just a deployment decision (not covered here)
  81. 81. Questions?
  82. 82. Thank you!Twitter: @hseeberger

×