A short and sweet introduction to Microsoft Orleans - https://dotnet.github.io/orleans/ - OSS actor programming framework from Microsoft Research. As presented in Alt.Net Israel (http://altnet.azurewebsites.net/) meeting group, Dec 2016.
1. A BRIEF INTRO TO
MICROSOFT
ORLEANS
URI GOLDSTEIN / @URIG / HTTP://URIG.IO/
Alt.Net Israel
2. MICROSOFT ORLEANS
A framework for building distributed
applications
• Made by Microsoft Research
• Free and Open Source (MIT License)
• Production Ready (Halo 4, Azure Service Fabric)
3. TWO GOALS
• Simple Distributed
Programming
• Scalable by Default
• The Actor Model of
Programming
4. ACTOR PROGRAMMING MODEL
• An Actor is “Unit of Computation” that upon receiving a
Message:
• Can send Messages to other Actors.
• Can Create new Actors.
• Designates the behavior to be used
for the next Message it receives.
State +
Logic
5. ACTORS
• Encapsulate State and Logic
• Run Concurrently
• Communicate Asynchronously
Via Message Passing
• Addressable
(Addresses can go in Messages)
7. ORLEANS: GRAIN = VIRTUAL ACTOR
• Grains are C# Classes
• Derived from GrainBase
• Implement an Interface (ex: IUser or IConversation)
• Messages Passing = Calling Interface Methods
• Ex: SendMessageToMembers(string text)
• Can be Stateless or Stateful
8. GRAIN EXAMPLE
public class ConversationGrain : Grain, IConversation
{
// State
private string AdminId;
private IEnumberable<IUserGrain> Members;
// Receive messages
public async Task SendMessageToAdmin(string message)
{
// Send a message
var admin = GrainFactory.GetGrain<IUserGrain>(AdminId);
await admin.GetMessage(message);
}
//...
}
9. GRAIN LIFECYCLE
• Managed by Silos and Clusters
• Grains always exist
• Can be Active / Inactive
• Garbage Collected
• Single instance if Statefull
• Many instances if Stateless Orleans Cluster
Silo Silo Silo
10. GRAIN COMMUNICATION
• Messages = Method Calls
• Method Calls are Queued
• Grains are Single Threaded
• Addresses are C# References
• Location is Transparent
var grain = GrainFactory
.GetGrain<IUserGrain>("Uri");
await grain.SayHello("World");
11. GRAIN PERSISTENCE
Choose:
• No State (Think functional!)
• Transient State: In Memory
• Persistent State:
• Azure Table Storage
• Shared ATS
• Roll your own
• Configurable per Grain
• Implicitly Read upon Activation
• Explicitly Written by Grain
Logic
• Storage Provider in charge of
Serialization
12. DEPLOYMENT
• Silos are self hosting
• So Clusters run anywhere Windows can
Ex: Azure Cloud Services (Worker Roles)
• Server to Server over TCP
• Entry point is GrainClient
• Message Passing (Method Call), or
• Observer Pattren (Pub/Sub)
Orleans
Client
Orleans
Cluster
Interface
s
15. THANK YOU
• Orleans website
http://dotnet.github.io/orleans
• Orleans on GitHub
https://github.com/dotnet/orle
ans
• 30 min intro from Carl Hewitt
who invented the Actor Model
http://tinyurl.com/CarlHewitt
•Ask me anything:
Uri Goldstein
twitter.com/urig
http://urig.io/