Introduction to
Orleans Virtual Actor Model

Gökhan GÖKALP

30.05.2017

Trendyol Tech Talk

Agenda

  • Actor Model
  • Project Orleans
  • Development with Orleans
  • Appromixmate Performance Expectations
  • Demonstration
  • References
  • Contacts

Actor Model

  • First of all, an actor is the primitive unit of computation.
  • Actors are completely isolated from each other and they will never share memory.
  • The actor model is a conceptual model to deal with concurrent computation.
  • Everything's message-focused
    • Each actor has a mailbox.
    • Each actor is independent of the other and can send message to each other.
  • So, What can do actors?
    • It can create one or more actors. (one actor is no actor)
    • It can send a message to one another.
    • It determines what will do with the message while sending the message to one another.
  • Created by Hewitt, Bishop and Steiger - 1970s

Actor Model

Everything's message-focused and one actor is no actor.

Project Orleans

Orleans is a framework that provides a straightforward approach to building distributed high-scale computing applications.

Orleans Concepts

  • Silo: deployment host for Grains.
    • One or more Silos per node.
  • Grain: the actor is called Grain in Orleans. (Virtual Actor)
    • Grain is activated into a silo when invoked.
    • Garbage automatically collected when not used.
    • They communicate via asynchronous message passing.
    • An actor executes with single-threaded semantics.

Project Orleans

  • No need to learn:
    • Complex concurrency patterns.
    • Scaling patterns.
  • Single-threaded execution context
  • Orleans provide high availability (can be added dynamically nodes to cluster) and low latency.
  • Orleans handle:
    • Reliability concerns
    • Distributed resource management concerns
  • It was created by Microsoft Reasearch and designed for use in the cloud and made available as open source in January 2015

Orleans is to simplify distributed computing and allow non-experts to write efficient, scalable and reliable distributed services.

Development with Orleans

  1. Design Grain Interface
  2. Implement Grain Interface
  3. Grain Method Invocation
  4. Grain Persistance
  5. Some Grain Features

Development with Orleans

Design Grain Interface

Grains interact with each other by invoking methods declared as part of the respective grain interfaces.

  • Grain interface derived from IGrain
  • All methods of a grain interface must return a Task
  • Clients and Grains communicate with each other via RPC.
public interface IMyGrain : IGrainWithStringKey
{
    Task<string> SayHello(string name);
}

Development with Orleans

Implement Grain Interface

  • Grain derived from GrainBase and implement interface
  • Using asynchronous messaging, it provides full-duplex communication with other grains, as well as Orleans Client code.
public class MyGrain : IMyGrain
{
    public Task<string> SayHello(string name)
    {
        return Task.FromResult($"Hello {name}");
    }
}

Development with Orleans

Grain Method Invocation

var grain = GrainClient.GrainFactory.GetGrain<IMyGrain>("grain1");
await grain.SayHello("World");

Create a proxy object, and calling the methods:

  • A grain reference can be constructed by passing the identity of a grain to the GrainFactory.GetGrain<T>() method.

Development with Orleans

Grain Persistance

  • Orleans provides automated state persistance. (GrainBase<TGrainState>)
  • Allow different grain types to use different types of storage providers.
  • Grains will be marked with a [StorageProvider] attribute that specifies a named instance of a storage provider.
[StorageProvider(ProviderName="store1")]
public class MyGrain<MyGrainState> ...
{
  ...
}
<StorageProviders>
    <Provider Type="Orleans.Storage.MemoryStorage" Name="DevStore" />
    <Provider Type="Orleans.Storage.AzureTableStorage" Name="store1"
        DataConnectionString="DefaultEndpointsProtocol=https;AccountName=data1;AccountKey=SOMETHING1" />
    <Provider Type="Orleans.Storage.AzureBlobStorage" Name="store2"
        DataConnectionString="DefaultEndpointsProtocol=https;AccountName=data2;AccountKey=SOMETHING2"  />
</StorageProviders>

Development with Orleans

Some Grain Features

  • Stateless Worker Grain

    • Can be scaled out automatically at runtime.

  • Immutable Messages

    • For better serialization performance.

  • Reentrant Grain

    • In Orleans, concurrent processing can be provided with the “[Reentrant]” attribute.

  • Observer Grain

    • Can observe events

Appromixmate Performance Expectations

Using X-Large VMs (8 CPU Cores / 14 GB RAM) on Microsoft Azure, with one silo per VM:

  • A grain will handle a maximum of 1,000 requests per second.
  • A silo will handle a maximum of 10,000 requests per second.
  • A silo will hold 100,000 active grains.

References

Contacts

Introduction to Orleans Virtual Actor Model

By Gökhan Gökalp

Introduction to Orleans Virtual Actor Model

Introduction to Orleans Virtual Actor Model presentation at Trendyol tech talk.

  • 2,931