阿帕奇+ Tomcat 与 mod_jk:负载平衡时的 maxThread 设置

发布于 2024-09-08 05:23:50 字数 526 浏览 2 评论 0原文

我在 2 台服务器上使用 mod_jk 设置了 Apache + Tomcat。每台服务器都有自己的 Apache+Tomcat 对,每个请求都由 2 台服务器上的 Tomcat 负载平衡工作程序提供服务。

我有一个关于 Apache 的 maxClient 和 Tomcat 的 maxThread 应该如何设置的问题。

默认数字是, Apache: maxClient=150, Tomcat: maxThread=200

在此配置中,如果我们只有 1 个服务器设置,则它会正常工作,因为 Tomcat 工作线程不会同时接收超过 150 个传入连接。但是,如果我们在两台服务器之间进行负载平衡,Tomcat 工作线程是否有可能收到 150 +(来自另一台服务器的某个数字)并使 maxThread 溢出为严重:所有线程(200)当前都忙

如果是这样,我应该在这种情况下设置Tomcat的maxThread=300吗?

谢谢

I have Apache + Tomcat setup with mod_jk on 2 servers. Each server has its own Apache+Tomcat pair, and every request is being served by Tomcat load balancing workers on 2 servers.

I have a question about how Apache's maxClient and Tomcat's maxThread should be set.

The default numbers are,
Apache: maxClient=150, Tomcat: maxThread=200

In this configuration, if we have only 1 server setup, it would work just fine as Tomcat worker never receives the incoming connections more than 150 at once. However, if we are load balancing between 2 servers, could it be possible that Tomcat worker receives 150 + (some number from another server) and make the maxThread overflow as SEVERE: All threads (200) are currently busy?

If so, should I set Tomcat's maxThread=300 in this case?

Thanks

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

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

发布评论

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

评论(1

后来的我们 2024-09-15 05:23:50

将 maxThreads 设置为 300 应该没问题 - 没有固定的规则。这取决于您是否看到任何连接被拒绝。

增加太多会导致高内存消耗,但众所周知,生产 Tomcat 可以运行 750 个线程。也请参见这里。 http://java-monitor.com/forum/showthread.php?t=235

您确实遇到了SEVERE 错误吗?我在 Tomcat 6.0.20 上进行了测试,当超过 maxThreads 时,它会抛出一条 INFO 消息。

INFO: Maximum number of threads (200) created for connector with address null and port 8080

在超过 acceptCount 值之前,它不会拒绝连接。默认值为 100。

来自 Tomcat 文档 http://tomcat.apache。 org/tomcat-5.5-doc/config/http.html

传入的最大队列长度
尽可能连接请求
请求处理线程正在使用中。
排队时收到的任何请求
已满将被拒绝。默认
值为 100。

它的工作方式是

1) 随着同时请求数量的增加,将创建线程直至配置的最大值(maxThreads 属性的值)。

因此,在您的情况下,此时将出现消息“创建的最大线程数 (200)”。但是,请求仍将排队等待服务。

2) 如果同时收到更多请求,它们将排队直至配置的最大值(acceptCount 属性的值)。

这样总共可以接受 300 个请求,不会失败。 (假设您的acceptCount默认为100)

3)超过这个数字会引发连接拒绝错误,直到有资源可用于处理它们。

所以你应该没问题,直到你到达第 3 步

Setting maxThreads to 300 should be fine - there are no fixed rules. It depends on whether you see any connections being refused.

Increasing too much causes high memory consumption but production Tomcats are known to run with 750 threads. See here as well. http://java-monitor.com/forum/showthread.php?t=235

Have you actually got the SEVERE error? I've tested on our Tomcat 6.0.20 and it throws an INFO message when the maxThreads is crossed.

INFO: Maximum number of threads (200) created for connector with address null and port 8080

It does not refuse connections until the acceptCount value is crossed. The default is 100.

From the Tomcat docs http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

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.

The way it works is

1) As the number of simultaneous requests increase, threads will be created up to the configured maximum (the value of the maxThreads attribute).

So in your case, the message "Maximum number of threads (200) created" will appear at this point. However requests will still be queued for service.

2) If still more simultaneous requests are received, they are queued up to the configured maximum (the value of the acceptCount attribute).

Thus a total of 300 requests can be accepted without failure. (assuming your acceptCount is at default of 100)

3) Crossing this number throws Connection Refused errors, until resources are available to process them.

So you should be fine until you hit step 3

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