且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

阿卡:"尝试反序列化序列化ActorRef没有范围&QUOT的ActorSystem;错误

更新时间:2022-02-12 08:35:43

这是 ActorSystem 负责所有的参与 ActorRef 功能code>的对象。

An ActorSystem is responsible for all of the functionality involved with ActorRef objects.

在你的程序是这样

actorRef ! message

您实际上是调用ActorSystem,而不是ActorRef,内一堆工作将消息在正确的邮箱,放球的演员来运行接收线程池中的方法,等等...从文档:

You're actually invoking a bunch of work within the ActorSystem, not the ActorRef, to put the message in the right mailbox, tee-up the Actor to run the receive method within the thread pool, etc... From the documentation:

这是演员系统管理它被配置以使用的资源
  来运行,它包含演员。有可能是数以百万计的演员
  一个这样的系统中,所有的咒语之后将其视为
  丰富,他们在大约只有300个字节的开销权衡
  每个实例。当然,确切顺序消息
  在大的系统处理的是没有被应用可控
  笔者

An actor system manages the resources it is configured to use in order to run the actors which it contains. There may be millions of actors within one such system, after all the mantra is to view them as abundant and they weigh in at an overhead of only roughly 300 bytes per instance. Naturally, the exact order in which messages are processed in large systems is not controllable by the application author

这就是为什么你的code工作,但不是在星火精独立。您的每一个星火节点缺少ActorSystem机械,因此,即使你可以在一个节点反序列化ActorRef就没有ActorSystem处理在您的节点功能

That is why your code works fine "standalone", but not in Spark. Each of your Spark nodes is missing the ActorSystem machinery, therefore even if you could de-serialize the ActorRef in a node there would be no ActorSystem to process the ! in your node function.

您可以在每个节点内建立一个ActorSystem和使用(我)的远程通过的 actorSelection 或(ii)您所提到的序列化方法,其中每个节点的ActorSystem将是系统在你所引用的例子。

You can establish an ActorSystem within each node and use (i) remoting to send messages to your ActorRef in the "master" ActorSystem via actorSelection or (ii) the serialization method you mentioned where each node's ActorSystem would be the system in the example you quoted.