ted.neward@newardassociates.com | Blog: http://blogs.newardassociates.com | Github: tedneward | LinkedIn: tedneward
Our goal here is to:
Explore what a "virtual actor" is and how it works
See how Orleans implements these virtual actors
Talk about Orleans-centric distributed system design
What is it?
actors model for CLR technology stacks
"grains"
stateless or persistent
virtual actors: "always alive" semantics
open-source
https://github.com/microsoft/orleans
used on some sizable projects
Halo 4, Halo 5
Grain
Silo
Cluster
Host
"Virtual Actor": Identity + Logic + State
defined observable/"hook"able lifecycle
Single-threaded, serial message receipt
single living instance: "activation"
Objects have implicit identity (memory address)
Actors use more generalized identity
Orleans grains must have "long-lived" identity
Orleans uses one of five options for identity:
long
GUID
string
GUID + string (compound)
long + string (compound)
Grains can be entirely stateless
singletons, in essence
can allow multiple activations
Grains can hold state
state is held across lifetime of server
state can be persisted to external storage
Describes the messaging surface
uses CLR interfaces and async idioms
only type visible to clients
"IDL" for Orleans
bundle of data passed across the wire
binary format; serialized (deep copy)
actual runtime type passed (not declared type)
Orleans generates "serializers" as part of build
can be invoked await
(preserves order) or async (no ordering)
server instance/process, containing grains
manage allocation/lifecycle of grains
provides location transparency
forces "remote-first" mentality
designed to work together in a cluster
defined observable/"hook"able lifecycle
collection of silos
responsible for grain placement in Silos
random
local-to-caller (server)
hash-based
activation-count-based
configurable and customizable
process which contains the running server(s)
most often a Console, Service, or ASP.NET app
heavy use of Microsoft Hosting classes
Grains always exist
runtime activates them on demand
runtime deactivates them "later" or on request
Everything is a Task or Task-of-T
enforcing/requiring asynchronicity
Platform requirements
Microsoft .NET (.NET Core 6, 7)
... and a network
Hello, Orleans
https://github.com/tedneward/Demo-Orleans/HelloWorld
four projects:
interfaces (IDL)
implementations
client
server/host
any CLR language (most often C#)
Interfaces
ClassLibrary
requires
Microsoft.Orleans.Core.Abstractions
Microsoft.Orleans.CodeGenerator.MSBuild
IHelloWorld
public interface IHelloWorld : Orleans.IGrainWithIntegerKey { Task<string> SayHello(string name); }
Grains (implementations)
ClassLibrary
requires
Microsoft.Orleans.Core.Abstractions
Microsoft.Orleans.CodeGenerator.MSBuild
Interfaces
HelloWorld
public class HelloWorld : Orleans.Grain, IHelloWorld { private readonly ILogger _logger; public HelloWorld(ILogger<HelloWorld> logger) { _logger = logger; } public Task<string> SayHello(string name) { _logger.LogInformation("SayHello: name = '{name}', ", name); return Task.FromResult($"Hello, {name}, welcome to Orleans"); } }
Host
Console
requires
Microsoft.Orleans.Server
(Microsoft.Extensions.Hosting)
(Microsoft.Extensions.Logging.Console)
Interfaces
Grains
Program.cs
var builder = new HostBuilder() .UseOrleans(c => { c.UseLocalhostClustering() .Configure<ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "HelloWorld"; }) .ConfigureApplicationParts( parts => parts.AddApplicationPart(typeof(HelloWorld).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()); }); var host = builder.Build(); await host.StartAsync();
Client
Console
requires
Microsoft.Orleans.Client
Interfaces
Client Setup
var client = new ClientBuilder() .UseLocalhostClustering() .Configure<ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "HelloWorld"; }) .ConfigureLogging(logging => logging.AddConsole()) .Build(); await client.Connect(); Console.WriteLine("Client successfully connected to silo host \n");
Client calling host
var friend = client.GetGrain<IHelloWorld>(0); var response = await friend.SayHello("Good morning, HelloGrain!");
must extend an "identity interface"
describes the kind of primary key
IGrainWithGuidKey
IGrainWithIntegerKey
IGrainWithStringKey
IGrainWithGuidCompoundKey
IGrainWithIntegerCompoundKey
methods must return Task
must implement grain interface
must extend Orleans.Grain
base class
optionally override OnActivateAsync
/OnDeactivateAsync
for notification of activation/deactivation
exceptions will cancel activation
deactivation is not guaranteed (e.g., server crash)
primary key available via GetPrimaryKey
grains are never accessed directly
clients must obtain a "grain reference"
pass identity to GrainFactory.GetGrain
references can be used as typical .NET objects
Persistent grains
Timers and reminders
Streams
Heterogenous Silos
Evolving/versioning Grains
Event sourcing
Transactions
virtual actor system
built on top of CLR
providing easy language-to-messaging syntax/semantics
capable of supporting high scale/load
Orleans OSS repository
https://github.com/dotnet/orleans
Official docs
https://learn.microsoft.com/en-us/dotnet/orleans/
OrleansContrib
https://github.com/orgs/OrleansContrib
Awesome-Orleans
https://github.com/OrleansContrib/Awesome-Orleans
"Introducing Microsoft Orleans"
https://www.amazon.com/Introducing-Microsoft-Orleans-Implementing-Cloud-Native/dp/148428013X
"Microsoft Orleans for Developers"
https://www.amazon.com/Microsoft-Orleans-Developers-Cloud-Native-Distributed/dp/1484281667
"Distributed .NET w/Microsoft Orleans"
https://www.amazon.com/Distributed-NET-Microsoft-Orleans-applications-ebook/dp/B09NPBDQSL
Architect, Engineering Manager/Leader, "force multiplier"
http://www.newardassociates.com
http://blogs.newardassociates.com
Sr Distinguished Engineer, Capital One
Educative (http://educative.io) Author
Performance Management for Engineering Managers
Books
Developer Relations Activity Patterns (w/Woodruff, et al; APress, forthcoming)
Professional F# 2.0 (w/Erickson, et al; Wrox, 2010)
Effective Enterprise Java (Addison-Wesley, 2004)
SSCLI Essentials (w/Stutz, et al; OReilly, 2003)
Server-Based Java Programming (Manning, 2000)