Each connection is a stream of Request => Response, having a slow Future inside that stream will backpressure so the same client cannot push another request through that connection.
The Akka HTTP server by default limits the number of concurrent connections to 1024 (you can set it using akka.http.server.max-connections) meaning that at any given time there can be 1024 Request => Response calls running, however if those calls are all starting a Future on an execution context with 4 threads there is only 4 threads available to execute, and 1020 requests would queue up to be executed when a thread is available. If you want to limit the number of requests to a specific number and fail additional requests rather than queue them up you can do that with a custom directive like this: https://gist.github.com/johanandren/b87a9ed63b4c3e95432dc0497fd73fdb -- Johan Akka Team On Tue, Aug 1, 2017 at 1:39 PM, Josh F <[email protected]> wrote: > Hi all, > > I am just trying out akka-http and haven't been able to find much > information about how backpressure works when we use futures and run > operations async. > > For example, if I create a REST API with a route that looks like this: > ``` > val route = > (path("users") & post & entity(as[NewUser])) { user => > complete(createNewUser(user)) > } > ``` > where the method `createNewUser(user)` spawns an async operation which > interacts with a database and returns a Future[User]. > > Say the database slows down and there is a backlog of pending requests, > does akka-http recognize that the futures are taking a long time to > complete, and then slow down the number of calls to createNewUser? > > Also how does the execution context used to execute the futures affect the > backpressure? For example, if my database operations take place on an > execution context which only supports 4 concurrent operations, will > akka-http ensure that there are at most 4 pending futures/calls to > createNewUser at any time? > > Thanks for any insights on this! > > Josh > > -- > >>>>>>>>>> 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. > -- >>>>>>>>>> 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.
