High initial latency for requests using akka connection pool

hi,
I’m implementing an micro service that communicates with other services over http. Essentially the service makes a backend http api calls to other servers to fulfill request.
I use akka http connection pool by default.

To maintain higher throughput at high(~10 sec) latency between services at a high request rates, I allow a larger connection pool size on the client side

For the first requests takes a lot of time(~20 second ) before they get forwarded upstream. reducing “max-connections” seems to lessen the delay.

can anyone suggest, how I can maintain a larger connection pool without the initial delays.
I have added the config & some code I use for the testing below.

Config: 
   akka.http.host-connection-pool {
      max-open-requests = 32768
      max-connections = 2048
      min-connections = 256
      max-retries = 0
    }
Code:

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpMethods, HttpRequest, Uri}
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContextExecutor}

object APIClient {
  def main(args: Array[String]): Unit = {
    implicit val system:ActorSystem = ActorSystem()
    implicit val materializer:ActorMaterializer = ActorMaterializer()
    implicit val executionContext:ExecutionContextExecutor = system.dispatcher

    val http = Http(system)
    val message = Await.result(http.singleRequest(HttpRequest(HttpMethods.GET,
      Uri("http://example.com:80/"))),  10.second)
    val payload = Await.result(Unmarshal(message.entity).to[String], 1.second)
    message.discardEntityBytes()

    print(payload)

    system.terminate()
  }
}

Thanks
Prasanna Josium

That sounds like an awfully high number of both min/pre-created connections and maximum. Are you sure this will help your app work better? Note that it is min/max per host you will connect to that you are configuring, not global limits for the pool. I would recommend reading up on the configuration, carefully think about the consequences, and then change a single setting at a time. Then benchmark and verify that you got the improvement you wanted. Just setting all settings you find to very high values is not a good idea.

If you enable debug level logging with akka.loglevel=debug and make sure your logger let through debug entries for akka.http you will be able to se pretty detailed log entries about what the connection pool is up to that may help you understand what does not work as you expect.

@johanandren. Thanks for the hint on running at debug mode. Apparently the client pool creation was indeed taking time. Anyway, I updated the client library to akka-http_2.11 version 10.1.3 . earlier it was at version 10.0.5; somehow this problem has disappeared after the version update.

That sounds like an awfully high number of both min/pre-created connections and maximum. Are you sure this will help your app work better?
The large number of connections were allowed to maintain throughputs at very high latencies(10+ seconds). Since the client and servers are connected as a peer to peer services in our setup, such a configuration works for us.