Parallel execution of methods

145 Views Asked by At

I have an application that sends multiple request to my spray-can 1.3.1 server.

FireBug shows me, that these requests are triggered in parallel.

However, on the server these request are handled strictly serially.

I think I need to somehow configure the spray server to handle multiple requests in parallel - but how?

The server is started like that:

object Server extends SimpleRoutingApp{  
  def main(args: Array[String]): Unit = {
    implicit val system = ActorSystem()
    startServer("0.0.0.0", port = 8080) {
      get{
        pathSingleSlash {
          complete{
            HttpEntity(
              MediaTypes.`text/html`,
              Template.txt
            )
....
1

There are 1 best solutions below

0
Carlos Vilchez On BEST ANSWER

As Spray routing is synchronous in an actor, you will need to do something else to make it handle multiple requests in parallel.

  1. Using the Detach directive: This directive will spawn a new actor to process that request.
  2. Using an actor-per-request

You can also find other links in SO about it.