Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Actor Model in .NET:
Akka.NET vs Microsoft Orleans
for the curious
William Tulloch
Lead Consultant – Readify
@wtulloch
Preamble
Concurrency and distributed applications
What is the Actor Model?
The Model of Actor Model
A way of reasoning about concurrent computation
What is the Actor Model
A way of reasoning about concurrent computation
Is inherently concurrent
The Model of Actor Model
Is a conceptual model for reasoning about concurrent
computation
Is inherently concurrent
Manages...
The Model of Actor Model
Is a conceptual model for reasoning about concurrent
computation
Adopts the philosophy that every...
What is an Actor?
Lightweight
Never shares state
Communicates through asynchronous
messages
Has a mailbox to buffer messag...
An Actor Can not exist on its own
Microsoft Orleans
&
Akka.NET
The overview
Akka.NET
• A port of Java/Scala Akka
• Open source
• Task Parallel Library
• Reactive methodology
• Can be ru...
The overview
Orleans
• Started by Microsoft Research
• Open source
• Task Parallel Library
• Reactive methodology
• Cloud-...
Orleans versus Akka.NET
Hosting Actors
Image from Halo Orleans at build 2104
Orleans - SiloAkka - ActorSystem
Hosting Actors
Image from Halo Orleans at build 2104
Orleans - SiloAkka - ActorSystem
Actors versus Grains
Orleans: An Actor is Grain
Grain instances always exist virtually
Orleans: An Actor is Grain
Grain instances always exist virtually
Are created on demand
Orleans: An Actor is Grain
Grain instances always exist virtually
Are created on demand
Are location transparent
Orleans: An Actor is Grain
Grain instances always exist virtually
Are created on demand
Are location transparent
Every gra...
Akka.NET: An Actor is Actor
Must be explicitly created and stopped
Akka.NET: An Actor is Actor
Must be explicitly created and stopped
Are created in the context of their parent
Akka.NET: An Actor is Actor
Must be explicitly created and stopped
Are created in the context of their parent
Exposes a se...
Akka.NET: An Actor is Actor
Must be explicitly created and stopped
Are created in the context of their parent
Exposes a se...
Creating grains and actors
Creating a grain
Orleans – creating a grain
• In Visual Studio create two projects
• One for your grain interfaces
• One for your grain imp...
Create a Grain interface
public interface IHelloWorld : IGrainWithIntegerKey
{
Task Greeting(string name);
Task<string> Re...
Create an implementation of the interface
public class HelloWorldGrain : Grain, IHelloWorld
{
public Task Greeting(string ...
Interacting with Grains
static async Task SendMessage(User user )
{
var helloWorld = GrainClient.GrainFactory.GetGrain<IHe...
Creating an Actor
Akka.Net – creating an actor
• In Visual Studio:
• Create a new class library
• Create a console application
• Import the ...
Create message
public class HelloUserMessage
{
public User User { get; }
public HelloUserMessage(User user)
{
User = user;...
Create an actor
public class HelloWorldActor : ReceiveActor
{
private TimeSpan _waitPeriod;
public HelloWorldActor(TimeSpa...
Using the actor
var system = ActorSystem.Create("demo")
var helloWorld = system.ActorOf(Props.Create(() => new HelloWorldA...
Demo Hello World
Messages and Serialisation
Messages and Serialisation
public class UserMessage
{
public string FirstName { get;}
public string LastName { get;}
publi...
Messages and serialisation
Task<string> Greeting(string firstName, string lastName);
Task<Immutable<byte[]>> ProcessReques...
Messages and Serialisation
[Immutable]
public class User
{
public string FirstName { get;}
public string LastName { get;}
}
Bits and Pieces
“let it crash” and exception handling
Persisting state
Changing behaviour
Grains for everyone
Routing in A...
Summing up
Resources
Akka.NET
Akka.NET home: http://getakka.net/
Bootcamp: https://github.com/petabridge/akka-bootcamp
Orleans
Orlean...
Akka.net versus microsoft orleans
Upcoming SlideShare
Loading in …5
×

Akka.net versus microsoft orleans

5,764 views

Published on

Slides from my talk at DDD Melbourne 2016 on a comparative overview of Akka.NET and Microsoft Orleans

Published in: Technology
  • Be the first to comment

Akka.net versus microsoft orleans

  1. 1. Actor Model in .NET: Akka.NET vs Microsoft Orleans for the curious William Tulloch Lead Consultant – Readify @wtulloch
  2. 2. Preamble Concurrency and distributed applications
  3. 3. What is the Actor Model?
  4. 4. The Model of Actor Model A way of reasoning about concurrent computation
  5. 5. What is the Actor Model A way of reasoning about concurrent computation Is inherently concurrent
  6. 6. The Model of Actor Model Is a conceptual model for reasoning about concurrent computation Is inherently concurrent Manages concurrency through message passing
  7. 7. The Model of Actor Model Is a conceptual model for reasoning about concurrent computation Adopts the philosophy that everything is an actor Is inherently concurrent Manages concurrency through message passing
  8. 8. What is an Actor? Lightweight Never shares state Communicates through asynchronous messages Has a mailbox to buffer messages Processes one message at a time Is a single-thread object
  9. 9. An Actor Can not exist on its own
  10. 10. Microsoft Orleans & Akka.NET
  11. 11. The overview Akka.NET • A port of Java/Scala Akka • Open source • Task Parallel Library • Reactive methodology • Can be run within an application, on-prem or in the cloud(?)
  12. 12. The overview Orleans • Started by Microsoft Research • Open source • Task Parallel Library • Reactive methodology • Cloud-native Akka.NET • A port of Java/Scala Akka • Open source • Task Parallel Library • Reactive methodology • Can be run within an application, on- prem or in the cloud(?)
  13. 13. Orleans versus Akka.NET
  14. 14. Hosting Actors Image from Halo Orleans at build 2104 Orleans - SiloAkka - ActorSystem
  15. 15. Hosting Actors Image from Halo Orleans at build 2104 Orleans - SiloAkka - ActorSystem
  16. 16. Actors versus Grains
  17. 17. Orleans: An Actor is Grain Grain instances always exist virtually
  18. 18. Orleans: An Actor is Grain Grain instances always exist virtually Are created on demand
  19. 19. Orleans: An Actor is Grain Grain instances always exist virtually Are created on demand Are location transparent
  20. 20. Orleans: An Actor is Grain Grain instances always exist virtually Are created on demand Are location transparent Every grain must have an Id
  21. 21. Akka.NET: An Actor is Actor Must be explicitly created and stopped
  22. 22. Akka.NET: An Actor is Actor Must be explicitly created and stopped Are created in the context of their parent
  23. 23. Akka.NET: An Actor is Actor Must be explicitly created and stopped Are created in the context of their parent Exposes a set of life-cycle hooks
  24. 24. Akka.NET: An Actor is Actor Must be explicitly created and stopped Are created in the context of their parent Exposes a set of life-cycle hooks Are location transparent akka.tcp://Demo@127.0.0.1:12345/user/HelloWorld/$c
  25. 25. Creating grains and actors
  26. 26. Creating a grain
  27. 27. Orleans – creating a grain • In Visual Studio create two projects • One for your grain interfaces • One for your grain implementations • In both projects install the NuGet package Microsoft.Orleans.OrleansCodeGenerator.build
  28. 28. Create a Grain interface public interface IHelloWorld : IGrainWithIntegerKey { Task Greeting(string name); Task<string> ReturnGreeting(string name); } Must implement one of the following: • IGrainWithIntegerKey • IGrainWithGuidKey • IGrainWithStringKey • IGrainWithIntegerCompoundKey • IGrainWithGuidCompoundKey
  29. 29. Create an implementation of the interface public class HelloWorldGrain : Grain, IHelloWorld { public Task Greeting(string name) { Console.WriteLine($"Hi {name} from Orleans"); return TaskDone.Done; } public Task<string> ReturnGreeting(string name) { return Task.FromResult($"Hi {name} from Orleans"); } }
  30. 30. Interacting with Grains static async Task SendMessage(User user ) { var helloWorld = GrainClient.GrainFactory.GetGrain<IHelloWorld>(0); var response = await helloWorld.Greeting(user); WriteLine(response); }
  31. 31. Creating an Actor
  32. 32. Akka.Net – creating an actor • In Visual Studio: • Create a new class library • Create a console application • Import the core Akka.NET Nuget package: Akka
  33. 33. Create message public class HelloUserMessage { public User User { get; } public HelloUserMessage(User user) { User = user; } }
  34. 34. Create an actor public class HelloWorldActor : ReceiveActor { private TimeSpan _waitPeriod; public HelloWorldActor(TimeSpan waitPeriod) { _waitPeriod = waitPeriod; Receive<HelloUserMessage>(m => { var user = m.User; Thread.Sleep(_waitPeriod); WriteLine($"Hi {user.Id} {user.FirstName} nice to meet you [on thread "); }); Receive<DataCompleted>(m => WriteLine("Data is completed")); }
  35. 35. Using the actor var system = ActorSystem.Create("demo") var helloWorld = system.ActorOf(Props.Create(() => new HelloWorldActor())); helloWorld.Tell(new HelloUserMessage(new User()); await system.Terminate();
  36. 36. Demo Hello World
  37. 37. Messages and Serialisation
  38. 38. Messages and Serialisation public class UserMessage { public string FirstName { get;} public string LastName { get;} public UserMessage(string firstName, string lastName) { FirstName = firstName; LastName = lastName; } }
  39. 39. Messages and serialisation Task<string> Greeting(string firstName, string lastName); Task<Immutable<byte[]>> ProcessRequest(Immutable<byte[]> request);
  40. 40. Messages and Serialisation [Immutable] public class User { public string FirstName { get;} public string LastName { get;} }
  41. 41. Bits and Pieces “let it crash” and exception handling Persisting state Changing behaviour Grains for everyone Routing in Akka.NET Clustering in Akka.NET
  42. 42. Summing up
  43. 43. Resources Akka.NET Akka.NET home: http://getakka.net/ Bootcamp: https://github.com/petabridge/akka-bootcamp Orleans Orleans Home: http://dotnet.github.io/orleans/ Halo-Orleans: https://channel9.msdn.com/Events/Build/2014/3-641 Comparing Akka.NET and Orleans: https://github.com/akka/akka- meta/blob/master/ComparisonWithOrleans.md

×