Any good implementation of Actors for C#?

C#.NetConcurrencyActor

C# Problem Overview


Is there any good implementation of actors concurrency model for .net/c#?

I have to optimize a c# routine and i think that actors model fits perfectly as a solution for my problem. Unfortunately i have experience only with scala implementation.

C# Solutions


Solution 1 - C#

.NET Actor Model frameworks:

Proto.Actor

  • Actors
  • Virtual Actors

https://github.com/AsynkronIT/protoactor-dotnet

Akka.NET

  • Actors

https://github.com/akkadotnet/akka.net

Microsoft Orleans

  • Virtual Actors

https://github.com/dotnet/orleans

Solution 2 - C#

One might also look at Project Orleans Microsofts approach on actors.(which was released last week)

This is the projects website: http://research.microsoft.com/en-us/projects/orleans/

Here is also a good talk from build 2014 as introduction

Using Orleans to Build Halo 4’s Distributed Cloud Services in Azure http://channel9.msdn.com/Events/Build/2014/3-641

Please note that the bits for download as posted today are CTP.

Introduction to Orleans: http://felixnotes.com/orleans-microsofts-take-on-the-actor-pattern-in-net/

And yes, it was also open sourced: https://github.com/dotnet/orleans

Solution 3 - C#

You should have a look at MS Concurrency & Coordination Runtime (CCR), and the Decentralized Software Services (DSS), part of Robotic Studio.

These frameworks would allow you develop loosely coupled services that fulfill most of the actor-approach requirements.

Axum would be the best fit, unfortunately it's still in some sort of alpha/beta phase (UPDATE it has been killed in Feb. 2011). I use it for my research and must say that the general direction is great and it has enormous potential.

Not C# but C++ is Microsoft's Asynchronous Agents Library which gives you all the features that you need.

Have a good look at Parallel related features of .NET 4.

Hope it helps!

Solution 4 - C#

Stact

An actor-lib on .Net. Quite competent and well tested. The foundation of TopShelf, MassTransit and NServiceBus.Host.

https://github.com/phatboyg/stact

Contains the abstractions:

  • Workflow, allowing complex state-driven protocols to be defined and executed
  • Channels, to support message passing between objects
  • Actors, both typed and anonymous
  • Fibers, a cooperative threading model
  • Routing
  • Request/Reply
  • Schedulers

Upcoming:

  • Proper supervisor hierarchies

Being actively developed at the time of writing by Chris.

Overview:

Developing concurrent applications requires an approach that departs from current software development methods, an approach that emphasizes concurrency and communication between autonomous system components. The actor model defines a system of software components called actors that interact with each other by exchanging messages (instead of calling methods on interfaces in an object-oriented design), producing a system in which data (instead of control) flows through components to meet the functional requirements of the system.

Stact is a library for building applications using the actor model in .NET. The main assembly, Stact.dll, is the actor library and includes everything needed to use the actor model in any type of application. There are also additional supporting frameworks, such as Stact.ServerFramework, that can be used to expose actors via sockets or HTTP, allowing services to be built using actors.

Solution 5 - C#

NAct is an actors framework for .NET which takes a really easy-to-use approach. (Disclaimer: I wrote it)

The message passing between two actors is just a method call between two objects. You have to make sure that all method arguments are immutable, and it will be thread-safe.

It works by wrapping your objects in a proxy that deals with the thread switching. All the normal .NET features, particularly events, are dealt with correctly, so you can write normal code and thread marshalling will happen on its own.

There's even a branch with support for C# 5 async/await.

Solution 6 - C#

I don't know of any implementations for C#, but there's a whole new programming language based on the Actor model by Microsoft. It's called Axum:

