Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Distributed Akka talk

Distributed Akka talk

Slides from my talk at the Cross Functional Amsterdam meetup

Raymond Roestenburg

August 29, 2013
Tweet

More Decks by Raymond Roestenburg

Other Decks in Programming

Transcript

  1. 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
  2. Akka Actors Stable IDs (ActorRef) Message ordering sender / receiver

    pair Configurable Dispatchers ActorSystems ActorPaths Parental Supervision Friday, October 11, 13
  3. JVM Shared heap (no preemption) Immutability not enforced Reuse Java

    libraries Performance Friday, October 11, 13
  4. master worker “user” guardian Guardian is parent of master, master

    parent of worker. loadgen Friday, October 11, 13
  5. master worker “user” guardian Stop / Resume / Escalate /

    Restart loadgen Friday, October 11, 13
  6. Static vs Dynamic (a,b,c) (x) (x) (x) c b d

    join a leave x a b c Friday, October 11, 13
  7. (a,b,c) (x) (x) (x) x a b c Static membership

    pre-configured nodes Startup sequence? restart after failure? Friday, October 11, 13
  8. 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
  9. 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
  10. val future = context.actorSelection(path) .resolveOne future.map( aRef => aRef !

    msg).recover { case ActorNotFound(selection) => //ouch } Friday, October 11, 13
  11. identify active lookup runner master worker In between lookup actor

    identifies remote actor Friday, October 11, 13
  12. 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
  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
  14. 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
  15. 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
  16. 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
  17. 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
  18. akka { actor { provider = "akka.cluster.ClusterActorRefProvider" } cluster {

    seed-nodes = [ "akka.tcp://[email protected]:2551"] roles = ["loadrun", “loadgen”] auto-down = on } } Friday, October 11, 13
  19. 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