Hi hAkkers,

I'm using Akka HTTP Client to send a simple request to a local server and I 
am observing high latencies. The URL is a simple one with no processing and 
the server is local, machine is high end too.
Latency observed is ~8-10ms. Instead, it should be ~0-1ms. When using other 
libraries/methods I get the response in 1ms. Below is the code:

object Main extends Logging {
  def main(args: Array[String]): Unit = {
    implicit val system = ActorSystem()
    implicit val materializer = ActorMaterializer()

    val poolClientFlow = Http().cachedHostConnectionPool[Int]("localhost")

    logger.info("warming up...")
    (1 to 1000).par.foreach(id => send(id, poolClientFlow))

    Thread.sleep(3000)

    logger.info("starting...")
    (1 to 1000).par.foreach(id => send(id, poolClientFlow))
    logger.info("done...")

    system.terminate()
  }

  val uri = "/"

  private def send(id: Int, poolClientFlow: Flow[(HttpRequest, Int), 
(Try[HttpResponse], Int), HostConnectionPool])(implicit system: ActorSystem, 
materializer: ActorMaterializer): Unit = {
    import system.dispatcher
    val source: Source[(Try[HttpResponse], Int), NotUsed] = 
Source.single(HttpRequest(uri = uri) -> id).via(poolClientFlow)
    val start: Long = System.nanoTime()
    val future: Future[(Int, String)] = source.runWith(Sink.head).flatMap {
      case (Success(response), id: Int) =>
        Unmarshal(response.entity).to[String].map(result => (id, result))
      case _ =>
        throw new Exception("FAILED")
    }
    val result: (Int, String) = Await.result(future, 10 seconds)
    logger.info(s"TIME: ${(System.nanoTime() - start) / 1000000} ID: 
${result._1}")
  }
}



application.conf is:

akka {
  loglevel = DEBUG
}

akka.http {
  host-connection-pool {
    max-connections = 120
    min-connections = 1
    max-retries = 0
    max-open-requests = 4096
    pipelining-limit = 1
    idle-timeout = 30 s
    client = {
      connecting-timeout = 10s
      idle-timeout = 60 s
    }
  }
}



It's a simple hello world code but I am not sure the reason for low 
performance.

Thanks,
GK

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to