78

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.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Borba
  • 791
  • 1
  • 6
  • 6
  • http://blogs.msdn.com/b/dotnet/archive/2014/04/02/available-now-preview-of-project-orleans-cloud-services-at-scale.aspx – Daniel Little May 12 '14 at 03:09

13 Answers13

57

.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

Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
  • This open source project has some good promise too https://github.com/louthy/language-ext // Log process var logger = spawn("logger", Console.WriteLine); // Ping process ping = spawn("ping", msg => { tell(logger, msg); tell(pong, "ping", TimeSpan.FromMilliseconds(100)); }); // Pong process pong = spawn("pong", msg => { tell(logger, msg); tell(ping, "pong", TimeSpan.FromMilliseconds(100)); }); // Trigger tell(pong, "start"); – Dasith Wijes Sep 26 '16 at 23:27
25

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

silverfighter
  • 6,762
  • 10
  • 46
  • 73
22

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!

CharlesB
  • 86,532
  • 28
  • 194
  • 218
alex25
  • 621
  • 5
  • 19
  • 6
    and I found this here: http://code.google.com/p/retlang/ – alex25 Feb 20 '10 at 02:03
  • thanks for your comprehensive answer. – Borba Feb 24 '10 at 11:42
  • TPL Dataflow contains building blocks for Agents/Actors on C# – Dzmitry Lahoda May 02 '11 at 13:36
  • The ccrdss link is now dead - TPL Dataflow (TDF) is talked about here: http://msdn.microsoft.com/en-us/concurrency/default.aspx and here: http://msdn.microsoft.com/en-us/devlabs/gg585582 (although I imagine the second link will go stale sooner or later. At the time of posting this comment, TDF was still at the preview stage. – paytools-steve Nov 20 '11 at 11:39
  • TPL Dataflow link update: http://msdn.microsoft.com/en-us/library/vstudio/dd492627(v=vs.120).aspx – BozoJoe Dec 06 '14 at 04:05
18

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.

Henrik
  • 9,714
  • 5
  • 53
  • 87
13

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.

Alex Davies
  • 171
  • 2
  • 5
  • Would you consider giving some of your time to extending Stact instead of creating a new framework? I'd very interested in seeing your async-thinking permeate more of Stact (I'm not its author, but I really like it). – Henrik Mar 18 '12 at 10:18
  • Hmm, I'm really happy that any implementation of Actors is gaining traction, but I'm still a fan of doing it using method calls. Compare these to (coincidentally identical) code samples using Stact and NAct: https://github.com/phatboyg/Stact/wiki/Samples-Ping-Pong and http://code.google.com/p/n-act/wiki/PingPong – Alex Davies May 14 '12 at 16:43
  • 1
    I prefer the message-passing semantics, because it's true to what it does and there's no way to show e.g. intermittent network failure or reason easily with the concurrency and clocks of messages being sent when that's not explicit. Were I to participate in a framework nowadays I'd extend the F# MailboxProcessor, which already works really well - with supervisors and easier message passing across network. – Henrik May 14 '12 at 20:19
  • I just created [EasyActor](https://github.com/David-Desmaisons/EasyActor) which philosophy is similar to NAct. Main diferences with Nact is that it supports results received from actors with Task and is based on Castle Core DynamicProxy to intercept method calls. Raw performance test also indicates an improved performance of rouglhy 40% in the ping-pong test. – David Desmaisons Oct 05 '15 at 02:55
5

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.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
5

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.

masnider
  • 2,609
  • 13
  • 20
hasancc
  • 145
  • 1
  • 9
2

You should also consider PostSharp Actors

Omer Raviv
  • 11,409
  • 5
  • 43
  • 82
2

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

GregC
  • 7,737
  • 2
  • 53
  • 67
1

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.

Stefan Forster
  • 405
  • 4
  • 7
0

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

Henrik
  • 9,714
  • 5
  • 53
  • 87
0

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...

Justin du Coeur
  • 2,699
  • 1
  • 14
  • 19
0

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 method. This returns an Async workflow which you can turn into a task that can be awaited in C# using the Async.StartAsTask method.

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

Anton Tcholakov
  • 3,710
  • 1
  • 12
  • 10