Akka 中的 Future 超时

发布于 2024-12-17 06:54:15 字数 975 浏览 0 评论 0原文

我们有一个服务器,可以处理不同参与者的投资组合和证券(在其内部)。对于证券数量较少(<20)的投资组合,这种方法效果很好。当我将安全计数增加到 1000 时,遇到以下问题:

akka.dispatch.FutureTimeoutException: Futures timed out after [5000] ms

我可以通过增加 akka 配置中的超时来绕过此错误,这是正确的做法吗?在早于 1.2 的 akka 版本中,我可以在 actor 中设置 self.timeout,但这已被弃用。

我(间歇性地)面临的另一个问题是,在我的投资组合参与者中加入 futures.map 代码时,整个服务器挂起:

    //fork out for each security
    val listOfFutures = new ListBuffer[Future[Security]]()
    for (security <- portfolio.getSecurities.toList) {
      val securityProcessor = actorOf[SecurityProcessor].start()
      listOfFutures += (securityProcessor ? security) map {
        _.asInstanceOf[Security]
      }
    }
    EventHandler.info(this,"joining results from security processors")
    //join for each security
    val futures = Future.sequence(listOfFutures.toList)
    futures.map {
      listOfSecurities =>
        portfolioResponse = MergeHelper.merge(portfolio, listOfSecurities)
    }.get

We have a server that processes portfolio and securities (inside it) in different actors. For portfolio with smaller number of securities (<20) this works fine. When i increase the number of security count to 1000, encountered following issues:

akka.dispatch.FutureTimeoutException: Futures timed out after [5000] milliseconds

I could bypass this error by increasing timeout inside akka config, is that the right thing to do? In akka versions earlier than 1.2 i could set self.timeout inside the actor but that is deprecated.

The other issue I faced (intermittently) is that the entire server hangs while joining in futures.map code inside my portfolio actor:

    //fork out for each security
    val listOfFutures = new ListBuffer[Future[Security]]()
    for (security <- portfolio.getSecurities.toList) {
      val securityProcessor = actorOf[SecurityProcessor].start()
      listOfFutures += (securityProcessor ? security) map {
        _.asInstanceOf[Security]
      }
    }
    EventHandler.info(this,"joining results from security processors")
    //join for each security
    val futures = Future.sequence(listOfFutures.toList)
    futures.map {
      listOfSecurities =>
        portfolioResponse = MergeHelper.merge(portfolio, listOfSecurities)
    }.get

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守护在此方 2024-12-24 06:54:15

您没有说明您使用的是哪个版本的 Akka,并且考虑到我使用水晶球的时间有限,我会假设您使用的是 1.2。

您可以在调用ask/?时指定超时。

(另外,你的代码有点复杂,但我已经在你的其他问题中解决了。)

干杯,

You do not state which version of Akka you're on, and given my limited time with the crystal ball I'll assume that you're on 1.2.

You can specify a Timeout when you call ask/?

(Also, your code is a bit convoluted, but that I have already solved in your other question.)

Cheers,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文