> Axum (previously codenamed Maestro) is a domain specific concurrent programming language, based on the Actor model, being developed by Microsoft. It is an object-oriented language based on the .NET Common Language Runtime using a C-like syntax which, being a domain-specific language, is intended for development of portions of a software application that is well-suited to concurrency. But it contains enough general-purpose constructs that one need not switch to a general-purpose programming language (like C#) for the sequential parts of the concurrent components.

Solution 7 - C#

Today Microsoft announced Azure Service Fabric which according to this picture, implements an actor programming model:

Azure Service Fabric

See the announcement: http://azure.microsoft.com/blog/2015/04/20/announcing-azure-service-fabric-reducing-complexity-in-a-hyper-scale-world/

Update: The SDK is now available and there's a video tutorial as well.

Solution 8 - C#

Have you considered MailboxProcessor of T, provided with F#?

Solution 9 - C#

You should also consider PostSharp Actors

Solution 10 - C#

Remact.Net is my current project. It uses WebSockets and Json for the remote actor messaging. It has typesafety for C# actors but also supports dynamic types for browser based actors written in Java script.

My previous project was AsyncWcfLib. This is a C# library for actors communicating in a process or between different applications. The remote message passing uses WCF.
An actor catalog service enables actor discovery on several hosts.The hosts may run Windows or Linux.

Solution 11 - C#

FSharp.Actor

An actor framework for F#.

From an example:

let rec schizoPing =
    (fun (actor:IActor<_>) ->
        let log = (actor :?> Actor.T<_>).Log
        let rec ping() =
            async {
                let! (msg,_) = actor.Receive()
                log.Info(sprintf "(%A): %A ping" actor msg, None)
                return! pong()
            }
        and pong() =
            async {
                let! (msg,_) = actor.Receive()
                log.Info(sprintf "(%A): %A pong" actor msg, None)
                return! ping()
            }
        ping()
    )
        

Sending two messages to the 'schizo' actor results in

let schizo = Actor.spawn (Actor.Options.Create("schizo")) schizoPing

!!"schizo" <-- "Hello"
!!"schizo" <-- "Hello"

Output:

(schizo): "Hello" ping
(schizo): "Hello" pong

Find it at github and at docs

Solution 12 - C#

Just noticed this question, and thought to add a newer data point. Microsoft currently has a semi-official project for this, called ActorFX. It's open source and still evolving, but worth keeping an eye on...

Solution 13 - C#

As already mentioned, F#'s MailboxProcessor class offers a simple, straightforward implementation of the actor model. A fantastic introduction on how to use it is available here. F# interoperates with C# very well and you can wrap up the agent in a class with methods which post different messages. For the cases where the agent will reply with an asynchronous response, see the [PostAndAsyncReply][2] method. This returns an Async workflow which you can turn into a task that can be awaited in C# using the [Async.StartAsTask][3] method.

Finally, if you need to distribute your actors remotely, I recommend you check out [Akka.NET][4] which offers both C# and F# APIs.

[2]: https://msdn.microsoft.com/en-us/library/ee370407(VS.100%29.aspx [3]: https://msdn.microsoft.com/en-us/library/ee821132.aspx [4]: http://akkadotnet.github.io

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBorbaView Question on Stackoverflow
Solution 1 - C#Roger JohanssonView Answer on Stackoverflow
Solution 2 - C#silverfighterView Answer on Stackoverflow
Solution 3 - C#alex25View Answer on Stackoverflow
Solution 4 - C#HenrikView Answer on Stackoverflow
Solution 5 - C#Alex DaviesView Answer on Stackoverflow
Solution 6 - C#Anton GogolevView Answer on Stackoverflow
Solution 7 - C#hasanccView Answer on Stackoverflow
Solution 8 - C#GregCView Answer on Stackoverflow
Solution 9 - C#Omer RavivView Answer on Stackoverflow
Solution 10 - C#Stefan ForsterView Answer on Stackoverflow
Solution 11 - C#HenrikView Answer on Stackoverflow
Solution 12 - C#Justin du CoeurView Answer on Stackoverflow
Solution 13 - C#Anton TcholakovView Answer on Stackoverflow