简体   繁体   English

带有mod_jk的Apache + Tomcat:负载平衡时的maxThread设置

[英]Apache + Tomcat with mod_jk: maxThread setting upon load balancing

I have Apache + Tomcat setup with mod_jk on 2 servers. 我在2台服务器上安装了带有mod_jk的Apache + Tomcat。 Each server has its own Apache+Tomcat pair, and every request is being served by Tomcat load balancing workers on 2 servers. 每个服务器都有自己的Apache + Tomcat对,每个请求由2台服务​​器上的Tomcat负载平衡工作者提供服务。

I have a question about how Apache's maxClient and Tomcat's maxThread should be set. 我有一个关于如何设置Apache的maxClient和Tomcat的maxThread

The default numbers are, Apache: maxClient=150, Tomcat: maxThread=200 默认数字是, 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. 在这种配置中,如果我们只有1个服务器设置,那么它可以正常工作,因为Tomcat工作者永远不会一次接收超过150个的传入连接。 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 ? 但是,如果我们在两台服务器之间进行负载平衡,那么Tomcat工作者是否可能收到150 +(来自另一台服务器的某些数字)并使maxThread溢出为SEVERE: All threads (200) are currently busy

If so, should I set Tomcat's maxThread=300 in this case? 如果是这样,在这种情况下我应该设置Tomcat的maxThread=300吗?

Thanks 谢谢

Setting maxThreads to 300 should be fine - there are no fixed rules. 将maxThreads设置为300应该没问题 - 没有固定的规则。 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. 增加太多导致高内存消耗,但已知生产Tomcats运行750个线程。 See here as well. 在这里也可以看到。 http://java-monitor.com/forum/showthread.php?t=235 http://java-monitor.com/forum/showthread.php?t=235

Have you actually got the SEVERE error? 你真的得到了SEVERE错误吗? I've tested on our Tomcat 6.0.20 and it throws an INFO message when the maxThreads is crossed. 我已经在我们的Tomcat 6.0.20上进行了测试,当超过maxThreads时它会抛出一条INFO消息。

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. 在超过acceptCount值之前,它不会拒绝连接。 The default is 100. 默认值为100。

From the Tomcat docs http://tomcat.apache.org/tomcat-5.5-doc/config/http.html 来自Tomcat文档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. 默认值为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). 1)随着并发请求数量的增加,线程将创建到配置的最大值(maxThreads属性的值)。

So in your case, the message "Maximum number of threads (200) created" will appear at this point. 因此,在您的情况下,此时将显示消息“最大线程数(200)已创建”。 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). 2)如果收到更多的同时请求,它们将排队到配置的最大值(acceptCount属性的值)。

Thus a total of 300 requests can be accepted without failure. 因此,总共可以接受300个请求而不会失败。 (assuming your acceptCount is at default of 100) (假设您的acceptCount默认为100)

3) Crossing this number throws Connection Refused errors, until resources are available to process them. 3)越过此数字会抛出Connection Refused错误,直到资源可用于处理它们。

So you should be fine until you hit step 3 所以你应该没事,直到你完成第3步

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM