Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring the number of queued requests for tomcat

Tags:

java

jvm

tomcat

So with tomcat you can set the acceptCount value (default is 100) which means when all the worker threads are busy - new connections are placed in a queue (until it is full, after which they are rejected).

What I would like is to monitor the size of items in this queue - but can't work out if there is a way to get at this via JMX (ie not what the queue max size is - that is just config, but what the current number of items are in the queue).

Any ideas appreciated.

Config for tomcat: http://tomcat.apache.org/tomcat-6.0-doc/config/http.html (search for "acceptCount")

like image 410
Michael Neale Avatar asked Mar 22 '11 07:03

Michael Neale


People also ask

How many requests can Tomcat handle?

The default installation of Tomcat sets the maximum number of HTTP servicing threads at 200. Effectively, this means that the system can handle a maximum of 200 simultaneous HTTP requests.

How do I know how many threads Tomcat has?

By default, Tomcat sets maxThreads to 200, which represents the maximum number of threads allowed to run at any given time. You can also specify values for the following parameters: minSpareThreads : the minimum number of threads that should be running at all times. This includes idle and active threads.

Does Tomcat queue request?

If still more simultaneous requests are received, Tomcat will accept new connections until the current number of connections reaches maxConnections . Connections are queued inside the server socket created by the Connector until a thread becomes avaialble to process the connection.

What happens when Tomcat runs out of threads?

If the server doesn't have enough threads, the server will wait until a thread becomes available before processing a request. In extreme cases, those requests that get queued may never get processed, if the wait time exceeds a server timeout value.


2 Answers

This thread on the mailing list and the reply from Charles suggests that no such JMX exists.

Quote from Chuck: "Note that the accept queue is not visible to Tomcat, since it's maintained by the comm stack of the OS."

Quote from David : "Unfortunately, since Tomcat knows nothing about the requests in the accept queue,...."

Is there no way to get this information (How much requests are in the accept queue?) out?

No, the accept queue is completely invisible. Only the comm stack knows anything about it, and there are no APIs I'm aware of to queue the contents - because the content hasn't been received yet, only the connection request.

Depending on what your real problem is (i.e. for measuring requests in the accept queue which Tomcat has not yet begun procesing) if you're looking at a "throttling solution" see this follow-up on the same thread.

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

JoseK


The accept queue cannot be monitored, but you can get the number of queued requests for tomcat using Executor.

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="20" minSpareThreads="10" maxQueueSize="30" />
<Connector port="8080" protocol="HTTP/1.1" executor="tomcatThreadPool" connectionTimeout="20000" redirectPort="8443" maxConnections="50" />

The configuration maxThreads="20" means the threadpool has 20 workers at most, can process 20 requests simultaneously.

maxQueueSize="30" means that the threadpool can queued at most 30 unprocessed requests. Thus, you can monitor the queueSize attribute via JMX to get the number of queued requests.

But by default, the threadpool queue will never hold any requests because the default value of maxConnections is the value of maxThreads, which means when all workers are busy, new requests are queued in the accept queue.

By setting maxConnections="50", tomcat can accept more requests than maxThreads(20). In the example above, the Executor threadpool can handle 20 requests, the extra 30 requests will hold in the threadpool queue, any more requests further will be queue in the accept queue.

So now you can monitor the number of requests queued in threadpool using MBean 'Catalina:type=Executor,name=tomcatThreadPool' and attribute name 'queueSize'

like image 37
kelgon Avatar answered Sep 17 '22 18:09

kelgon