Gökhan Gökalp
Software Architect, Blog writer. If you free your mind, you free your code.
Gökhan GÖKALP
29.06.2018
Devnot Yazılımcı Buluşmaları
Gökhan GÖKALP
Software Architect
http://www.gokhan-gokalp.com
E-mail: gok.gokalp@yahoo.com
LinkedIn: in/gokgokalp
Twitter: @gokgokalp
"Message passing" the key point
Concurrent
Parallel
Concurrent & parallel, huh?
Actors have mailboxes
What do they do?
Debugging, tracing, testing could be hard.
An example
We can think actors as a group of people. Everyone has some functionality and independent of each other. They are communicating with each other via emails.
What do they do?
An example
Student sends an email to the teacher of him and email is immutable. (non-blocking operation) The teacher checks her mailbox at any time.
What do they do?
When?
Published 1970s
Erlang 1980s (fault-tolerant)
Orleans is a framework that provides a straightforward approach to building distributed "cloud-based" high scale computing applications without thinking "concurrency" issues.
Virtual Actor Model Abstraction (concurrency & high scalability)
No need to learn:
Microsoft research
Open-sourced, January 2015
Microsoft research
In OOP, we encapsulating states of objects. Also, it's easy to be able to do stateful operations. (shared memory)
but, in distributed stateless world :(
shared memory, encapsulating? :(
but, in orleans project;
It's possible to build a distributed environment that behaves like single shared memory, encapsulates states and can scale with "low latency".
I love in memory...
Orleans Concepts
Orleans works in silos in each machine. In silos, grains are activated.
If silo failure, its grains are reactivated at other silos.
Orleans Concepts
real-time things during high loads, huh?
Orleans Concepts - Grains
Grain lifecycle management runs at runtime transparently.
Orleans Concepts - Silo
Core Features
Core Features - Streams
Scenarios
Deployment
Monitoring
Orleans output its runtime statistics and metrics through the ITelemetryConsumer interface.
Design Grain Interface
Development with
Grains interact with each other by invoking methods declared as part of the respective grain interfaces.
public interface IMyGrain : IGrainWithIntegerKey
{
Task<string> SayHello(string name);
}
Implement Grain Interface
Development with
public class MyGrain : Grain, IMyGrain
{
public Task<string> SayHello(string name)
{
return Task.FromResult($"Hello {name}");
}
}
Accessing a Grain
var helloGrain = client.GetGrain<IMyGrain>(1); //Called grain activation
await helloGrain.SayHello("Gökhan");
Grain Persistance
Development with
[StorageProvider(ProviderName="store1")]
public class MyGrain : Grain<MyGrainState>, IMyGrain
{
public Task<string> SayHello(string name)
{
return Task.FromResult($"Hello {name}");
}
}
<StorageProviders>
<Provider Type="Orleans.Storage.MemoryStorage" Name="devStore" />
<Provider Type="Orleans.Storage.AzureTableStorage" Name="store1"
DataConnectionString="..." />
<Provider Type="Orleans.Storage.AzureBlobStorage" Name="store2"
DataConnectionString="..." />
</StorageProviders>
Dependency Injection
Development with
var siloBuilder = new SiloHostBuilder(); //new ClientBuilder();
siloBuilder.ConfigureServices(svc=>
svc.AddSingleton<IInjectedService,InjectedService>());
public class MyGrain : Grain, IMyGrain
{
private readonly IInjectedService _injectedService;
public MyGrain(IInjectedService injectedService)
{
_injectedService = injectedService;
}
public Task<string> SayHello(string name)
{
return Task.FromResult($"Hello {name}");
}
}
Stateless Worker Grain (performans)
Development with
[StatelessWorker]
public class MyStatelessWorkerGrain : Grain, IMyStatelessWorkerGrain
{
...
}
var worker = GrainFactory
.GetGrain<IMyStatelessWorkerGrain>(0); //or Guid.Empty
await worker.Process(args);
Development with
Appromixmate Performance Expectations
Using X-Large VMs (8 CPU Cores / 14 GB RAM) on Microsoft Azure, with one silo per VM:
NOTE: Old results - https://github.com/OrleansContrib/DesignPatterns
Demo
Development with
By Gökhan Gökalp
Actor Model and Microsoft Project Orleans meetup.
Software Architect, Blog writer. If you free your mind, you free your code.