C# 的 Actors 有什么好的实现吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2186222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:11:48  来源:igfitidea点击:

Any good implementation of Actors for C#?

c#.netconcurrencyactor

提问by Borba

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

.net/c#的actor 并发模型有什么好的实现吗?

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.

我必须优化 ac# 例程,我认为 actor 模型非常适合作为我的问题的解决方案。不幸的是,我只有 Scala 实现的经验。

采纳答案by alex25

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

你应该看看 MS Concurrency & Coordination Runtime (CCR)和去中心化软件服务 (DSS),它是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.

Axum 将是最合适的,不幸的是它仍处于某种 alpha/beta 阶段(更新它已在 2011 年 2 月被杀死)。我用它做我的研究,不得不说大方向很好,潜力很大。

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

不是 C#,而是 C++ 是 Microsoft 的异步代理库,它为您提供所需的所有功能。

Have a good look at Parallel related featuresof .NET 4.

好好看看.NET 4 的Parallel 相关特性

Hope it helps!

希望能帮助到你!

回答by Anton Gogolev

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:

我不知道 C# 的任何实现,但是有一种基于 Microsoft 的 Actor 模型的全新编程语言。它被称为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.

Axum(以前的代号Maestro)是一种领域特定的并发编程语言,基于 Actor 模型,由 Microsoft 开发。它是一种基于 .NET 公共语言运行时的面向对象语言,使用类似 C 的语法,该语法是一种特定于领域的语言,旨在开发非常适合并发的软件应用程序部分。但它包含足够多的通用结构,无需为并发组件的连续部分切换到通用编程语言(如 C#)。

回答by GregC

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

您是否考虑过随 F# 提供的 T 的 MailboxProcessor?

回答by Henrik

Stact

斯塔特

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

.Net 上的 actor-lib。相当称职且经过良好测试。TopShelf、MassTransit 和 NServiceBus.Host 的基础。

https://github.com/phatboyg/stact

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
  • 工作流,允许定义和执行复杂的状态驱动协议
  • 通道,支持对象之间的消息传递
  • 演员,包括打字的和匿名的
  • Fibers,一种协作线程模型
  • 路由
  • 请求/回复
  • 调度器

Upcoming:

即将到来:

  • Proper supervisor hierarchies
  • 适当的主管层级

Being actively developed at the time of writing by Chris.

在撰写本文时由 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.

Stact 是一个使用 .NET 中的 actor 模型构建应用程序的库。主程序集 Stact.dll 是角色库,包括在任何类型的应用程序中使用角色模型所需的一切。还有其他支持框架,例如 Stact.ServerFramework,可用于通过套接字或 HTTP 公开 Actor,从而允许使用 Actor 构建服务。

回答by Alex Davies

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

NAct是 .NET 的 actor 框架,它采用了一种非常易于使用的方法。(免责声明:我写的)

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.

两个 actor 之间传递的消息只是两个对象之间的方法调用。您必须确保所有方法参数都是不可变的,并且是线程安全的。

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.

它的工作原理是将您的对象包装在处理线程切换的代理中。所有正常的 .NET 功能,尤其是事件,都得到了正确处理,因此您可以编写正常的代码,线程编组将自行发生。

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

甚至还有一个支持 C# 5 async/await 的分支。

回答by Stefan Forster

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

Remact.Net是我目前的项目。它使用 WebSockets 和 Json 进行远程参与者消息传递。它对 C# actor 具有类型安全性,但也支持用 Java 脚本编写的基于浏览器的 actor 的动态类型。

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.

我之前的项目是AsyncWcfLib。这是一个 C# 库,用于在进程中或不同应用程序之间进行通信。远程消息传递使用 WCF。
演员目录服务在多个主机上启用演员发现。这些主机可能运行 Windows 或 Linux。

回答by Omer Raviv

You should also consider PostSharp Actors

您还应该考虑PostSharp Actors

回答by Henrik

FSharp.Actor

FSharp.Actor

An actor framework for F#.

F#的actor框架。

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 githuband at docs

githubdocs 上找到它

回答by Justin du Coeur

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

刚刚注意到这个问题,并想添加一个更新的数据点。微软目前为此有一个半官方项目,称为ActorFX。它是开源的并且仍在不断发展,但值得关注......

回答by Roger Johansson

.NET Actor Model frameworks:

.NET Actor 模型框架:

Proto.Actor

原型演员

  • Actors
  • Virtual Actors
  • 演员
  • 虚拟演员

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

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

Akka.NET

阿卡网

  • Actors
  • 演员

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

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

Microsoft Orleans

微软奥尔良

  • Virtual Actors
  • 虚拟演员

https://github.com/dotnet/orleans

https://github.com/dotnet/orleans