scala - Akka Streams 的 ActorPublisher 作为 Web 响应的源 - 背压如何工作

标签 scala akka akka-http akka-stream backpressure

我使用 akka-streams' ActorPublisher actor 作为每个连接的流式传输 Source 数据被发送到传入的 WebSocket 或 HTTP 连接.

ActorPublishercontract是通过提供需求 - 下游可以接受的元素数量来定期请求数据。如果需求为 0,我不应该发送更多元素。我观察到如果我缓冲元素,当消费者速度慢时,缓冲区大小在 1 到 60 之间波动,但大部分在 40-50 附近。

为了流式传输,我使用 akka-http 将 WebSocket 输出和 HttpResponse 数据设置为 Message< 的 Source 的能力s(或 ByteStrings)。

我想知道在这种情况下背压是如何工作的——当我通过网络将数据流式传输到客户端时。这些数字究竟是如何计算出来的?它会检查网络级别发生的情况吗?

最佳答案

对于您的问题“在这种情况下背压如何工作”,我能找到的最接近的来自 the documentation :

Akka HTTP is streaming all the way through, which means that the back-pressure mechanisms enabled by Akka Streams are exposed through all layers–from the TCP layer, through the HTTP server, all the way up to the user-facing HttpRequest and HttpResponse and their HttpEntity APIs.

至于“这些数字是如何计算的”,我认为是specified in the configuration settings .

关于scala - Akka Streams 的 ActorPublisher 作为 Web 响应的源 - 背压如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44531122/

相关文章:

database - Slick 3 - 基于其他表以事务方式插入到多个表中

java - Scala 泛型混淆

java - 为什么添加 Thread.sleep 会使我的 Akka TestKit 单元测试通过?

scala - 无法使用 Akka-Http 验证 OAuth2

java - 如何使用 Proguard 缩小 scala swing 库?

scala - 为什么scala不能推断方法参数的类型

scala - Akka的分布式 Actor

java - Akka 用于异步处理?

scala - Akka:如何将消息内容包装到 HTTP 响应中?

scala - 如何提高 Akka-http websocket 性能