简体   繁体   English

如何在部署在不同群集节点上的两个相同参与者之间保持状态? (akka.net)

[英]How do I persist states between two same actors deployed on different cluster node? (akka.net)

If I have a setup like below, let's say I'll have 3 nodes joined to a cluster, and I use round robin pool. 如果我有如下所示的设置,那么说我将有3个节点加入集群,并且我使用了循环池。

var worker = cluster.ActorOf(Props.Create<Worker>().WithRouter(
                 new ClusterRouterPool(
                     new RoundRobinPool(5),
                     new ClusterRouterPoolSettings(30, true, 1))), "worker");

The "worker" simply remembers how many messages it has processed like below “工作者”只记得它已经处理了多少条消息,如下所示

public class Worker : TypedActor, IHandle<int> {
readonly List<int> processed;

public Worker()
{
    processed = new List<int>();
}

public void Handle(int message)
{
    System.Threading.Thread.Sleep(new Random().Next(1000, 2000));
    processed.Add(message);
    Console.WriteLine("WORKER ({0}) [{1}:{2}], processed: {3}", message, Context.Self.Path, Cluster.Get(Context.System).SelfUniqueAddress.Address.Port, processed.Count);
}

Is there anyway to synchronize the "processed List" between different actors on different cluster nodes? 无论如何,是否需要在不同群集节点上的不同参与者之间同步“已处理列表”? Is this something that akka.net.cluster.sharding will eventually do? 这是akka.net.cluster.sharding最终会做的事情吗? Or am I doing something which totally makes no sense? 还是我在做完全没有意义的事情?

In general your problem seems to be the closest to what JVM akka eventuate and ddata plugins offer. 一般你的问题似乎是最接近于JVM阿卡落空DDATA插件提供。 General side effect in every case when you have actors working on it on the same piece of data is eventual consistency - since your state is 'shared' between many actors working on the multiple machines, the actual state at particular point it time may be blurred and will differ depending on which actor's point of view will you take. 在每种情况下,如果让参与者在同一条数据上进行操作,通常会产生副作用,即最终的一致性-由于您的状态是“在多台计算机上工作的许多参与者之间共享的”状态,因此在特定时间点的实际状态可能会模糊视您所采取的演员角度而定。

At the moment I haven't heard about any finished production ready options on .NET land for your case, but Akka.DistributedData - which is currently under development - will allow you to complete your task. 目前,您还没有听说过.NET平台上有任何成品可以投入生产的选项,但是目前正在开发中的Akka.DistributedData可以让您完成任务。 It's a Akka implementation of CRDTs . 这是CRDT的Akka实现。

What CRDTs will give you, is the access to an eventually consistent data types that can be replicated over different nodes in distributed cluster up to the moment, when total state is concise in whole application. CRDT将为您提供访问最终一致的数据类型的权限,这些数据类型可以在整个应用程序的总体状态简洁的情况下,通过分布式集群中的不同节点进行复制。 In that case you could replace your processed list to GSet which would allow you to attach your elements to one data set in distributed fashion. 在这种情况下,您可以将processed列表替换为GSet ,这将允许您以分布式方式将元素附加到一个数据集。

If you don't want to wait, take a risk or build CRDT on your own, you could use third-party solutions like Riak . 如果您不想等待,冒险或自行构建CRDT,则可以使用Riak之类的第三方解决方案

PS: Akka.Cluster.Sharding has a different purpose, which is to automatically distribute your actors evenly on your cluster - even when number of nodes changes - so that the only one instance of specific actor will be present in the current cluster scope. PS: Akka.Cluster.Sharding的目的不同,它是自动在群集上均匀分布Actor(即使节点数发生变化),以便在当前群集范围内仅存在一个特定actor实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM