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

Proto.Actor

 Proto.Actor

Introduction to Proto.Actor

Roger Johansson

February 06, 2017
Tweet

More Decks by Roger Johansson

Other Decks in Programming

Transcript

  1. Actor Model Three axioms: Send – an actor can send

    messages to other actors Create – an actor can create new actors Become – an actor can decide how to handle it’s next message ”An island of consistency in a sea of concurrency” ”Shared nothing”, ”Black box” ”Location transparent”, ”Distributable by design”
  2. OOP Actor Model Behavior Stateful Synchronous method calls Behavior Stateful

    Asynchronous message passing OOP vs. Actor Model Why Actors?? The synchronous model has worked nicely for 60 years!?
  3. Moore’s Law We can no longer build faster processors Instead,

    we stack them next to eachother and call them ”cores” 200 300 400 500 1000 1800 2530 3200 3600 2200 2930 3000 3200 3330 3330 3150 3200 3150 3150 3150 1 1 1 1 1 1 1 1 1 2 2 4 4 8 8 16 16 32 32 64 0 10 20 30 40 50 60 70 0 500 1000 1500 2000 2500 3000 3500 4000 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 MHZ and Cores per year Mhz Cores
  4. CPU

  5. Scale up and out are essentially the same That is;

    we want to execute code ”somewhere”, on a core, on a machine, in a cluster. Why should we have to resort to different technologies to accomplish the same thing?
  6. Scale up and out are essentially the same That is;

    we want to execute code ”somewhere”, on a core, on a machine, in a cluster. Why should we have to resort to different technologies to accomplish the same thing?
  7. Thread Pool Multiplex Scheduling Actor1 Actor1 Actor2 Actor2 Actor3 Actor4

    Actor4 Actor1 Cheaper than threads, no context switching Actor3 Actor4 Actor2 Actor1 Actor3 Actor2 Time
  8. A router delegates messages to other ”routee” actors Group routers

    – delegate messages to your existing actors Pool routers – delegate messages to a dedicated pool of actors Routers
  9. BroadcastRouter 1 2 1 2 1 2 1 2 Router

    Routee2 Routee3 Routee1 Notifies all ”routees”
  10. RoundRobinRouter 1 2 1 2 3 3 4 4 Router

    Routee1 Routee2 Routee3 Scale up! .. Or down!
  11. RoundRobinRouter Scale up! Routee1 Routee2 Routee3 Routee1 Routee2 Routee3 Routee1

    Routee2 Routee3 Scale out! Remote1 Remote2 Remote3 Router Router Router Router
  12. ConsistentHashRouter M Y M Y X A X A Router

    Routee1 Routee2 Routee3 Affinity between hash index and routee
  13. ConsistentHashRouter Maps hash of 123 to routee1 Id: 123 Create

    … Id: 123 Stop … Id:456 Create … Id: 789 Payment … Routee1 Routee2 Routee3 Router Id: 789 Payment … Id: 123 Stop … Id:456 Create … Id: 123 Create …
  14. Supervision Every actor is being supervised by another actor that

    dictates how failures should be handled A supervisor can decide to: • Force a restart • Terminate • Ignore and resume • Escalate up to it’s own supervisor
  15. /c2 /b2 /b1 /a1 /a2 /b3 /c3 /c4 /c5 /

    Error Kernel /c1 OneForOne supervisor AllForOne supervisor /b1 /b3
  16. DB Actor DB Query DB Result DB Up DB Query

    DB Error Poll DB Status DB Down
  17. Node A 433 Node B 24345 Node C 82327 Hash:

    989123 Node E 943772 Node D 612344 Node F 987234 Grain Id: Roger Names: Roger Names: Roger Actors: Roger : User