Play 2! framework multithreading issue

new_web_programmer

I have a standard play 2! application which communicates with the front-end via JSON. All requests are routed to controllers. Now the controllers import some heavy duty calculation classes.

So if a user requests a calculation, it might take 5 secs for the controller method to get the results back from the actual calculation class, as the calculation is iterative and takes time.

Doesn't this mean then that the server is blocked for these 5 secs? It cannot service any other user? Is 20 people are using this calculation tool simultaneously, it could become difficult for others to even load the home page served by same server due to the long queue... Am i right in this line of thinking and what could be a possible solution?

Donovan Muller

Your assumptions are correct. Play 2 uses a few thread pools which are each allocated to specific things. See here

So like you said, with the default configuration and assuming you are calling your calculation class synchronously, if more than 24 people hit your site at the same time, you Play 2 app will start to block.

I specifically mentioned 24 people because Play's default thread pool configuration is set to 1 thread per core up to a max of 24 threads. See here for more options. Hence if you block all 24 threads you're going to start having problems in terms of site responsiveness.

There are a few solutions:

  • Increase the default thread pool size (if you have a good idea of what your load will be) See here for more about that
  • Create a separate thread pool/execution context specifically (see docs on "Using other thread pools") for your heavy computation class and call it in a promise/future providing that execution context. This way the default thread pool will not be burdened with that blocking call. Again, you will have to tune that pool to your requirements.
  • Implement your heavy computation functionality as Akka Actors. See here (probably the best solution if you have the time)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jquery and play framework 2 javascript router issue

From Dev

Play Framework onStarup issue

From Dev

Play framework favicon issue

From Dev

Issue with bindFromRequest in Play! Framework 2.3

From Dev

Play Framework Connection Timeout issue

From Dev

WS play framework connection issue

From Dev

Objectify with Play Framework 2

From Dev

Issue with mysql connection while running JUnit test with play2 framework

From Dev

Issue with mysql connection while running JUnit test with play2 framework

From Dev

Play framework 2.2 Slick dependency issue

From Dev

scala play framework 2.2.6 encoding issue

From Dev

Play! Framework on dokku memory issue (heap object)

From Dev

Library import issue in Intelij Idea and Play Framework

From Dev

Play framework 2.3 ActionBuilder composition issue

From Dev

Play Framework Templates - Iterating over a list issue

From Dev

Play! Framework on dokku memory issue (heap object)

From Dev

Configure QueryDSL on Play 2 Framework

From Dev

Play Framework 2 view declaration

From Dev

Use MongoDB with Play 2 Framework

From Dev

Configure QueryDSL on Play 2 Framework

From Dev

Zend Framework 2 routing issue

From Dev

Hydrator issue in Zend Framework 2

From Dev

Scala ActiveRecord performance issue when used with play framework

From Dev

Play Framework Ning WS API encoding issue with HTML pages

From Dev

play framework evolution issue on deleting or updating model name

From Dev

julia: is it possible to play multithreading

From Dev

julia: is it possible to play multithreading

From Dev

Play Framework 2 & AngularJS - Partial Handling

From Dev

Unit Test controllers in Play 2 framework with Scala

Related Related

HotTag

Archive