Your SlideShare is downloading. ×

Above the clouds: introducing Akka

3,413

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 …

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
3,413
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
153
Comments
1
Likes
9
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
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
  • Transcript

    • 1. Above the Clouds: Introducing Akka Jonas Bonér CTO Typesafe Twitter: @jbonerpresented by Martin Odersky
    • 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. akkaIntroducing
    • 4. VisionSimpler Concurrency Scalability Fault-tolerance
    • 5. Vision...with a single unified Programming model Runtime service
    • 6. Manage system overload
    • 7. Scale up & Scale out
    • 8. Replicate and distribute for fault-tolerance
    • 9. Transparent load balancing
    • 10. ARCHITECTURE CORE SERVICES
    • 11. ARCHITECTURE ADD-ON MODULES
    • 12. ARCHITECTURE CLOUDY AKKA
    • 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. What is an Actor?
    • 15. ActorBehavior State
    • 16. Event- drivenActorBehavior State
    • 17. Event- drivenActorBehavior State
    • 18. Event- drivenActorBehavior State
    • 19. Event- drivenActorBehavior State
    • 20. Event- drivenActorBehavior State
    • 21. ActorBehavior State
    • 22. Event- drivenActorBehavior State
    • 23. Akka Actorsone tool in the toolbox
    • 24. Actorscase object Tickclass Counter extends Actor { var counter = 0 def receive = { case Tick => counter += 1 println(counter) }}
    • 25. Create Actorsval counter = actorOf[Counter] counter is an ActorRef
    • 26. Start actorsval counter = actorOf[Counter].start
    • 27. Stop actorsval counter = actorOf[Counter].startcounter.stop
    • 28. Send: !counter ! Tick fire-forget
    • 29. Send: !!!// returns a futureval future = actor !!! Messagefuture.awaitval result = future.result returns the Future directly
    • 30. Futureval future1, future2, future3 = Future.empty[String]future1.awaitfuture2.onComplete(f => ...)future1.completeWithResult(...)future2.completeWithException(...)future3.completeWith(future2)
    • 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. 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. Dataflowimport Future.flowval x, y, z = Promise[Int]()flow { z << x() + y() println("z = " + z())}flow { x << 40 }flow { y << 2 }
    • 34. Send: !!val result = (actor !! Message).as[String] uses Future under the hood and blocks until timeout or completion
    • 35. Replyclass SomeActor extends Actor { def receive = { case User(name) => // use reply self.reply(“Hi ” + name) }}
    • 36. HotSwapself become { // new body case NewMessage => ...}
    • 37. HotSwapactor ! HotSwap { // new body case NewMessage => ...}
    • 38. HotSwapself.unbecome()
    • 39. Set dispatcherclass MyActor extends Actor { self.dispatcher = Dispatchers .newThreadBasedDispatcher(self) ...}actor.dispatcher = dispatcher // before started
    • 40. Remote Actors
    • 41. Remote Server// use host & port in configActor.remote.start()Actor.remote.start("localhost", 2552) Scalable implementation based on NIO (Netty) & Protobuf
    • 42. Two types ofremote actorsClient initiated & managedServer initiated & managed
    • 43. Client-managed supervision works across nodesimport Actor._val service = remote.actorOf[MyActor](host, port)service ! message
    • 44. Server-managedregister and manage actor on server client gets “dumb” proxy handle import Actor._ remote.register(“service:id”, actorOf[MyService]) server part
    • 45. Server-managed val service = remote.actorFor( “service:id”, “darkstar”, 9999) service ! message client part
    • 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. 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. Clustered Actors(in development for upcoming Akka 2.0)
    • 49. Addressval actor = actorOf[MyActor](“my-service”) Bind the actor to a virtual address
    • 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. Deployment configuration akka { actor { deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1" replicas = 3 stateless = on } } } } }
    • 52. Deployment configuration akka { Address actor { deployment { my-service { router = "least-cpu" clustered { home = "node:test-node-1" replicas = 3 stateless = on } } } } }
    • 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. 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. 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. 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. 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. 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. Upcoming features•Publish/Subscribe (broker and broker-less)•Compute Grid (MapReduce)•Data Grid (querying etc)•Distributed STM (Transactional Memory)•Event Sourcing
    • 60. Akka Node
    • 61. Akka Nodeval ping = actorOf[Ping](“ping”)val pong = actorOf[Pong](“pong”)ping ! Ball(pong)
    • 62. Akka Node val ping = actorOf[Ping](“ping”) val pong = actorOf[Pong](“pong”) ping ! Ball(pong)Ping Pong
    • 63. Akka Node AkkaCluster Node Ping Pong
    • 64. Akka Cluster Node Akka Node Akka AkkaCluster Node Cluster Node Ping Pong Akka Akka Cluster Node Cluster Node
    • 65. Akka Cluster Node Akka AkkaCluster Node Cluster Node Ping Pong Akka Akka Cluster Node Cluster Node
    • 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. 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. 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. 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. Let it crashfault-tolerance
    • 71. TheErlang model
    • 72. 9 nines
    • 73. ...let’s take astandard OO application
    • 74. Which components havecritically important state and explicit error handling?
    • 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. 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. 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. Fault-tolerantonion-layered Error Kernel
    • 79. ErrorKernel
    • 80. ErrorKernel
    • 81. ErrorKernel
    • 82. ErrorKernel
    • 83. ErrorKernel
    • 84. ErrorKernel
    • 85. ErrorKernel
    • 86. ErrorKernel
    • 87. ErrorKernel
    • 88. ErrorKernel
    • 89. ErrorKernel
    • 90. ErrorKernel
    • 91. ErrorKernel
    • 92. ErrorKernel
    • 93. ErrorKernel
    • 94. Node 1 Node 2
    • 95. Linkinglink(actor)unlink(actor)startLink(actor)spawnLink[MyActor]
    • 96. Fault handlers AllForOneStrategy( errors, maxNrOfRetries, withinTimeRange) OneForOneStrategy( errors, maxNrOfRetries, withinTimeRange)
    • 97. Supervisionclass
Supervisor
extends
Actor
{

faultHandler
=
AllForOneStrategy(



List(classOf[IllegalStateException])




5,
5000))

def
receive
=
{



case
Register(actor)
=>
link(actor)

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

    ×