above the clouds introducing akka
play

Above the Clouds: Introducing Akka Jonas Bonr CTO Typesafe - PowerPoint PPT Presentation

Above the Clouds: Introducing Akka Jonas Bonr CTO Typesafe Twitter: @jboner torsdag 13 oktober 11 The problem It is way too hard to build: 1. correct highly concurrent systems 2. truly scalable systems 3. fault-tolerant systems that


  1. Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jboner torsdag 13 oktober 11

  2. The problem It is way too hard to build: 1. correct highly concurrent systems 2. truly scalable systems 3. fault-tolerant systems that self-heals ...using “state-of-the-art” tools torsdag 13 oktober 11

  3. akka Introducing torsdag 13 oktober 11

  4. Vision Simpler Concurrency Scalability Fault-tolerance torsdag 13 oktober 11

  5. Vision ...with a single unified Programming model Runtime service torsdag 13 oktober 11

  6. Manage system overload torsdag 13 oktober 11

  7. Scale up & Scale out torsdag 13 oktober 11

  8. Replicate and distribute for fault-tolerance torsdag 13 oktober 11

  9. Transparent load balancing torsdag 13 oktober 11

  10. ARCHITECTURE CORE SERVICES torsdag 13 oktober 11

  11. ARCHITECTURE ADD-ON MODULES torsdag 13 oktober 11

  12. ARCHITECTURE CLOUDY AKKA torsdag 13 oktober 11

  13. WHERE IS AKKA USED? SOME EXAMPLES: FINANCE TELECOM • • Stock trend Analysis & Simulation Streaming media network gateways • Event-driven messaging systems SIMULATION BETTING & GAMING • 3D simulation engines • Massive multiplayer online gaming E-COMMERCE • High throughput and transactional • Social media community sites betting torsdag 13 oktober 11

  14. What is an Actor? torsdag 13 oktober 11

  15. Actor Behavior State torsdag 13 oktober 11

  16. Event-driven Thread Actor Behavior State torsdag 13 oktober 11

  17. Event-driven Thread Actor Behavior State torsdag 13 oktober 11

  18. Event-driven Thread Actor Behavior State torsdag 13 oktober 11

  19. Event-driven Thread Actor Behavior State torsdag 13 oktober 11

  20. Event-driven Thread Actor Behavior State torsdag 13 oktober 11

  21. Actor Behavior State torsdag 13 oktober 11

  22. Event-driven Thread Actor Behavior State torsdag 13 oktober 11

  23. Akka Actors one tool in the toolbox torsdag 13 oktober 11

  24. Actors case object Tick class Counter extends Actor { var counter = 0 def receive = { case Tick => counter += 1 println(counter) } } torsdag 13 oktober 11

  25. Create Actors val counter = actorOf[Counter] counter is an ActorRef torsdag 13 oktober 11

  26. Start actors val counter = actorOf[Counter].start torsdag 13 oktober 11

  27. Stop actors val counter = actorOf[Counter].start counter.stop torsdag 13 oktober 11

  28. Send: ! counter ! Tick fire-forget torsdag 13 oktober 11

  29. Send: ? // returns a future val future = actor ? Message future onComplete { f => f.value } returns the Future directly torsdag 13 oktober 11

  30. Future val future1, future2, future3 = Future.empty[String] future1.await future2 onComplete { f => ... } future3 onResult { ... } onException { ... } onTimeout { ... } future1 foreach { ... } future1 map { ... } future1 flatMap { ... } future1 filter { ... } torsdag 13 oktober 11

  31. Future val f0 = Future { ... } Future.firstCompletedOf(futures) Future.reduce(futures)((x, y) => ..) Future.fold(zero)(futures)((x, y) => ...) Future.find { ... } Future.sequence { ... } Future.traverse { ... } torsdag 13 oktober 11

  32. Promise promise1.completeWithResult(...) promise2.completeWithException(...) promise3.completeWith(promise2) The write side of the Future torsdag 13 oktober 11

  33. Dataflow import Future.flow val x, y, z = Promise[Int]() flow { z << x() + y() println("z = " + z()) } flow { x << 40 } flow { y << 2 } torsdag 13 oktober 11

  34. Reply class SomeActor extends Actor { def receive = { case User(name) => // use reply self.reply(“Hi ” + name) } } torsdag 13 oktober 11

  35. HotSwap self become { // new body case NewMessage => ... } torsdag 13 oktober 11

  36. HotSwap self.unbecome() torsdag 13 oktober 11

  37. Set dispatcher class MyActor extends Actor { self.dispatcher = Dispatchers .newPinnedDispatcher(self) ... } actor.dispatcher = dispatcher // before started torsdag 13 oktober 11

  38. Remote Actors torsdag 13 oktober 11

  39. Remote Server // use host & port in config Actor.remote.start() Actor.remote.start("localhost", 2552) Scalable implementation based on NIO (Netty) & Protobuf torsdag 13 oktober 11

  40. Register and manage actor on server client gets “dumb” proxy handle import Actor._ remote.register(“service:id”, actorOf[MyService]) server part torsdag 13 oktober 11

  41. val service = remote.actorFor( “service:id”, “darkstar”, 9999) service ! message client part torsdag 13 oktober 11

  42. Remoting in Akka 1.2 Problem Deployment (local vs remote) is a dev decision We get a fixed and hard-coded topology Can’t change it dynamically and adaptively Needs to be a deployment & runtime decision torsdag 13 oktober 11

  43. Clustered Actors (in development for upcoming Akka 2.x) torsdag 13 oktober 11

  44. Address val actor = actorOf[MyActor](“ my-service ”) Bind the actor to a virtual address torsdag 13 oktober 11

  45. Deployment •Actor address is virtual and decoupled from how it is deployed •If no deployment configuration exists then actor is deployed as local •The same system can be configured as distributed without code change (even change at runtime) •Write as local but deploy as distributed in the cloud without code change •Allows runtime to dynamically and adaptively change topology torsdag 13 oktober 11

  46. Deployment configuration akka { actor { deployment { my-service { router = "least-cpu" failure-detector = "accrual" clustered { nr-of-instances = 3 replication { storage = "transaction-log" strategy = "write-through" } } } } } } torsdag 13 oktober 11

  47. The runtime provides •Subscription-based cluster membership service •Highly available cluster registry for actors •Automatic cluster-wide deployment •Highly available centralized configuration service •Automatic replication with automatic fail-over upon node crash •Transparent and user-configurable load-balancing •Transparent adaptive cluster rebalancing •Leader election •Durable mailboxes - guaranteed delivery torsdag 13 oktober 11

  48. Akka Node torsdag 13 oktober 11

  49. Akka Node val ping = actorOf[Ping](“ping”) val pong = actorOf[Pong](“pong”) ping ! Ball(pong) torsdag 13 oktober 11

  50. Akka Node val ping = actorOf[Ping](“ping”) val pong = actorOf[Pong](“pong”) ping ! Ball(pong) Pong Ping torsdag 13 oktober 11

  51. Akka Node Akka Cluster Node Pong Ping torsdag 13 oktober 11

  52. Akka Cluster Node Akka Node Akka Akka Cluster Node Cluster Node Pong Ping Akka Akka Cluster Node Cluster Node torsdag 13 oktober 11

  53. Akka Cluster Node Akka Akka Cluster Node Cluster Node Pong Ping Akka Akka Cluster Node Cluster Node torsdag 13 oktober 11

  54. Akka Cluster Node Akka Akka akka { actor { Cluster Node Cluster Node deployment { ping {} pong { router = "round-robin" clustered { nr-of-instances = 3 } } Pong Ping } } } Akka Akka Cluster Node Cluster Node torsdag 13 oktober 11

  55. Akka Cluster Node Akka Akka akka { Ping actor { Cluster Node Cluster Node deployment { ping {} pong { router = "round-robin" clustered { nr-of-instances = 3 } } Pong } } } Akka Akka Cluster Node Cluster Node torsdag 13 oktober 11

  56. Akka Pong Cluster Node Akka Akka akka { Pong Ping actor { Cluster Node Cluster Node deployment { ping {} pong { router = "round-robin" clustered { nr-of-instances = 3 } } } } } Akka Akka Pong Cluster Node Cluster Node torsdag 13 oktober 11

  57. Akka Pong Cluster Node Akka Akka akka { Pong Ping actor { Cluster Node Cluster Node deployment { ping {} pong { router = "round-robin" ZooKeeper ZooKeeper ZooKeeper clustered { Ensemble nr-of-instances = 3 } } } } } Akka Akka Pong Cluster Node Cluster Node torsdag 13 oktober 11

  58. Let it crash fault-tolerance torsdag 13 oktober 11

  59. The Erlang model torsdag 13 oktober 11

  60. 9 nines torsdag 13 oktober 11

  61. ...let’s take a standard OO application torsdag 13 oktober 11

  62. torsdag 13 oktober 11

  63. Which components have critically important state and explicit error handling? torsdag 13 oktober 11

  64. torsdag 13 oktober 11

  65. Classification of State • Scratch data • Static data • Supplied at boot time • Supplied by other components • Dynamic data • Data possible to recompute • Input from other sources; data that is impossible to recompute torsdag 13 oktober 11

  66. Classification of State • Scratch data • Static data • Supplied at boot time • Supplied by other components • Dynamic data • Data possible to recompute • Input from other sources; data that is impossible to recompute torsdag 13 oktober 11

  67. Classification of State • Scratch data Must be • Static data • Supplied at boot time protected • Supplied by other components by any means • Dynamic data • Data possible to recompute • Input from other sources; data that is impossible to recompute torsdag 13 oktober 11

Recommend


More recommend