views:

78

answers:

1

Hi, 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

+2  A: 

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

JoseK
Very nice point about acceptCount! This should work perfectly. Sorry I should have been more clear in my question, but it was my general what-if type question. I had originally had maxThread=150 and got SEVERE error. So I changed it back to the default 200, but then I realized 200 wouldn't be enough either for the reason that I have described in the question. Thanks a lot for the answer. It all make sense now.
c411