Above the clouds: introducing Akka

4,140 views

Published on

Akka is using the Actors together with STM to create a unified runtime and programming model for scaling both UP (multi-core) and OUT (grid/cloud). Akka provides location transparency by abstracting away both these tangents of scalability by turning them into an ops task. This gives the Akka runtime freedom to do adaptive automatic load-balancing, cluster rebalancing, replication & partitioning

Published in: Technology, Business
1 Comment
9 Likes
Statistics
Notes
No Downloads
Views
Total views
4,140
On SlideShare
0
From Embeds
0
Number of Embeds
633
Actions
Shares
0
Downloads
174
Comments
1
Likes
9
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • \n
  • Scalable: Scala stands for SCALAble language which means that the language is designed to scale with the usage. Concepts and abstractions scale from small to larges\nComponent-Oriented: scala was initially designed as a language to do component oriented programming, with its requirements on reusability, maintainability, orthogonality and extensibility.\nCoherent: Scala has managed to build a coherent whole while merging the FP and OO paradigms.\nHigh level: Scala allows you to program it to very high level utilizing its powerful abstractions both in OO and FP\nExtensible: It is great for building Domain Specific Languages (DSLs). Since Scala has a good type inference, a very flexible syntax which gives it a dynamic feel similar to Ruby and Python.\n
  • Above the clouds: introducing Akka

    1. 1. Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jbonerpresented by Martin Odersky
    2. 2. The problemIt is way too hard to build:1. correct highly concurrent systems2. truly scalable systems3. fault-tolerant systems that self-heals...using “state-of-the-art” tools
    3. 3. akkaIntroducing
    4. 4. VisionSimpler Concurrency Scalability Fault-tolerance
    5. 5. Vision...with a single unified Programming model Runtime service
    6. 6. Manage system overload
    7. 7. Scale up & Scale out
    8. 8. Replicate and distribute for fault-tolerance
    9. 9. Transparent load balancing
    10. 10. ARCHITECTURE CORE SERVICES
    11. 11. ARCHITECTURE ADD-ON MODULES
    12. 12. ARCHITECTURE CLOUDY AKKA
    13. 13. WHERE IS AKKA USED? SOME EXAMPLES:FINANCE TELECOM• Stock trend Analysis & Simulation • Streaming media network gateways• Event-driven messaging systems SIMULATIONBETTING & GAMING • 3D simulation engines• Massive multiplayer online gaming E-COMMERCE• High throughput and transactional • Social media community sites betting
    14. 14. What is an Actor?
    15. 15. ActorBehavior State
    16. 16. Event- drivenActorBehavior State
    17. 17. Event- drivenActorBehavior State
    18. 18. Event- drivenActorBehavior State
    19. 19. Event- drivenActorBehavior State
    20. 20. Event- drivenActorBehavior State
    21. 21. ActorBehavior State
    22. 22. Event- drivenActorBehavior State
    23. 23. Akka Actorsone tool in the toolbox
    24. 24. Actorscase object Tickclass Counter extends Actor { var counter = 0 def receive = { case Tick => counter += 1 println(counter) }}
    25. 25. Create Actorsval counter = actorOf[Counter] counter is an ActorRef
    26. 26. Start actorsval counter = actorOf[Counter].start
    27. 27. Stop actorsval counter = actorOf[Counter].startcounter.stop
    28. 28. Send: !counter ! Tick fire-forget
    29. 29. Send: !!!// returns a futureval future = actor !!! Messagefuture.awaitval result = future.result returns the Future directly
    30. 30. Futureval future1, future2, future3 = Future.empty[String]future1.awaitfuture2.onComplete(f => ...)future1.completeWithResult(...)future2.completeWithException(...)future3.completeWith(future2)
    31. 31. Futureval f1 = Futures.future(callable)val f2 = Futures.firstCompletedOf(futures)val f3 = Futures.reduce(futures)((x, y) => ..)val f4 = Futures.fold(zero)(futures)((x, y) => ...)
    32. 32. Futureval future1 = for { a: Int <- actor !!! "Hello" // returns 5 b: String <- actor !!! a // returns "10" c: String <- actor !!! 7 // returns "14"} yield b + "-" + cval future2 = for { a <- actor !!! Req("Hello") collect { case Res(x: Int) => x } b <- actor !!! Req(a) collect { case Res(x: String) => x } c <- actor !!! Req(7) collect { case Res(x: String) => x }} yield b + "-" + c
    33. 33. Dataflowimport Future.flowval x, y, z = Promise[Int]()flow { z << x() + y() println("z = " + z())}flow { x << 40 }flow { y << 2 }
    34. 34. Send: !!val result = (actor !! Message).as[String] uses Future under the hood and blocks until timeout or completion
    35. 35. Replyclass SomeActor extends Actor { def receive = { case User(name) => // use reply self.reply(“Hi ” + name) }}
    36. 36. HotSwapself become { // new body case NewMessage => ...}
    37. 37. HotSwapactor ! HotSwap { // new body case NewMessage => ...}
    38. 38. HotSwapself.unbecome()
    39. 39. Set dispatcherclass MyActor extends Actor { self.dispatcher = Dispatchers .newThreadBasedDispatcher(self) ...}actor.dispatcher = dispatcher // before started
    40. 40. Remote Actors
    41. 41. Remote Server// use host & port in configActor.remote.start()Actor.remote.start("localhost", 2552) Scalable implementation based on NIO (Netty) & Protobuf
    42. 42. Two types ofremote actorsClient initiated & managedServer initiated & managed
    43. 43. Client-managed supervision works across nodesimport Actor._val service = remote.actorOf[MyActor](host, port)service ! message
    44. 44. Server-managedregister and manage actor on server client gets “dumb” proxy handle import Actor._ remote.register(“service:id”, actorOf[MyService]) server part
    45. 45. Server-managed val service = remote.actorFor( “service:id”, “darkstar”, 9999) service ! message client part
    46. 46. Server-managed import Actor._ remote.register(actorOf[MyService]) remote.registerByUuid(actorOf[MyService]) remote.registerPerSession( “service:id”, actorOf[MyService]) remote.unregister(“service:id”) remote.unregister(actorRef) server part
    47. 47. Remoting in Akka 1.1 Remote Actors Client-managed Server-managed ProblemDeployment (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
    48. 48. Clustered Actors(in development for upcoming Akka 2.0)
    49. 49. Addressval actor = actorOf[MyActor](“my-service”) Bind the actor to a virtual address
    50. 50. 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
    51. 51. Deployment configuration akka { actor { deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1" replicas = 3 stateless = on } } } } }
    52. 52. Deployment configuration akka { Address actor { deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1" replicas = 3 stateless = on } } } } }
    53. 53. Deployment configuration akka { Address actor { Type of load- deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1" replicas = 3 stateless = on } } } } }
    54. 54. Deployment configuration akka { Address actor { Type of load- deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1"Clustered replicas = 3 or Local stateless = on } } } } }
    55. 55. Deployment configuration akka { Address actor { Type of load- deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1"Clustered replicas = 3 or Local stateless = on } Home node } } } }
    56. 56. Deployment configuration akka { Address actor { Type of load- deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1"Clustered replicas = 3 or Local stateless = on } Home node } } } Nr of replicas } in cluster
    57. 57. Deployment configuration akka { Address actor { Type of load- deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1"Clustered replicas = 3 or Local stateless = on } Home node } } } Stateful or Nr of replicas } in cluster Stateless
    58. 58. 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
    59. 59. Upcoming features•Publish/Subscribe (broker and broker-less)•Compute Grid (MapReduce)•Data Grid (querying etc)•Distributed STM (Transactional Memory)•Event Sourcing
    60. 60. Akka Node
    61. 61. Akka Nodeval ping = actorOf[Ping](“ping”)val pong = actorOf[Pong](“pong”)ping ! Ball(pong)
    62. 62. Akka Node val ping = actorOf[Ping](“ping”) val pong = actorOf[Pong](“pong”) ping ! Ball(pong)Ping Pong
    63. 63. Akka Node AkkaCluster Node Ping Pong
    64. 64. Akka Cluster Node Akka Node Akka AkkaCluster Node Cluster Node Ping Pong Akka Akka Cluster Node Cluster Node
    65. 65. Akka Cluster Node Akka AkkaCluster Node Cluster Node Ping Pong Akka Akka Cluster Node Cluster Node
    66. 66. Akka Cluster Node akka { Akka actor { Akka deployment {Cluster Node ping {} Cluster Node pong { router = "round-robin" clustered { replicas = 3 stateless = on } } Ping} Pong } } Akka Akka Cluster Node Cluster Node
    67. 67. Akka Cluster Node akka { Akka actor { Akka Ping deployment {Cluster Node ping {} Cluster Node pong { router = "round-robin" clustered { replicas = 3 stateless = on } } } Pong } } Akka Akka Cluster Node Cluster Node
    68. 68. Akka Pong Cluster Node akka { Akka actor { Akka Ping deployment { PongCluster Node ping {} Cluster Node pong { router = "round-robin" clustered { replicas = 3 stateless = on } } } } } Akka Akka Pong Cluster Node Cluster Node
    69. 69. Akka Pong Cluster Node akka { Akka actor { Akka Ping deployment { PongCluster Node ping {} Cluster Node pong { router = "round-robin" clustered { ZooKeeper ZooKeeper replicas = 3 ZooKeeper stateless = on Ensemble } } } } } Akka Akka Pong Cluster Node Cluster Node
    70. 70. Let it crashfault-tolerance
    71. 71. TheErlang model
    72. 72. 9 nines
    73. 73. ...let’s take astandard OO application
    74. 74. Which components havecritically important state and explicit error handling?
    75. 75. 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 •
    76. 76. 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 •
    77. 77. Classification of State• Scratch data• Static data • Supplied Must time at boot be • Supplied by other components protected• Dynamic data • Databy anyto recompute possible means • Input from other sources; data that is impossible to recompute •
    78. 78. Fault-tolerantonion-layered Error Kernel
    79. 79. ErrorKernel
    80. 80. ErrorKernel
    81. 81. ErrorKernel
    82. 82. ErrorKernel
    83. 83. ErrorKernel
    84. 84. ErrorKernel
    85. 85. ErrorKernel
    86. 86. ErrorKernel
    87. 87. ErrorKernel
    88. 88. ErrorKernel
    89. 89. ErrorKernel
    90. 90. ErrorKernel
    91. 91. ErrorKernel
    92. 92. ErrorKernel
    93. 93. ErrorKernel
    94. 94. Node 1 Node 2
    95. 95. Linkinglink(actor)unlink(actor)startLink(actor)spawnLink[MyActor]
    96. 96. Fault handlers AllForOneStrategy( errors, maxNrOfRetries, withinTimeRange) OneForOneStrategy( errors, maxNrOfRetries, withinTimeRange)
    97. 97. Supervisionclass
Supervisor
extends
Actor
{

faultHandler
=
AllForOneStrategy(



List(classOf[IllegalStateException])




5,
5000))

def
receive
=
{



case
Register(actor)
=>
link(actor)

}}
    98. 98. Manage failureclass FaultTolerantService extends Actor { ... override def preRestart(reason: Throwable) = { ... // clean up before restart } override def postRestart(reason: Throwable) = { ... // init after restart }}
    99. 99. ...and much much more STM FSMHTTP Camel Microkernel GuiceOSGi Dataflow AMQPscalaz Spring Security
    100. 100. Get it and learn more http://akka.io
    101. 101. EOF

    ×