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

Actor Frameworks in .NET

Actor Frameworks in .NET

The actor model is a novel approach to writing concurrent software. It is based on the concept of small computational units communicating through asynchronous message passing, thus allowing concurrency and scalability while negating a lot of the problems of concurrent programming.

The actor model has been gaining adoption with the Erlang language and the Akka framework for JVM languages. But up until now, the .NET landscape lacked a truly robust and production ready actor framework. This changed dramatically this year with the release of not one but two open-source actor frameworks for .NET - Akka.NET (a port of the JVM Akka), and Orleans by Microsoft.

Presented at the Gigya Meetup group, June 2015.

Ed52a75c8cf2f4cb1c2e9d8d161ca771?s=128

Rotem Hermon

June 03, 2015
Tweet

Transcript

  1. Rotem Hermon Actor Frameworks in .NET

  2. Not THAT kind of actors.

  3. The problem with multi-threaded concurrency • Shared memory and state

    • Locks and deadlocks • Race conditions • Blocking calls • Not easily distributed • Hard to understand and maintain
  4. Threads are EVIL!

  5. The Actor Model • Formalized in 1973 (Carl Hewitt) •

    Concurrency by Message Passing • Avoids problems of threading and locking
  6. An Actor, Carl Hewitt definition • The fundamental unit of

    computation that embodies: • Processing • Storage • Communication • An actor can: • Create new Actors • Send messages to Actors • Designate how to handle the next message
  7. An Actor • Lightweight • Never shares state • Communicates

    through asynchronous messages • Mailbox buffers incoming messages • Processes one message at a time • Single threaded
  8. (Actors are actually Nanoservices)

  9. The Actor Model • Simpler concurrent programming model • Higher

    abstraction level • Write single-threaded code (easier to understand) • Scale via actor instances • Maximize CPU utilization • Easy to distribute
  10. Leading Actor Implementations • Erlang • Developed in the late

    90s by Ericsson for HA telecom exchanges • Actors are a core language feature • Akka • A JVM (Scala/Java) Actor framework library • Started by Jonas Bonér in 2009 • Became part of Typesafe (company behind Scala)
  11. Actors in .NET Before 2015

  12. Actors in .NET After 2015

  13. Akka.NET MS Orleans

  14. Akka.NET • A port of Akka to .NET. • Started

    Jan 2014 by Roger Alsing and Aaron Stannard • V1.0 – March 2015 • Some modules still in beta (Persistence, Clustering) • Founded Petabridge as an OS company behind Akka.NET (cooperating with Typesafe)
  15. Akka.NET Fundamentals Actors Contains: • State • Behavior • An

    actor can “switch” its internal behavior • Mailbox • Several types of mailboxes • Children • An actor is “responsible” for other actors it creates - Supervisor
  16. Akka.NET Fundamentals • Actors form an hierarchical structure • Actor

    Lifecycle • Actors needs to be created and destroyed • Fault handling is done via supervision hierarchies • Several available supervision strategies • Location Transparency • Actors can be created remotely • Actors are called via an actor reference, same for local and remote • Akka Clustering for additional features
  17. Akka.NET Fundamentals • Dispatchers • Schedules the message delivery to

    actors (code execution) • Can be shared across actors • Several types of dispatchers and configurations • Routers • An actor that routes messages to other actors • Several routing strategies
  18. None
  19. Orleans • A project by Microsoft Research • Started at

    2011, in production since 2012 • Serving high scale Microsoft services on Azure (Halo 4 cloud services) • Open sourced in January 2015
  20. Orleans • Project goal: a simplified Actors implementation to make

    distributed application programming easier • Prefer developer productivity and transparent scalability • Provides a higher abstraction level for actors: Virtual Actors
  21. Orleans – Virtual Actors • A virtual “actor space”, analogues

    to virtual memory • An Actor “always exists” • Orleans runtime handles Actor placement, activation and GC when needed • Orleans balances resources across the cluster, provides elastic scalability
  22. Orleans – Programming Model • An Actor is a .NET

    class, implementing an interface with asynchronous methods • Orleans uses code generation to create Actor proxies • The caller of an Actor uses the actor interface via the proxy • Messaging is transparent and handled by Orleans. Programmers deal with interfaces and methods
  23. Orleans (Virtual Actors) • Focus on simplicity and productivity •

    Implicit lifecycle, handled by runtime • Automatic clustering and load balancing • Actor interfaces are regular interfaces (standard OOP) • No hierarchy, all actors are directly accessible Akka (Classic Actors) • Provide full power (exposing complexity) • Explicit lifecycle, handled by programmer • Clustering and load balancing available (but more complex) • Actors communicates via explicit message classes • Actors are ordered in hierarchies and accessible by path
  24. None
  25. Orleans or Akka ? • Choose Akka if • Need

    full power – complex topologies, fine grain failure handling, dynamic changing of behavior, explicit message handling • Experienced development team • Choose Orleans if • Need a simple model for distributed applications • Automatic and straightforward scaling • Development team with varied levels of experience
  26. Thank You! We’re hiring! http://gigya.com/careers/ Rotem Hermon VP Architecture @

    Gigya