Search code examples
akkaakka-io

How to obtain high outbound concurrency with Akka IO(Http)


Given:

val system = ActorSystem("test")
val http = IO(Http)(system)
def fetch = http ! HttpRequest(GET, "http://0.0.0.0:8080/loadtest")

If I were to do:

(0 to 25).foreach(_ => fetch)

I would expect that the code would fire off 25 asynchronous requests. What happens instead is that four requests are set off. They wait for a response. When the response to all 4 comes back then four more are sent off until all 25 are processed.

I tried tweaking with Spray's configuration to create a custom dispatcher but this had no effect...

outbound-http-dispatcher {
  type = Dispatcher
  executor = "thread-pool-executor"
  throughput = 250
}

spray.can {
  host-connector-dispatcher = outbound-http-dispatcher
  manager-dispatcher = outbound-http-dispatcher
}

How can I configure Akka/Spray to send off all 25 requests asynchronously?

Using: Akka 2.2.3, Spray 1.2.0


Solution

  • You are running into the max connections configuration setting for the host-connector in spray (it is 4 by default).

    This is how you change it: spray.can.host-connector.max-connections=25