Tomcat Thread Monitoring Mbeans Description

2019-06-03 20:21发布

问题:

In thread related Mbeans of Tomcat I see under Catalina.ThreadPool.

there are different attributes viz. maxThreads, currentThreadCount, currentThreadsBusy etc.

So, where can I get the description of these Mbean attributes, what each of these attribute is indicating, I need to include this in my monitoring automation code, Which will provide the Thread utilization stats.

also possible I would like to see the Source code, where can I get it?

When I see the Mbean class name (through jconsole) it shows as org.apache.tomcat.util.modeler.BaseModelMBean, but when I go through the source code of BaseModelMBean I see there are neither fields or data members representing these attributes mentioned above part of this class or the interfaces it implements.

Then which implementation of the Mbean is being represented here??

回答1:

maxThreads, currentThreadCount, currentThreadsBusy JMX properties relate to a thread pool the Tomcat Connector uses to handle incoming requests. You can see the threads usually named http-nio-[port-number]-exec-[sequence-number] in your application thread list. When a request arrives to the Connector, the latter assigns, by the means of a thread pool, a certain thread to it, this thread will by "busy" until the request is handled. So, currentThreadsBusy reflects the number of the requests that are being currently handled.

maxThreads defines the number of the threads you don't want to exceed in any case. When currentThreadsBusy counter reaches maxThreads threshold, no more requests could be handled, and the application chokes.

currentThreadCount indicates the amount of threads the thread pool has right now, both busy and free, thread pool will terminate some threads if they are unused for a certain period of time or create new ones, up to maxThreads, if there is a demand, see the details below.

"Under the hood", since Tomcat 7, it is org.apache.tomcat.util.net.AbstractEndpoint that is, among other things, responsible for thread management. If it uses java.util.concurrent.ThreadPoolExecutor as a thread pool (default choice), maxThreads maps to the ThreadPoolExecutor's maximumPoolSize, currentThreadsBusy - to activeCount, and currentThreadCount - to poolSize.

Having said that, currentThreadsBusy is the best choice for monitoring a web application's health. maxThreads is more like a static value (unless you change it dynamically, at will). currentThreadCount may deliver some helpful information, with a certain time lag.



回答2:

You can read about getCurrentThreadCount(), getCurrentThreadsBusy() and maxThreads in JIoEndpoint: Javadoc or Source