繁体   English   中英

WSClient-打开的文件太多

[英]WSClient - Too Many Open Files

我正在CentOS 6上使用Play Framework 2.4,并且我的应用程序抛出此异常:

java.net.SocketException: Too many open files

我搜索了很多有关Stack Overflow的主题,并尝试了以下解决方案:

  • 将打开的文件数增加到65535;
  • 更改/etc/security/limits.conf的硬限制和软限制;
  • 在/etc/sysctl.conf上更改fs.file-max的值;
  • 减少了文件/ proc / sys / net / ipv4 / tcp_fin_timeout的超时;

该错误不断发生。 在另一个站点上,我发现人们面临着同样的问题,因为他们没有从WSClient调用close()方法,但就我而言,我正在使用依赖项注入:

@Singleton
class RabbitService @Inject()(ws:WSClient) {

  def myFunction() {
    ws.url(“url”).withHeaders(
      "Content-type" -> "application/json",
      "Authorization" -> ("Bearer " + authorization))
      .post(message)
      .map(r => {
      r.status match {
        case 201 => Logger.debug("It Rocks")
        case _ => Logger.error(s"It sucks")
      }
    })

  }

}

如果我更改实现以等待结果,它的工作就像一个魅力,但是性能却很差-我想使用map函数代替等待结果:

@Singleton
class RabbitService @Inject()(ws:WSClient) {

  def myFunction() {
    val response = ws.url("url")
      .withHeaders(
        "Content-type" -> "application/json",
        "Authorization" -> ("Bearer " + authorization))
      .post(message)

    Try(Await.result(response, 1 seconds)) match {
      case Success(r) =>
        if(r.status == 201) {
          Logger.debug(s"It rocks")
        } else {
          Logger.error(s"It sucks")
        }
      case Failure(e) => Logger.error(e.getMessage, e)
    }

  }

}

有人知道如何解决此错误吗? 我已经尝试了一切,但没有成功。

如果有人也面临同样的问题,你需要在配置WSClient application.conf -需要设置maxConnectionsTotalmaxConnectionsPerHost

这就是我解决这个问题的方法。

https://www.playframework.com/documentation/2.5.x/ScalaWS

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM