我正在尝试使用 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