Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache + Tomcat with mod_jk: maxThread setting upon load balancing

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

like image 773
c4il Avatar asked Jul 05 '10 11:07

c4il


People also ask

Can Tomcat do load balancing?

A Tomcat cluster consists of a set of connected Tomcat Servers that work together so that, in many respects, they can be viewed as a single system. Each node, sets to perform the same task, controlled and scheduled by load balancer.

Is load balancing or clustering possible in Tomcat?

An Apache HTTP server can be used as the load balancing front end for a Tomcat cluster. This is accomplished using the mod_jk module. The mod_jk module serves as a redirector to servlet containers like Tomcat and can also be used to setup a cluster of Tomcat servers.

What is difference between mod_jk and mod_proxy?

Which connector: mod_jk or mod_proxy? mod_jk is mature, stable and extremely flexible. It is under active development by members of the Tomcat community. mod_proxy_ajp is distributed with Apache httpd 2.2 and later.

What is the use of mod_jk in Apache?

The mod_jk connector is an Apache HTTPD module that allows HTTPD to communicate with Apache Tomcat instances over the AJP protocol. The module is used in conjunction with Tomcat's AJP Connector component.


1 Answers

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

like image 125
JoseK Avatar answered Sep 21 '22 18:09

JoseK