Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka Http: Exceeded configured max-open-requests value of [32]

I post some data to Server using the following code

  def post(endpoint: String, entity: Strict) = {
    Http().singleRequest(HttpRequest(uri = Notifier.notificationUrl + endpoint, method = HttpMethods.POST,
      entity = entity)) onComplete {
      case Success(response) => response match {
        case HttpResponse(StatusCodes.OK, _, _, _) =>
          log.info("communicated successfully with Server")
      }
      case Failure(response) =>
        log.error("communicated failed with Server: {}", response)
    }
  }

This is called every 10 seconds when Notifier actor receives message as following

case ecMonitorInformation: ECMonitorInformation =>
  post("monitor", httpEntityFromJson(ecMonitorInformation.toJson))

Problem?

I see that Initially (around 5 requests going to server) but then it hungs up, I do not see any logging, server does not receive any data. After a while on the client side, I see following

ERROR c.s.e.notification.Notifier - communicated failed with Server: java.lang.RuntimeException: Exceeded configured max-open-requests value of [32]

What is going on? How do I fix this issue?

like image 864
daydreamer Avatar asked Aug 26 '15 17:08

daydreamer


3 Answers

If you are going to be repeatedly calling your method, you might want to consider using one of the connection pool based client methods as described here: http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/client-side/index.html

You can also set the connection pool settings in the akka-http client configuration: http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/configuration.html#akka-http-core

Search for host-connection-pool.

like image 123
Jason Martens Avatar answered Nov 14 '22 17:11

Jason Martens


I went through the docs and tried the following

val connectionFlow: Flow[HttpRequest, HttpResponse, 
        Future[Http.OutgoingConnection]] =
        Http().outgoingConnection(host = "localhost", port = 8080)

and then

  def httpPost(uri: String, httpEntity:Strict) {
    val responseFuture: Future[HttpResponse] =
      Source.single(HttpRequest(uri = "/monitor", method = HttpMethods.POST, entity=httpEntity))
        .via(connectionFlow)
        .runWith(Sink.head)

    responseFuture onComplete {
      case Success(response) => log.info("Communicated with Server: {}", response)
      case Failure(failure) => log.error("Communication failed with Server: {}", failure)
    }

and this worked for me

like image 33
daydreamer Avatar answered Nov 14 '22 18:11

daydreamer


You can also overcome this error by upping the max-open-requests property of akka which is 32 by default.

The property to change will be:

akka.http.host-connection-pool.max-open-requests = 64

The only caveat is that this will fail when the client opens more concurrent connections than what the new value of that parameter is, in this example if the open connections exceed 64, you will get the same error.

like image 3
harpresing Avatar answered Nov 14 '22 19:11

harpresing