演员入BufferOverflowException当发送的单

0

的问题

我想送几百http请求从akka演员但是我得到

akka.stream.BufferOverflowException: Exceeded configured max-open-requests value of [16]. This means that the request queue of this pool (HostConnectionPoolSetup(places.api.here.com,443,ConnectionPoolSetup(ConnectionPoolSettings(16,1,5,16,1,Duration.Inf,100 milliseconds,2 minutes,30 seconds,ClientConnectionSettings(Some(User-Agent: akka-http/10.2.0)...

这个应用程序。conf

   http {
          host-connection-pool {
            max-connections = 16
            min-connections = 1
            max-open-requests = 16
          }
        }

这个代码

override def receive: Receive = {
      case Foo(_) => 
       val res: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://..."))
   // do something for the result

我试图控制由国家e。克

override def receive: Receive = run(0)
def run(openRequests: Int) : Receive = {
  case Foo(_) if openRequests <= 16 => 
     context.become(run(openRequests + 1))
       val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://..."))
       responseFuture.foreach(context.become(run(openRequests - 1)))
        //...

不管怎么样,我得到了同样的例外 BufferOverflowException

任何意见将会极大的赞赏

akka akka-http akka-stream scala
2021-10-22 05:31:19
1

最好的答案

2

使用 context 异步的内部 Future 是个坏主意。 context 它是唯一有效的话期间演员。

错误是, context.become(run(openRequests - 1)) 使用价值的 openRequests 在时间 Future 创建,不值时它被称为。 因此,当第一个请求完成,它将呼叫 context.become(run(-1)) (这显然是伪造的),虽然可能有15起未决请求。

解决的办法是发送私人消息,以在自己的 foreach 而不是呼叫 context.become 直接。 当演员处理这一信息就会递减 目前 请求数,和发出新的请求,如果有必要的。

2021-10-22 07:52:58

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................