播放框架和线程池 [英] Play Framework and Threadpools

查看:101
本文介绍了播放框架和线程池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Play框架向我的应用程序公开的线程数是否有限制? Play应用程序中的线程大小是如此珍贵吗?如果我使用自己在应用程序中创建的线程池而不使用Play提供的线程池,该怎么办.这是推荐的吗?任何人都可以谈谈Play如何处理线程吗?

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?

推荐答案

Play应用程序中的线程限制基本上必须由分配给VM的最大内存确定.每个线程都将消耗相当多的内存,因为它们拥有自己的堆栈.本质上,可能的最大线程数取决于您将传递给JVM的参数以及计算机上的总RAM等.

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.

您应该让Play为您管理线程.配置文档位于此处. Play设计的一部分在于最大程度地减少所需的线程数,因此,除非您进行大量阻塞调用,否则您无需触摸它.

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使用Akka处理线程.可以在

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

根据参考配置,

默认情况下 播放的parallelism-factor设置为1.这意味着默认情况下,Play的线程池等于可用处理器的数量,最大为24.

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.

这篇关于播放框架和线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