如何增加(AKKA-HTTP 客户端)singleRequest 响应卡盘大小

How to Increase (AKKA-HTTP Client) singleRequest response chuck size

我正在从 URL 读取 HTTP 响应流。 响应 runForeach returns 小块流。 我想增加块大小。

我有一个 application.conf 文件,我在其中试验了以下内容(增加默认值),但没有任何改变。不确定哪个配置参数是我需要的。我一定是做错了什么。

application.conf:

akka.http.host-connection-pool.client.parsing.max-chunk-size=50m
akka.http.host-connection-pool.client.parsing.max-chunk-ext-length=50m
akka.http.host-connection-pool.client.parsing.max-content-length=50m

我的代码:

var config: Config = ConfigFactory.load()

implicit val system = ActorSystem("test", config)
import system.dispatcher
implicit val materializer = ActorMaterializer()

val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = source))

responseFuture.flatMap { response =>
   val responseData = response.entity.dataBytes
   responseData.runForeach(chunk => {
     println(s"CHUNK:${chunk}")
   })
}

谢谢。

如文档所述,这些属性的设置 - link to documentation :

IMPORTANT: Please note that this sections settings can be overriden by the corresponding settings in: akka.http.server.parsing, akka.http.client.parsing or akka.http.host-connection-pool.client.parsing.

也许你应该尝试配置 akka.http.host-connection-pool.client.parsingakka.http.server.parsing

max-chunk-size 是一种防止填充内存的保护措施,如果服务器响应更大的块,它会导致请求失败,它不会以任何其他方式规定块的大小。

块大小由 OS 网络缓冲区、网络数据包大小、服务器响应 http 块等因素决定。您不能真正说 "I want 50m chunks"。

您可以做的是将传入的 ByteString 连接成 50mb 块,concat 是零复制操作,因此开销应该相当低。

Akka Streams 文档中有一个示例,说明如何创建执行 "rechunking" 的自定义图形阶段,此处可能有用:http://doc.akka.io/docs/akka/2.4/scala/stream/stream-cookbook.html#chunking-up-a-stream-of-bytestrings-into-limited-size-bytestrings