5. RMI, EJB, CORBA, SOAP,
XML-RPC, Thrift
are easy, but ultimately
flawed!
Fail under network
partitioning and partial
failure...
6. RMI, EJB, CORBA, SOAP,
XML-RPC
are easy, but ultimately
flawed!
It’s time for RPC to retire.
Fail under network
partitioning and partial Steve Vinovsky
failure...
7. RMI, EJB, CORBA, SOAP, Akka*
XML-RPC
Simple toolkit for building
are easy, but ultimately distributed, scalable,
flawed! fault-tolerant systems
Fail under network • actors / transactors
partitioning and partial • supervisors
failure... • routing and dispatching
• STM for better shared
stated concurrency
• much more…
8. class HelloWorldActor extends Actor {
def receive = {
case msg => self reply (msg + " World")
}
}
LocalActorRef
val myActor = actorOf[HelloWorldActor].start()
val result = myActor !! “message”
9. Dispatcher stuffs actor[-s] with messages
class ActorA extends Actor {
self.dispatcher = someDispatcher
...
}
class ActorB extends Actor {
self.dispatcher = someDispatcher
...
}
13. remote.start("localhost", 9999).register(
"hello-service", actorOf[HelloWorldActor])
RemoteActorRef
val actor = remote.actorFor(
"hello-service", "localhost", 9999)
val result = actor !! "Hello"
14. Moreover, there could be a pool of
actors behind the ActorRef
class MyLoadBalancer extends Actor with LoadBalancer {
val pinger = actorOf(new Actor {
def receive = { case x => println("Pinger: " + x) } }).start()
val ponger = actorOf(new Actor {
def receive = { case x => println("Ponger: " + x) } }).start()
val seq = new CyclicIterator[ActorRef](List(pinger,ponger))
}
15. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
16. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
17. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
18. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
19. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
20. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
21. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
22. Fault tolerance
Groups of linked, supervised actors define subsystems:
those actors crash and restart together
30. [behind the scenes]
actor clustering
get deployment config
is scope
LocalActorRef
local?
Distributed Registry add to local actor registry
store serilized actor
factory in ZooKeeper
create create actor on
actor node
ClusteredActorRef / RoutedActorRef
ZooKeeper is used for storing
cluster configs, serialized actor
factories, metrics, etc.
40. Composable Futures
val future1 = for {
a <- (actor ? message1).mapTo[String]
b <- (actor ? message2).mapTo[String]
} yield a + b
val future2 = (actor ? Message3).map(_.toString)
val future3 = Futures.find[String](_.isEmpty)(
Seq(future1, future2))
41. BONUS: multi-jvm testing with
scalatest in specs2
https://github.com/typesafehub/sbt-multi-jvm
https://github.com/jboner/akka/tree/master/akk
a-cluster/src/multi-jvm
https://github.com/remeniuk/sbt-multi-jvm
42. GO AND TRY IT!
> git clone https://github.com/jboner/akka
> sbt