Can't execute more than 4 requests in parallel

63 views
Skip to first unread message

Leonti Bielski

unread,
Aug 27, 2016, 2:01:39 PM8/27/16
to Akka User List
Hi! I'm trying to load test my application using Akka Http client but failing to execute more than 4 requests in parallel.
The steps of the test:
1. Create a user
2. Authenticate the user
3. Prepare a request and create a sequence of it to execute in parallel.

Here is the code of the function doing the upload:


def upload() = {
 
val username = "ci_user_" + java.util.UUID.randomUUID()
 
val createUserRequest = CreateUserRequest(username, "password")

 
val toReceiptRequest: (MessageEntity, String, String) => HttpRequest = (requestEntity, userId, accessToken) => {
   
HttpRequest(method = HttpMethods.POST,
      uri
= s"http://localhost:9000/user/${userId}/receipt",
      entity
= requestEntity,
      headers
= List(Authorization(OAuth2BearerToken(accessToken))))
 
}

 
val uploadReceipt: (HttpRequest) => Future[StatusCode] = request => {
   
val start = System.currentTimeMillis()
   
println("Starting to upload receipt")

   
Http().singleRequest(request).map(response => {
     
println(response.status)
     
val end = System.currentTimeMillis()
     
println(s"Receipt uploaded in ${(end - start)}ms")
      response
.status
   
})
 
}

 
val requests: Future[Seq[HttpRequest]] = for {
    userInfo
: UserInfo <- createUser(createUserRequest)
    accessToken
: OAuth2AccessTokenResponse <- authenticateUser(userInfo)
    requestEntity
: MessageEntity <- createImageFileContent()
 
} yield Seq.fill(10)(toReceiptRequest(requestEntity, userInfo.id, accessToken.accessToken))

 
val result: Future[Seq[StatusCode]] = requests.flatMap(requests => Future.sequence(requests.map(request => uploadReceipt(request))))
  result
}

I'm doing this at the top of the class, so I should have 200 threads available:

implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(200))



The full code is here if it might hold a clue:
http://pastebin.com/iYsyu0En

How can I make it execute requests in parallel?

Thanks!
Leonti

Jan-Pieter van den Heuvel

unread,
Aug 29, 2016, 2:47:47 AM8/29/16
to Akka User List
Hi Leonti,

Akka Http Client uses connection pooling for the Request-Level Client API and the default number of connections to a single host is 4. My guess is that this results in the limitation you are experiencing. Try to increase the max-connections configuration parameter and see if that helps. For more details, have a look at the reference configuration in the documentation. Hope this helps.

Kind regards,
Jan-Pieter

Op zaterdag 27 augustus 2016 20:01:39 UTC+2 schreef Leonti Bielski:

Leonti Bielski

unread,
Aug 29, 2016, 9:43:16 AM8/29/16
to Akka User List
Hi Jan-Pieter!
Thanks for the reply!

Yes, it seems like this is the issue, although I'm still having trouble changing the behaviour.
I added this to my application.conf:
akka.http.client.host-connection-pool.max-connections = 100

But requests are still limited to 4 at a time.

println("max connections " + ConfigFactory.load().getInt("akka.http.client.host-connection-pool.max-connections"))
Prints 100, so config is loaded.

When I do Http(), does it load the config or do I have to somehow pass it manually?


Cheers,
Leonti

Andrew Gaydenko

unread,
Aug 29, 2016, 2:16:20 PM8/29/16
to Akka User List
May be without client ?

Leonti Bielski

unread,
Aug 30, 2016, 4:56:28 AM8/30/16
to Akka User List
Yes Andrew, that was it!

Thanks!
Reply all
Reply to author
Forward
0 new messages