问题
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.
回答1:
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!
回答2:
.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
回答3:
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
回答4:
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.
回答5:
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.
回答6:
Today Microsoft announced Azure Service Fabric which according to this picture, implements an actor programming model:
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.
回答7:
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 codenamedMaestro
) 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.
回答8:
Have you considered MailboxProcessor of T, provided with F#?
回答9:
You should also consider PostSharp Actors
回答10:
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.
回答11:
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
回答12:
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...
回答13:
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.
来源:https://stackoverflow.com/questions/2186222/any-good-implementation-of-actors-for-c