在 Akka Streams 中,Sink.fold() 处理是序列化的吗?
In Akka Streams, is Sink.fold() processing serialized?
我正在开始使用 Akka 流;我正在尝试创建一个从 Web 服务读取数据然后将它们保存在 S3 中的流。
我想知道,如果我使用 Sink.fold 方法(为了收集有关持久元素的信息)定义一个 Sink 用于持久化,那么发送到 sink 的元素是一个接一个地处理还是并行处理?
这是一个基本问题,但我无法在文档中找到明确的答案。
由于 Sink.fold
需要前一个元素的结果与下一个元素组合,因此它必须是顺序的。
实际上更像是 Sink.foldLeft
。
换句话说,如果您有 a, b
作为元素,并且您使用 f
折叠它们,则需要 acc = f(zero, a)
才能处理 f(acc, b)
。因此,在 a
的处理完成之前,无法处理 b
。
来自api doc:
A Sink that will invoke the given function for every received element, giving it its previous output (or the given zero value) and the element as input. The returned java.util.concurrent.CompletionStage will be completed with value of the final function evaluation when the input stream ends, or completed with Failure if there is a failure is signaled in the stream.
我正在开始使用 Akka 流;我正在尝试创建一个从 Web 服务读取数据然后将它们保存在 S3 中的流。 我想知道,如果我使用 Sink.fold 方法(为了收集有关持久元素的信息)定义一个 Sink 用于持久化,那么发送到 sink 的元素是一个接一个地处理还是并行处理?
这是一个基本问题,但我无法在文档中找到明确的答案。
由于 Sink.fold
需要前一个元素的结果与下一个元素组合,因此它必须是顺序的。
实际上更像是 Sink.foldLeft
。
换句话说,如果您有 a, b
作为元素,并且您使用 f
折叠它们,则需要 acc = f(zero, a)
才能处理 f(acc, b)
。因此,在 a
的处理完成之前,无法处理 b
。
来自api doc:
A Sink that will invoke the given function for every received element, giving it its previous output (or the given zero value) and the element as input. The returned java.util.concurrent.CompletionStage will be completed with value of the final function evaluation when the input stream ends, or completed with Failure if there is a failure is signaled in the stream.