a brief intro to microsoft orleans

15
A BRIEF INTRO TO MICROSOFT ORLEANS URI GOLDSTEIN / @URIG / HTTP://URIG.IO/ Alt.Net Israel

Upload: uri-goldstein

Post on 06-Apr-2017

154 views

Category:

Software


6 download

TRANSCRIPT

Page 1: A Brief Intro to Microsoft Orleans

A BRIEF INTRO TO MICROSOFT ORLEANSURI GOLDSTEIN / @URIG / HTTP://URIG.IO/

Alt.Net Israel

Page 2: A Brief Intro to Microsoft Orleans

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)

Page 3: A Brief Intro to Microsoft Orleans

TWO GOALS

• Simple Distributed Programming

• Scalable by Default

• The Actor Model of Programming

Page 4: A Brief Intro to Microsoft Orleans

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

Page 5: A Brief Intro to Microsoft Orleans

ACTORS

• Encapsulate State and Logic• Run Concurrently• Communicate AsynchronouslyVia Message Passing• Addressable (Addresses can go in Messages)

Page 6: A Brief Intro to Microsoft Orleans

SOMEWHAT CONTRIVED EXAMPLE

Uri

WhatsAppGroup

Shay

Boris

“Hello”

Uri: “Hello”Uri: “Hello”

“Wanna hear a secret?”

Page 7: A Brief Intro to Microsoft Orleans

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

Page 8: A Brief Intro to Microsoft Orleans

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); } //...}

Page 9: A Brief Intro to Microsoft Orleans

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

Page 10: A Brief Intro to Microsoft Orleans

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");

Page 11: A Brief Intro to Microsoft Orleans

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

Page 12: A Brief Intro to Microsoft Orleans

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

Page 13: A Brief Intro to Microsoft Orleans

SAMPLE ARCHITECTURE

Orleans Cluster(Azure Cloud Service)

Silo Silo SiloAzure Table

Storage

Shard

asp.net Web API

Shard

Shard

Request

Request

Page 14: A Brief Intro to Microsoft Orleans

SAMPLE ARCHITECTURE

Orleans Cluster(Azure Cloud Service)

Silo Silo SiloAzure Table

Storage

Shard

asp.net Web API

Shard

Shard

Request

Request

Page 15: A Brief Intro to Microsoft Orleans

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/