Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework and Threadpools

Is there a limit on the number of threads that Play framework exposes to my application? Is the thread size inside Play app so darn precious? What if I use a thread pool that I create by myself in the application and not use the one provided by Play. Is this recommended? Can anyone please throw some light on how Play handles threads?

like image 492
joesan Avatar asked May 29 '15 16:05

joesan


1 Answers

The limit of threads in your Play application would have to basically be determined by the maximum memory allocated to the VM. Threads will consume a fair bit of memory each, since they get their own stack. Essentially, the maximum number of threads possible depends on the arguments you will pass to the JVM and the total RAM on your computer, etc.

You should let Play manage threads for you. The configuration documentation is located here. Part of the design of Play deals in minimizing the number of threads you need, so unless you're doing a lot of blocking calls you shouldn't need to touch it.

Play uses Akka to handle the threading. The configuration for the internal actor system can be found here. The juicy part in this is the parallelism-factor and parallelism-max. If we look at the well commented reference configuration for Akka:

# The parallelism factor is used to determine thread pool size using the
# following formula: ceil(available processors * factor). Resulting size
# is then bounded by the parallelism-min and parallelism-max values.
parallelism-factor = 3.0

# Max number of threads to cap factor-based parallelism number to
parallelism-max = 64

Play's parallelism-factor by default is set to 1, based on the reference configuration. This means that by default, Play will have a thread pool equal to the number of processors available, to a maximum of 24.

like image 134
Jonathan Boudreau Avatar answered Sep 18 '22 04:09

Jonathan Boudreau