如何增加tomcat线程池中的线程数?

发布于 2024-11-16 09:46:20 字数 55 浏览 3 评论 0原文

我只是想知道如何增加tomcat线程池中的线程数? 以及设置最大值是多少,我不知道什么是合适的?

i just want to know How to increase number of threads in tomcat thread pool ?
and what number to set the max too, i don't know what's appropriate ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

闻呓 2024-11-23 09:46:20

听起来您应该保留默认值;-)

说真的:您应该设置的最大并行连接数取决于您预期的 tomcat 使用情况以及服务器上的核心数量。您的处理器上有更多核心 =>可以执行更多的并行线程。

请参阅此处如何配置...

Tomcat 10:https://tomcat。 apache.org/tomcat-10.0-doc/config/executor.html

Tomcat 9:https://tomcat.apache.org/tomcat-9.0-doc/config/executor.html

Tomcat 8:https://tomcat.apache.org/tomcat-8.0-doc/config/executor.html

Tomcat 7:https://tomcat.apache.org/tomcat-7.0-doc/config/executor .html

Tomcat 6:https://tomcat.apache.org/tomcat-6.0-doc/config/executor.html

Sounds like you should stay with the defaults ;-)

Seriously: The number of maximum parallel connections you should set depends on your expected tomcat usage and also on the number of cores on your server. More cores on your processor => more parallel threads that can be executed.

See here how to configure...

Tomcat 10: https://tomcat.apache.org/tomcat-10.0-doc/config/executor.html

Tomcat 9: https://tomcat.apache.org/tomcat-9.0-doc/config/executor.html

Tomcat 8: https://tomcat.apache.org/tomcat-8.0-doc/config/executor.html

Tomcat 7: https://tomcat.apache.org/tomcat-7.0-doc/config/executor.html

Tomcat 6: https://tomcat.apache.org/tomcat-6.0-doc/config/executor.html

泅渡 2024-11-23 09:46:20

您必须根据您的环境进行调整。

有时,增加积压的大小 (acceptCount) 而不是最大线程数更有用。

比如说,在某些情况下,您可以获得更好的性能,而不是

<Connector ... maxThreads="500" acceptCount="50"

使用它

<Connector ... maxThreads="300" acceptCount="150"

,因为争论资源的线程会更少,并且积压队列会被更快地消耗。

但无论如何,您都必须进行一些基准测试才能真正知道什么是最好的。

You would have to tune it according to your environment.

Sometimes it's more useful to increase the size of the backlog (acceptCount) instead of the maximum number of threads.

Say, instead of

<Connector ... maxThreads="500" acceptCount="50"

you use

<Connector ... maxThreads="300" acceptCount="150"

you can get much better performance in some cases, cause there would be less threads disputing the resources and the backlog queue would be consumed faster.

In any case, though, you have to do some benchmarks to really know what is best.

不必了 2024-11-23 09:46:20

来自 Tomcat 文档

ma​​xConnections
当达到此数量时,服务器将接受但不处理另一个连接。
一旦达到限制,操作系统仍可以根据acceptCount 设置接受连接。 (当所有可能的请求处理线程都在使用时,传入连接请求的最大队列长度。队列已满时收到的任何请求都将被拒绝。默认值为 100。)对于 BIO,默认值为 maxThreads 的值,除非 Executor在这种情况下使用默认值将是来自执行器的 maxThreads 值。对于 NIO 和 NIO2,默认值为 10000。对于 APR/native,默认值为 8192。请注意,对于 Windows 上的 APR/native,配置的值将减少到小于或等于 maxConnections 的 1024 的最高倍数。这样做是出于性能原因。

最大线程
此连接器要创建的请求处理线程的最大数量,因此决定了可以处理的并发请求的最大数量。如果未指定,则此属性设置为 200。如果执行程序与此连接器关联,则此属性将被忽略,因为连接器将使用执行程序而不是内部线程池执行任务。

From Tomcat Documentation

maxConnections
When this number has been reached, the server will accept, but not process, one further connection.
once the limit has been reached, the operating system may still accept connections based on the acceptCount setting. (The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.) For BIO the default is the value of maxThreads unless an Executor is used in which case the default will be the value of maxThreads from the executor. For NIO and NIO2 the default is 10000. For APR/native, the default is 8192. Note that for APR/native on Windows, the configured value will be reduced to the highest multiple of 1024 that is less than or equal to maxConnections. This is done for performance reasons.

maxThreads
The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文