找到你要的答案

Q:Live resources in Akka Stream flow description

Q:艾加流描述生活资源

There is this note in the akka-stream docs stating as follows:

… a reusable flow description cannot be bound to “live” resources, any connection to or allocation of such resources must be deferred until materialization time. Examples of “live” resources are already existing TCP connections, a multicast Publisher, etc.; …

I have several questions concerning the note:

  • Apart from the these two examples, what other resource counts as a live?
    • Anything that cannot be safely (deep)copied? Like a Thread?
    • Should I also avoid sharing anything that's not thread-safe?
  • What about an ActorRef existing in the ActorSystem used by the ActorFlowMaterializer?
  • How to defer allocation until materialization time? Is it safe for example to allocate it in the constructor of a PushPullStage but not in the create function of a FlowGraph?

有这张在阿卡流文档说明如下:

…一个可重用的流程描述不能绑定到“活”的资源,任何连接或这些资源配置必须推迟到物化时间。“活”的资源已经存在的TCP连接的例子,一个组播的出版商,等;…

我有几个关于笔记的问题:

  • Apart from the these two examples, what other resource counts as a live?
    • Anything that cannot be safely (deep)copied? Like a Thread?
    • Should I also avoid sharing anything that's not thread-safe?
  • What about an ActorRef existing in the ActorSystem used by the ActorFlowMaterializer?
  • How to defer allocation until materialization time? Is it safe for example to allocate it in the constructor of a PushPullStage but not in the create function of a FlowGraph?
answer1: 回答1:

The problem here is a common problem if we consider webservices, RMI connections or any other communication protocol. It's always recommended sharing "primitive" values then references, because marshalling/unmarshalling or serializing/unserializing is always a headache. Also think of different types of environments communicating each other. Sharing solid values is a safe way to solve communication.

Akka by itself is a good example of "microservices" communicating actors each other. When I read the documentation of Akka, one good word defines Akka actors very well. Actors are like mailbox clients and you can think of each client has a mailbox. When you pass a variable, it's just like you got a new email.

Short result of long story, be avoid sharing "dependent" objects that can be invalidated before it's read from another actor. Additionally, if your system names actorRefs dynamically, avoid calling them by its reference.

"Materializing" is explained in docs of akka-streams.

The process of materialization may be parameterized, e.g. instantiating a blueprint for handling a TCP connection’s data with specific information about the connection’s address and port information. Additionally, materialization will often create specific objects that are useful to interact with the processing engine once it is running, for example for shutting it down or for extracting metrics. This means that the materialization function takes a set of parameters from the outside and it produces a set of results. Compositionality demands that these two sets cannot interact, because that would establish a covert channel by which different pieces could communicate, leading to problems of initialization order and inscrutable runtime failures.

So use parameters instead of passing "connection" itself.

Deferring a live resource is not a big think. That means if you use one connection for all system, you should keep it alive always. Or when you create a transaction in actor-1 and send it to actor-2, you shouldn't terminate the transaction in actor-1 until actor-2 finished its job with transaction.

Then how you can understand ? Then you use "Future" and "offer()".

Hope I understand your question and hope I can express myself.

这里的问题是一个常见的问题,如果我们考虑到Web服务,RMI连接或任何其他通信协议。它总是推荐共享的“原始”值的引用,因为编组/反序列化/ unserializing始终是一个头痛的问题。也可以考虑不同类型的环境相互交流。共享实体值是解决通信安全的方法。

健康本身就是一个很好的例子“精卫”的演员们互相交流。当我读到阿卡的文档,一个字定义阿卡演员很好。演员就像邮箱客户端,你可以认为每个客户端都有邮箱。当你通过一个变量,就像你有一个新的电子邮件。

长的故事短,可避免共享”可以失效之前,来自另一个演员读依赖的对象。另外,如果你的系统的名称actorrefs动态,避免调用他们的参考。

“物化”是在阿卡流文档说明。

物化的过程可以被参数化,例如实例化与连接的地址和端口信息的特定信息处理TCP连接的数据蓝图。此外,物化往往会创造,一旦它运行的处理引擎交互有用的特定的对象,例如关闭或提取指标。这意味着物化功能需要一组参数外,它产生一个结果集。组合性要求这两集不能相互作用,因为这将建立由不同可以交流的隐蔽通道,导致初始化顺序和高深莫测的失效问题。

所以使用参数,而不是通过“连接”本身。

将生活资源是不是一个大的思考。这意味着,如果你使用一个连接的所有系统,你应该保持它始终活着。当你创建一个交易-1寄给actor-2,你不应该终止交易直到actor-2 -1完成交易的工作。

那你怎么能理解?然后使用“未来”和“offer()”。

希望我理解你的问题,希望我能表达我自己。

java  scala  akka  akka-stream