java 测量tomcat的排队请求数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5388210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Measuring the number of queued requests for tomcat
提问by Michael Neale
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).
因此,使用 tomcat,您可以设置 acceptCount 值(默认为 100),这意味着当所有工作线程都忙时 - 将新连接放入队列中(直到它已满,然后被拒绝)。
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).
我想要的是监视此队列中项目的大小 - 但无法确定是否有办法通过 JMX 获得此信息(即不是队列最大大小是多少 - 这只是配置,但是当前队列中的项目数)。
Any ideas appreciated.
任何想法表示赞赏。
Config for tomcat: http://tomcat.apache.org/tomcat-6.0-doc/config/http.html(search for "acceptCount")
tomcat 的配置:http: //tomcat.apache.org/tomcat-6.0-doc/config/http.html(搜索“acceptCount”)
采纳答案by JoseK
This thread on the mailinglist and the reply from Charlessuggests that no such JMX exists.
邮件列表上的这个帖子和Charles 的回复表明不存在这样的 JMX。
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.
引用 Chuck 的话:“请注意,接受队列对 Tomcat 不可见,因为它由操作系统的通信堆栈维护。”
引用 David 的话:“不幸的是,由于 Tomcat 对接受队列中的请求一无所知,......”
有没有办法获取这些信息(接受队列中有多少请求?)?
不,接受队列是完全不可见的。只有通信堆栈知道有关它的任何信息,我知道没有 API 可以将内容排队 - 因为尚未收到内容,只有连接请求。
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.
取决于您的真正问题是什么(即测量 Tomcat 尚未开始处理的接受队列中的请求),如果您正在查看“节流解决方案”,请在同一线程上查看此后续内容。
回答by kelgon
The accept queue cannot be monitored, but you can get the number of queued requests for tomcat using Executor.
无法监控接受队列,但您可以使用Executor获取 tomcat 的排队请求数。
<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.
配置maxThreads="20"表示线程池最多有 20 个 worker,可以同时处理 20 个请求。
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.
maxQueueSize="30"表示线程池最多可以排队 30 个未处理的请求。因此,您可以通过 JMX 监控 queueSize 属性以获取排队请求的数量。
But by default, the threadpool queue will never hold any requests because the default value of maxConnectionsis the value of maxThreads, which means when all workers are busy, new requests are queued in the accept queue.
但是默认情况下,线程池队列永远不会持有任何请求,因为maxConnections的默认值是maxThreads的值,这意味着当所有工作人员都忙时,新请求会在接受队列中排队。
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.
通过设置maxConnections="50",tomcat 可以接受比 maxThreads(20) 更多的请求。在上面的例子中,Executor 线程池可以处理 20 个请求,额外的 30 个请求将保留在线程池队列中,更多的请求将在接受队列中排队。
So now you can monitor the number of requests queued in threadpool using MBean 'Catalina:type=Executor,name=tomcatThreadPool' and attribute name 'queueSize'
因此,现在您可以使用 MBean 'Catalina:type=Executor,name=tomcatThreadPool' 和属性名称 'queueSize' 监视在线程池中排队的请求数