"crossing asynchronous boundaries" 的含义

Meaning of "crossing asynchronous boundaries"

来自 Akka 文档,Pipelining and Parallelism

Akka Streams processing stages (be it simple operators on Flows and Sources or graph junctions) are “fused” together and executed sequentially by default. This avoids the overhead of events crossing asynchronous boundaries but limits the flow to execute at most one stage at any given time.

跨越异步边界的事件是什么意思?

同样的词在A Tale of Two Monix Stream and corresponding slides

中也经常使用

当您具体化流时,ActorMaterializer 决定如何 运行 不同的阶段。默认情况下,所有阶段 运行 在幕后的同一演员内依次进行。这是为了避免如果每个阶段 运行 在不同的 actor 中会发生线程上下文切换开销。

当您在舞台上使用 async 运算符时,您是在告诉实体化器您想要在该点创建异步边界。这意味着舞台将 运行 在幕后有自己的演员。根据情况,这可能会影响性能,因为事件将跨越异步边界。

例如:

Source(List("A","B","C "))
  .map(x => x.toLowerCase)
  .async
  .map(x => x.toUpperCase)
  .map(x => x.trim)
  .runWith(Sink.ignore)

此流将 运行 舞台 map(x => x.toLowerCase) 与舞台 map(x => x.toUpperCase)map(x => x.trim) 中的演员不同。最后两个将 运行 在同一个演员中。

最后要提到的一件事是异步边界还允许在流内并行处理事件。每个异步边界都可以独立处理事件,因为它们 运行 在不同的参与者中(只要下游有需求)。在这个简单的场景中,"B" 可以在 map(x => x.toLowerCase) 处同时处理,而 "A" 在 map(x => x.toUpperCase)map(x => x.trim) 处处理。

我希望这有助于更多地了解流的工作原理。