a brief intro to microsoft orleans
TRANSCRIPT
A BRIEF INTRO TO MICROSOFT ORLEANSURI GOLDSTEIN / @URIG / HTTP://URIG.IO/
Alt.Net Israel
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)
TWO GOALS
• Simple Distributed Programming
• Scalable by Default
• The Actor Model of Programming
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
ACTORS
• Encapsulate State and Logic• Run Concurrently• Communicate AsynchronouslyVia Message Passing• Addressable (Addresses can go in Messages)
SOMEWHAT CONTRIVED EXAMPLE
Uri
WhatsAppGroup
Shay
Boris
“Hello”
Uri: “Hello”Uri: “Hello”
“Wanna hear a secret?”
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
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); } //...}
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
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");
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
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)
OrleansClient
OrleansCluster
Interfaces
SAMPLE ARCHITECTURE
Orleans Cluster(Azure Cloud Service)
Silo Silo SiloAzure Table
Storage
Shard
asp.net Web API
Shard
Shard
Request
Request
SAMPLE ARCHITECTURE
Orleans Cluster(Azure Cloud Service)
Silo Silo SiloAzure Table
Storage
Shard
asp.net Web API
Shard
Shard
Request
Request
THANK YOU
• Orleans websitehttp://dotnet.github.io/orleans• Orleans on GitHub
https://github.com/dotnet/orleans• 30 min intro from Carl
Hewitt who invented the Actor Modelhttp://tinyurl.com/CarlHewitt
•Ask me anything:Uri Goldsteintwitter.com/urighttp://urig.io/