“Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors”
Overview <ul><li>Developed by Scalable Solutions, http://scalablesolutions.se/
Event-driven actors
Remote actors
Supervision
STM </li></ul><ul>Jonas Bonér </ul>
Concurrency <ul><li>“Threads are bad” – dogma or truth?
Obviously, we can do just fine with shared mutable state and locks
But abstraction is good </li></ul>
Actors <ul><li>Model of concurrent computation based on  the physical world
Communication by asynchronous message passing
Concurrency without shared mutable state and locks
Made popular by Erlang </li></ul>
Actors in Scala <ul><li>Scala's primary concurrency primitive
Actors can encapsulate mutable state, but should communicate with immutable messages
Upcoming SlideShare
Loading in …5
×

Overview of Akka

4,310 views

Published on

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
  • This presentation comes not from any particular authority on Akka but is merely a representation of my understanding of the concepts employed by the framework. Please leave a comment and let me know if any of this seems incorrect ;)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
4,310
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Overview of Akka

  1. 1. “Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors”
  2. 2. Overview <ul><li>Developed by Scalable Solutions, http://scalablesolutions.se/
  3. 3. Event-driven actors
  4. 4. Remote actors
  5. 5. Supervision
  6. 6. STM </li></ul><ul>Jonas Bonér </ul>
  7. 7. Concurrency <ul><li>“Threads are bad” – dogma or truth?
  8. 8. Obviously, we can do just fine with shared mutable state and locks
  9. 9. But abstraction is good </li></ul>
  10. 10. Actors <ul><li>Model of concurrent computation based on the physical world
  11. 11. Communication by asynchronous message passing
  12. 12. Concurrency without shared mutable state and locks
  13. 13. Made popular by Erlang </li></ul>
  14. 14. Actors in Scala <ul><li>Scala's primary concurrency primitive
  15. 15. Actors can encapsulate mutable state, but should communicate with immutable messages
  16. 16. class Greeter extends Actor {
  17. 17. def act() {
  18. 18. while (true) {
  19. 19. receive {
  20. 20. case name: String => println(&quot;Hello, &quot;+name)
  21. 21. case _ => println(&quot;That's not a name!&quot;)
  22. 22. }
  23. 23. }
  24. 24. }
  25. 25. } </li></ul>
  26. 26. Akka Actors <ul><li>Akka implements its own Actors, similar API to Scala actors
  27. 27. class Greeter extends Actor {
  28. 28. def receive = {
  29. 29. case name: String => println(&quot;Hello, &quot;+name)
  30. 30. case _ => println(&quot;That's not a name!&quot;)
  31. 31. }
  32. 32. } </li></ul>
  33. 33. Hotswap! <ul>val greeter = actorOf[ Greeter ].start greeter ! HotSwap (Some({ case _ => println(&quot;Leave me alone!&quot;) })) </ul>
  34. 34. Remote Actors <ul><li>Start actors on remote nodes
  35. 35. Communication with remote actors is transparent
  36. 36. class RemoteGreeter extends Greeter {
  37. 37. self.makeRemote(&quot;192.1.33.7&quot;, 1337)
  38. 38. } </li></ul>
  39. 39. Supervision <ul><li>Supervisors keep child processes alive, restarting when they crash
  40. 40. Enables fault tolerance
  41. 41. “Let it crash”, aka “Embrace failure” – discourages defensive programming; simpler programs result </li></ul>
  42. 42. Supervision: Restart Strategies One for one All for one
  43. 43. Simple supervision example <ul>class RemoteGreeter extends Greeter { self.lifeCycle = Some( LifeCycle ( Permanent )) self.makeRemote(&quot;192.1.33.7&quot;, 1337) } trait GreeterSupervisor extends Actor { self.faultHandler = Some ( OneForOneStrategy (5, 5000)) self.trapExit = List (classOf[ Exception ]) val greeter = this.self.spawnLink[ RemoteGreeter ] } </ul>
  44. 44. Software Transactional Memory (STM) <ul><li>Way of controlling access to shared memory
  45. 45. Optimistic: log, don't lock
  46. 46. Akka provides several STM managed data structures, e.g.
  47. 47. val names = TransactionalVector [ String ]()
  48. 48. val ages = TransactionalMap [ String , Int ]()
  49. 49. These provide Atomicity, Consistency and Isolation
  50. 50. Akka's persistence modules provide Durability: Cassandra, Redis, MongoDB, </li></ul>
  51. 51. Transactional Actors... Transactors <ul><li>Sometimes, we need multiple actors to take part in an atomic operation
  52. 52. class Bank extends Transactor {
  53. 53. def receive = {
  54. 54. case Transfer (from, to, amount) =>
  55. 55. to ! Deposit (amount)
  56. 56. from ! Withdraw (amount)
  57. 57. }
  58. 58. } </li></ul>
  59. 59. Transactions Compose <ul><li>Any actors invoked within a transaction become part of that transaction </li></ul>
  60. 60. Thanks! Twitter: bmjames

×