scala 基于 Agent/Actor 的并发设计的设计模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/568727/
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-09-13 16:18:46  来源:igfitidea点击:

Design patterns for Agent / Actor based concurrent design

scalaerlangactoragent

提问by nso1

Recently i have been getting into alternative languages that support an actor/agent/shared nothing architecture - ie. scala, clojure etc (clojure also supports shared state).

最近我一直在研究支持演员/代理/无共享架构的替代语言 - 即。scala、clojure 等(clojure 也支持共享状态)。

So far most of the documentation that I have read focus around the intro level. What I am looking for is more advanced documentation along the gang of four but instead shared nothing based.

到目前为止,我阅读的大部分文档都集中在介绍级别。我正在寻找的是四人组中更高级的文档,但没有共享任何内容。

Why ? It helps to grok the change in design thinking. Simple examples are easy, but in a real world java application (single threaded) you can have object graphs with 1000's of members with complex relationships. But with agent based concurrency development it introduces a whole new set of ideas to comprehend when designing large systems. ie. Agent granularity - how much state should one agent manage - implications on performance etc or are their good patterns for mapping shared state object graphs to agent based system. tips on mapping domain models to design. Discussions not on the technology but more on how to BEST use the technology in design (real world "complex" examples would be great).

为什么 ?它有助于理解设计思维的变化。简单的例子很容易,但在现实世界的 Java 应用程序(单线程)中,您可以拥有具有复杂关系的 1000 个成员的对象图。但是通过基于代理的并发开发,它引入了一套全新的想法,以便在设计大型系统时加以理解。IE。代理粒度 - 一个代理应该管理多少状态 - 对性能的影响等,或者是将共享状态对象图映射到基于代理的系统的良好模式。将领域模型映射到设计的技巧。讨论的不是技术,而是更多关于如何在设计中最好地使用技术(现实世界的“复杂”例子会很棒)。

回答by Jan Henry Nystrom

Even if I cannot come up with any good real world examples that provide you with design patterns straight up, there are a few places to start.

即使我不能想出任何好的现实世界的例子来直接为你提供设计模式,也有几个地方可以开始。

The first is getting your head wrapped properly round the concepts. One book helping you do this is Making reliable distributed systems in the presence of software errorswritten by an Erlang Guru Joe Armstrong where explains Concurrency Oriented Programming in a very accessible way. It is in fact a Ph.D. thesis, but do not let that scare you. It is by far easier to read, and pleasant into the bargain, than most common text books.

首先是让你的头脑正确地围绕概念。一本帮助你做到这一点的书是 由 Erlang Guru Joe Armstrong 编写的在存在软件错误的情况下制作可靠的分布式系统,其中以一种非常容易理解的方式解释了面向并发的编程。它实际上是博士学位。论文,但不要让它吓到你。与大多数普通教科书相比,它更容易阅读,而且价格实惠。

Looking at actual systems normally means that you have to learn too much about the actual language for it too make sense just to evaluate things. For Erlang the documentationprovides design methodology and behaviours(Erlang speek for design pattern libraries). This will illustrate the design patterns most commonly used in this setting. And these have proved to be effective in building large scale systems, i.e. millions of lines of code (comparable to a factor 4 to 10 of other languages such as Java) and milloins of concurrent processes running on one machine in distributed clusters of machines. A recent example of a real live system is Facebook Chat.

查看实际系统通常意味着您必须对实际语言了解太多,因为仅评估事物也很有意义。对于 Erlang,文档提供了设计方法和行为(设计模式库的 Erlang 演讲)。这将说明在此设置中最常用的设计模式。并且这些已被证明在构建大规模系统方面是有效的,即数百万行代码(与 Java 等其他语言的 4 到 10 倍相比)和在分布式机器集群中的一台机器上运行的数以百万计的并发进程。一个真实的实时系统的最新例子是 Facebook Chat

For the other frameworks I cannot really help you I am afraid.

对于其他框架,我恐怕无法真正帮助您。

回答by Joseph Weissman

An "actor" is itself the unifying pattern for concurrent programming (an asynchronous message queue plus an execution context for processing it), but there are many design patterns which assist in specifying aspects or elements of agent-based systems. Many of the most common can be found in Wikipedia's article on Concurrency Patterns. Some highlights:

“参与者”本身就是并发编程的统一模式(一个异步消息队列加上一个用于处理它的执行上下文),但是有许多设计模式可以帮助指定基于代理的系统的方面或元素。许多最常见的可以在维基百科关于并发模式的文章中找到。一些亮点:

If you haven't come across it already, Akkamay be of interest to you -- it is a "purely" event-driven actor framework running on the JVM.

如果您还没有遇到过它,您可能会对Akka感兴趣——它是一个在 JVM 上运行的“纯”事件驱动的 actor 框架。

回答by Simon

I asked a similar question herewhich had some reasonable answers that may help. I'm watching yours carefully. I haven't yet found something which has really helped me, but I am very actively looking.

在这里问了一个类似的问题其中有一些合理的答案可能会有所帮助。我正在仔细观察你的。我还没有找到真正对我有帮助的东西,但我非常积极地寻找。

I think the mind-shift is the single largest barrier to stepping to concurrent architectures and languages and until that is cracked developers are going to stick with easy to learn MS style paradigms. For it to really become mainstream it needs to find its way into schools and be taught alongside C# and VB.

我认为思维转变是迈向并发架构和语言的最大障碍,在此之前,开发人员将坚持使用易于学习的 MS 风格范式。为了让它真正成为主流,它需要进入学校并与 C# 和 VB 一起教授。

My answer to the 2080 programmers questionis "concurrently".

我对2080 程序员问题的回答是“并发”。