【发布时间】:2020-07-01 14:13:59
【问题描述】:
我正在尝试使用 scala 并行集合。我正在尝试从本地服务器获取数据,我已经 设置好了,这是我的代码
val httpRequestInputs = List(inputs).par
def getResponse(data: String, url: String) = {
val request = basicRequest.body(text).post(url)
.headers(Map("content-type" -> "text/plain", "charset" -> "utf-8"))
.response(asString)
implicit val backend
= HttpURLConnectionBackend(options = SttpBackendOptions.connectionTimeout(5.minutes))
request.readTimeout(5.minutes).send().body
}
// program executes from here
httpRequestInputs.foreach { input =>
val result = getResponse(input, url)
result match {
case Right(value) => println(value)
case Left(value) => println("error")
}
当使用小尺寸的输入时,没有问题,但是,当我尝试使用大尺寸的输入时,
程序抛出SocketException,我检查了服务器,服务器没有错误,
在我看来,客户端正在提前关闭连接。而且,这些大投入,
单独运行时,通常需要不到 90 秒的时间来获得响应。
我尝试在 http 请求中扩展连接和读取超时选项,但我仍然得到 例外。
谁能帮我理解,为什么客户端要关闭连接?
对于http请求,我使用的是客户端com.softwaremill.sttp.client
【问题讨论】:
-
你能从抛出的
SocketException中打印出message吗?这可能会帮助您缩小问题的范围
标签: scala http parallel-collections