Measuring the number of queued requests for tomcat

前端 未结 2 891
一整个雨季
一整个雨季 2021-02-13 12:29

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

相关标签:
2条回答
  • 2021-02-13 12:41

    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'

    0 讨论(0)
  • 2021-02-13 12:50

    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.

    0 讨论(0)
提交回复
热议问题