How can Akka HTTP be configured to accept more concurrent connections?

1,991 views
Skip to first unread message

Benjamin Geer

unread,
Nov 29, 2016, 12:59:55 PM11/29/16
to Akka User List

I'm having trouble understanding how to configure Akka HTTP (version 2.4.11) to accept more than about 130 concurrent connections. My minimal test case is this example from the docs, in which I've tried to set relevant configuration options:


import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory

import scala.io.StdIn

object WebServer {
    def main(args: Array[String]) {

        val parallel = 1024

        implicit val system = ActorSystem("my-system", ConfigFactory.parseString(
            s"""
               |akka {
               |    http {
               |        server {
               |            backlog = $parallel
               |            pipelining-limit = $parallel
               |        }
               |
               |        host-connection-pool {
               |            max-connections = $parallel
               |            max-open-requests = $parallel
               |            max-connections = $parallel
               |        }
               |    }
               |}
             """.stripMargin))

        implicit val materializer = ActorMaterializer()
        // needed for the future flatMap/onComplete in the end
        implicit val executionContext = system.dispatcher

        val route =
            path("hello") {
                get {
                    complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
                }
            }

        val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

        println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
        StdIn.readLine() // let it run until user presses return
        bindingFuture
            .flatMap(_.unbind()) // trigger unbinding from the port
            .onComplete(_ => system.terminate()) // and shutdown when done
    }
}


I'm testing it with ab (on Mac OS X with a 4 GHz Intel Core i7):


$ ab -n 2000 -c 150 http://localhost:8080/hello
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
apr_socket_recv: Connection reset by peer (54)


When the value of -c is greater than about 130, I always get Connection reset by peer immediately, regardless of the configuration options above.


What am I missing?

Rafał Krzewski

unread,
Nov 29, 2016, 6:16:23 PM11/29/16
to Akka User List
I think you are looking for akka.http.server.max-connections. See [1]

akka.http.host-connection-pool are client settings for per-host connection pooling.

Cheers,
Rafał

Benjamin Geer

unread,
Nov 30, 2016, 9:43:07 AM11/30/16
to Akka User List
The default value of akka.http.server.max-connections is 1024. Increasing it to 2048 makes no difference, I get the same result. In any case, I don't see why I would need more than a maximum of 1024 connections to handle 150 concurrent connections as in my example.

Benjamin Geer

unread,
Nov 30, 2016, 11:25:05 AM11/30/16
to Akka User List
After more investigation, it appears that this is a Mac OS X kernel configuration issue, not an Akka issue.

Konrad Malawski

unread,
Nov 30, 2016, 2:05:06 PM11/30/16
to akka...@googlegroups.com, Benjamin Geer
Thanks for the info that it was a Mac issue.
Always benchmark on the actual hardware you'll be deploying to (usually linux) if checking scalability / performance :)

-- 
Konrad `ktoso` Malawski
Akka @ Lightbend

On 30 November 2016 at 17:25:08, Benjamin Geer (benjam...@gmail.com) wrote:

After more investigation, it appears that this is a Mac OS X kernel configuration issue, not an Akka issue.
--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages