Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

A tour of (advanced) Akka features in 40 minutes

220 views

Published on

These are the slides for my Akka presentation at JavaLand in 2017. It covers most Akka features like (remote) actors, clusters, FSM, Akka HTTP and persistence. It's explained on a high level to get an idea on what is possible with Akka.

Published in: Technology
  • Be the first to comment

A tour of (advanced) Akka features in 40 minutes

  1. 1. A Tour of (Advanced) Akka Features in 40 Minutes Johan Janssen, Info Support @johanjanssen42
  2. 2. Content ▪ Why Akka? ▪ Local actor ▪ Remote actor ▪ Scheduling ▪ Cluster ▪ Routing ▪ Cluster singleton ▪ Sharding ▪ Persistence ▪ Akka HTTP ▪ Finite State Machines ▪ Conclusion ▪ Questions
  3. 3. Why Akka?
  4. 4. Why Akka? ▪ Concurrent ▪ Scalable ▪ Fault tolerant ▪ More natural programming experience when connecting to other systems ▪ Easy to use?
  5. 5. Local actor
  6. 6. Local actor Actor on JVM 1
  7. 7. Local actor Coordinator Actor Hello conference
  8. 8. Local actor Coordinator Actor println("Hello conference")
  9. 9. class Worker extends Actor { def receive = { case x => println(x) } } val system = ActorSystem("ExampleActorSystem") val workerActorRef = system.actorOf(Props[Worker]) workerActorRef ! "Hello conference" Scala
  10. 10. Remote actor
  11. 11. Remote actor Actor on JVM 1 Actor on JVM 2
  12. 12. val workerActorRef = system.actorOf(Props[Worker]) workerActorRef ! "Hello conference" val workerActorRef = context.actorSelection("akka.tcp:// ExampleActorSystem@127.0.0.1:9005 /user/workerActor") workerActorRef ! "Hello conference"
  13. 13. akka { actor { provider = "akka.remote.RemoteActorRefProvider" } remote { enabled-transports = ["akka.remote.netty.tcp"] netty.tcp { hostname = "127.0.0.1" port = 9002
  14. 14. Remote actor Coordinator actor Worker actor StartMessage Hello conference
  15. 15. Remote actor Coordinator actor Worker actor WorkerMessage Greetings from the coordinator: Hello Conference
  16. 16. Remote actor Coordinator actor Worker actor WorkerResponse Message Item processed successfully
  17. 17. Scheduling
  18. 18. Scheduling Actor Scheduled once after 1 second Tick Scheduled every 5 seconds Tock system.scheduler.scheduleOnce(1 seconds, scheduleReceiveActor, Tick) system.scheduler.schedule(0 seconds, 5 seconds, scheduleReceiveActor, Tock)
  19. 19. Scheduling ▪ Does not work for fixed point in time like 17:00 – Use Quartz
  20. 20. Cluster
  21. 21. Cluster ActorSystem on JVM 1 ActorSystem on JVM 3 ActorSystem on JVM 2 ActorSystem on JVM 4
  22. 22. Seed nodes ▪ Contact points for automatically joining a cluster
  23. 23. akka { cluster { seed-nodes = [ "akka.tcp://ClusterNode@127.0.0.1:2551", "akka.tcp://ClusterNode@127.0.0.1:2552" ] } }
  24. 24. Cluster Worker Node Port 2551 Association failed with [akka.tcp://ClusterSystem@127.0.0.1:2552
  25. 25. Cluster Worker Node Port 2551 Worker Node Port 2552 Member Up with IP: 127.0.0.1 and port: 2551 Member Up with IP: 127.0.0.1 and port: 2552 Member Up with IP: 127.0.0.1 and port: 2551 Member Up with IP: 127.0.0.1 and port: 2552
  26. 26. Cluster Worker Node Port 2551 Worker Node Port 2552 Member Up with IP: 127.0.0.1 and port: 2550 Member Up with IP: 127.0.0.1 and port: 2550 Coordinator Node Port 2550
  27. 27. Cluster Worker Node Port 2551 Worker Node Port 2552 Coordinator Node Port 2550 RegisterWorker RegisterWorker
  28. 28. Cluster Worker Node Port 2551 Worker Node Port 2552 Coordinator Node Port 2550 Worker registered with IP: 127.0.0.1 and port: 2551 Worker registered with IP: 127.0.0.1 and port: 2552
  29. 29. Routing
  30. 30. Routing Actor on JVM 1 Actor on JVM 3 Actor on JVM 4 Actor on JVM 2 Loadbalancer
  31. 31. akka { actor { provider = "akka.cluster.ClusterActorRefProvider" deployment { /coordinator/router { router = round-robin-pool nr-of-instances = 10 routees.paths = ["/user/emptystringactor"] cluster { enabled = on allow-local-routees = off } } } } }
  32. 32. Routing Coordinator Actor on JVM 1 EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2""
  33. 33. Routing Coordinator Actor on JVM 1 EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2"" HashMap[hostname, counter]
  34. 34. Routing Coordinator Actor on JVM 1 EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2 ""
  35. 35. Routing Coordinator Actor on JVM 1 EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2 ""
  36. 36. Cluster singleton
  37. 37. Cluster singleton ▪ Only one instance of the actor in the cluster ▪ (Re)created on the oldest node ▪ Can be used for instance for scheduling/caching
  38. 38. Cluster singleton Actor on JVM 1 Other actors on JVM 3 Other actors on JVM 4 Singleton actor and other actors on JVM 2
  39. 39. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2""
  40. 40. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2"" HashMap[hostname, counter]
  41. 41. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2""
  42. 42. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2"" HashMap[hostname, counter]
  43. 43. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 EmptyString Actor on JVM 2 Crash
  44. 44. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 ""
  45. 45. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 "" HashMap[hostname, counter]
  46. 46. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 ""
  47. 47. Cluster singleton Coordinator EmptyString Actor on JVM 3 EmptyString Actor on JVM 4 "" HashMap[hostname, counter]
  48. 48. Sharding
  49. 49. Sharding ▪ Dividing a set of actors over a cluster ▪ Actors will be divided into groups called shards ▪ It will divide based on a logical identifier
  50. 50. Sharding Actor on JVM 1 odd Shard on JVM 3 even Shard on JVM 2 0, 2, 4, 6, 8 1, 3, 5, 7, 9
  51. 51. Persistence
  52. 52. Persistence ▪ Store actor information ▪ Recover after crash ▪ Possibility to take snapshots
  53. 53. Example without persistence Actor Cobol
  54. 54. Example without persistence Actor Cobol
  55. 55. Example without persistence Cobol Actor
  56. 56. Example without persistence Actor Java Cobol
  57. 57. Example without persistence Cobol Java Actor Crash Restart
  58. 58. Example without persistence Actor
  59. 59. Example without persistence Actor Scala
  60. 60. Example without persistence Scala Actor
  61. 61. Persistence PersistentActor Cobol Command Journal
  62. 62. Persistence Journal Cobol Event PersistentActor
  63. 63. Persistence Journal ACK PersistentActor Cobol Event
  64. 64. Persistence Cobol Journal Cobol Event PersistentActor
  65. 65. Persistence Cobol Journal Cobol Event PersistentActor Java Event
  66. 66. Persistence Cobol Java Journal Cobol Event PersistentActor Crash Restart Java Event
  67. 67. Persistence Journal Cobol Event PersistentActor Java Event
  68. 68. Persistence Cobol Java Journal Cobol Event PersistentActor Java Event Scala
  69. 69. Persistence Cobol Java Scala Journal Cobol Event PersistentActor Java Event
  70. 70. Snapshots Journal PersistentActor Snapshot store State until Event C++ C++ Cobol
  71. 71. Snapshots Journal PersistentActor Snapshot store State until Event C++ C++ Cobol
  72. 72. Snapshots Journal PersistentActor Snapshot store State until Event C++ C++ Cobol
  73. 73. Snapshots Journal PersistentActor Snapshot store State until Event C++ Java C++ Cobol
  74. 74. Snapshots Journal PersistentActor Snapshot store State until Event C++ Crash Restart C++ Cobol Java
  75. 75. Snapshots Journal PersistentActor Snapshot store State until Event C++ C++ Cobol Java
  76. 76. Snapshots Cobol C++ Journal PersistentActor Snapshot store State until Event C++ C++ Cobol Java
  77. 77. Snapshots Cobol C++ Java Journal PersistentActor Snapshot store State until Event C++ C++ Cobol Java
  78. 78. Snapshots Cobol C++ Java Scala Journal PersistentActor Snapshot store State until Event C++ C++ Cobol Java
  79. 79. Akka HTTP
  80. 80. Akka HTTP Actor on JVM 1 Actor on JVM 2
  81. 81. Finite State Machine
  82. 82. Finite State Machine ▪ State ▪ Event
  83. 83. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Progress, iteration Progress, iteration Progress, iteration NoProgress Progress, 2
  84. 84. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Work harder Iteration: 0
  85. 85. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Good job! Iteration: 0
  86. 86. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Wrong direction Iteration: 0
  87. 87. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Use Akka Iteration: 0
  88. 88. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Good job! Iteration: 1
  89. 89. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Wrong direction Iteration: 1
  90. 90. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Use Akka Iteration: 1
  91. 91. Finite State Machines (FSM) Inprogress Project Crappy Project New Project Get another job! Iteration: 2
  92. 92. Conclusion
  93. 93. Conclusion ▪ Akka can be used with Scala or Java ▪ There is even a .NET version of Akka ▪ Akka is really powerful ▪ Akka is quite easy to use ▪ Some features are still experimental
  94. 94. Questions Johan Janssen @johanjanssen42 GitHub: https://github.com/johanjanssen/Akka-examples

×