Share
Embed
Distributed Akka talk
Slides from my talk at the Cross Functional Amsterdam meetup
Raymond Roestenburg
August 29, 2013
Transcript
50 slides
-
My “Am I going to use this?” rules Must be
open source. The code quality must be excellent. Must be able to test ‘everything’ relatively easily. Docs must be comprehensive. Must have examples. The creators / community must have social skills. Pull request litmus test. Friday, October 11, 13 -
Actor Model message passing safely mutate state create send/receive become
Friday, October 11, 13 -
Akka Actors Stable IDs (ActorRef) Message ordering sender / receiver
pair Configurable Dispatchers ActorSystems ActorPaths Parental Supervision Friday, October 11, 13 -
JVM Shared heap (no preemption) Immutability not enforced Reuse Java
libraries Performance Friday, October 11, 13 -
master worker “user” guardian path from worker to worker1: ../worker1
loadgen worker1 Friday, October 11, 13 -
master worker “user” guardian Guardian is parent of master, master
parent of worker. loadgen Friday, October 11, 13 -
master worker “user” guardian Guardian supervises master, master supervises of
worker. loadgen Friday, October 11, 13 -
master worker “user” guardian Stop / Resume / Escalate /
Restart loadgen Friday, October 11, 13 -
master worker1 “user” guardian akka.tcp://loadgen@host:port/user/master/worker loadgen akka.tcp Java Serialization By
Default (Other Options) Friday, October 11, 13 -
Static vs Dynamic (a,b,c) (x) (x) (x) c b d
join a leave x a b c Friday, October 11, 13 -
(a,b,c) (x) (x) (x) x a b c Static membership
pre-configured nodes Startup sequence? restart after failure? Friday, October 11, 13 -
master worker loadgen user runner loadrun /user/runner/master/worker Remote Deployment user
/runner/master/worker { remote = "akka.tcp://loadgen@host:port" } Friday, October 11, 13 -
master worker loadgen user runner loadrun /user/runner/master/worker user /scenario/master/worker {
remote = "akka.tcp://loadgen@host:2552" } What if loadgen node is not up? Friday, October 11, 13 -
val future = context.actorSelection(path) .resolveOne future.map( aRef => aRef !
msg).recover { case ActorNotFound(selection) => //ouch } Friday, October 11, 13 -
identify active lookup runner master worker In between lookup actor
identifies remote actor Friday, October 11, 13 -
def receive = identify def identify:Receive = { // do
identification of ActorRef } def active(actor:ActorRef) : Receive = { // forward messages when active // or become(identify) when actor is terminated } Lookup Actor Friday, October 11, 13 -
context.setReceiveTimeout(timeout) sendIdentifyRequest() def identify:Receive = { case ReceiveTimeout => sendIdentifyRequest
// .. more to follow } def sendIdentifyRequest(): Unit = { val selection = context.actorSelection(path) selection ! Identify(path) } Friday, October 11, 13 -
def identify: Receive = { case ActorIdentity(`path`, Some(actor)) => context.setReceiveTimeout(Undefined)
context.become(active(actor)) context.watch(actor) case ActorIdentity(`path`, None) => // not found case ReceiveTimeout => sendIdentifyRequest() case msg:Any => // ignore } Friday, October 11, 13 -
def active(actor: ActorRef): Receive = { case Terminated(actorRef) => context.become(identify)
context.setReceiveTimeout(3 seconds) sendIdentifyRequest() case msg:Any => actor forward msg } Friday, October 11, 13 -
deploying maybe active deploy runner master worker Similar for RemoteDeploy
Friday, October 11, 13 -
def receive = deploying def deploying:Receive = { case ReceiveTimeout
=> deployAndWatch() case msg:Any => // ignore } def maybeActive(actor:ActorRef): Receive = { case Terminated(actorRef) => context.become(deploying) context.setReceiveTimeout(3 seconds) deployAndWatch() case msg:Any => actor forward msg } Similar for a RemoteDeploy Friday, October 11, 13 -
Seed nodes • initial contact points, joins automatically • no
seed nodes: join programmatically or through cluster admin • bin/akka-cluster <node-hostname> <jmx- port> <command> Friday, October 11, 13 -
val cluster = Cluster(actorSystem) cluster.join(address) cluster.leave(address) Cluster(system).subscribe(clusterListener, classOf[MemberUp]) (watch also
works as expected) Programmatically join and leave Friday, October 11, 13 -
akka { actor { provider = "akka.cluster.ClusterActorRefProvider" } cluster {
seed-nodes = [ "akka.tcp://[email protected]:2551"] roles = ["loadrun", “loadgen”] auto-down = on } } Friday, October 11, 13 -
def createWorkerRef:ActorRef = { import ConsistentHashingRouter._ def hashMapping: ConsistentHashMapping =
{ case DoWork(id, _) 㱺 id } clusterRouterConfig = ClusterRouterConfig(ConsistentHashingRouter( hashMapping = hashMapping, nrOfInstances = 1000) routerSettings = ClusterRouterSettings(10000,"/user/boxOffice",false,Some("boxOffice")))) context.actorOf(Props[Worker].withRouter(clusterRouterConfig, routerSettings) } Create a Consistently hashed worker Friday, October 11, 13 -
Remote DeathWatch Cluster Death Watch Supervision of Remotely deployed actors
Friday, October 11, 13 -
context.watch(actor) def receive = { case Terminated(`ref`) => //take action
} Friday, October 11, 13