Hi Gaurav,

two small remarks:

 * Try using `Http().singleRequest` instead of 
`Souce.single().via(poolClientFlow).run`. Materialization (= `run` / 
`runWith`) has a certain cost that can be avoided using 
`Http().singleRequest`.
 * Using `(1 to 1000).par.foreach` to run the benchmark may lead to strange 
results. Can you say how many requests you are running parallel? How much 
threads do you have? You might be ending up issuing all requests before 
getting a single response, which means with 120 connections that on the 
server request processing has to spread 120 concurrent requests on your 
much smaller number of cores. E.g. with 4 threads, this might mean an extra 
factor of 120/4 = 30 in the latency times. If you are only interested in 
latency, try running single requests, or at least not more than your server 
can process in parallel.

Johannes

On Sunday, January 1, 2017 at 10:54:16 PM UTC+1, Gaurav Kumar wrote:
>
> 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