On 20.05.2009 00:53, Pantvaidya, Vishwajit wrote:
>> -----Original Message-----
>> From: Rainer Jung [mailto:rainer.j...@kippdata.de]
>> Sent: Monday, May 18, 2009 11:10 PM
>> To: Tomcat Users List
>> Subject: Re: Running out of tomcat threads - why many threads in
>> RUNNABLEstage even with no activity
>>
>> On 19.05.2009 02:54, Caldarale, Charles R wrote:
>>>> From: Pantvaidya, Vishwajit [mailto:vpant...@selectica.com]
>>>> Subject: RE: Running out of tomcat threads - why many threads in
>>>> RUNNABLEstage even with no activity
>>>>
>>>> Ok - so then the question is when does tomcat transition the thread
>>>> from Running to Waiting? Does that happen after AJP drops that
>>>> connection?
>> RUNNABLE and WAITING are thread states in the JVM. They don't relate in
>> general to states inside Tomcat. In this special situation they do.
>>
>> The states you observe are both completely normal in themselves. One
>> (the stack you abbreviate with RUNNABLE) is handling a persistant
>> connection between web server and Tomcat which could send more requests,
>> but at the moment no request is being processed, the other (you
>> abbreviate with WAITING) is available to be associated with a new
>> connection that might come in some time in the future.
>>
> 
> [Pantvaidya, Vishwajit] Thanks Rainer. The RUNNABLE thread - is it a 
> connection between Tomcat and webserver, or between Tomcat and AJP? Is it 
> still RUNNABLE and not WAITING because the servlet has not explicitly closed 
> the connection yet (something like HttpServletResponse.getOutputStresm.close)

The thread handles a connection betwen the web server and Tomcat. AJP is
the protocol used on that connection.

It is runnable, because a socket read from inside the JVM puts a thread
into runnable state. The socket read is used to read the next request
and will block until data arrives over the established connection.

>>>> So could the problem be occurring here because AJP is holding on to
>>>> connections?
>>> Sorry, I haven't been following the thread that closely.  Not sure
>>> what the problem you're referring to actually is, but having a Tomcat
>>> thread reading input from the AJP connector is pretty normal.
>> The same to me. What's the problem? AJP is designed to reuse connections
>> (use persistent connections). If you do not want them to be used for a
>> very long time or like those connections to be closed when being idle,
>> you have to configure the appropriate timeouts. Look at the timeouts
>> documentation page of mod_jk.
>>
>> In general your max thread numbers in the web server layer and in the
>> Tomcat AJP pool need to be set consistently.
>>
> 
> [Pantvaidya, Vishwajit] My problem is that tomcat is running out of threads 
> (maxthreadcount=200). My analysis of the issue is:
> - threads count is exceeded because of a slow buildup of RUNNABLE threads 
> (and not because number of simultaneous http requests at some point exceeded 
> max thread count)

I don't belibve this reason. I would say thread count is exceeded,
because you allow a much higher concurrency on the web server layer.

> - most/all newly created TP-Processor threads are in RUNNABLE state and 
> remain RUNNABLE - never go back to WAITING state (waiting for thread pool)

So you are using persistent connections. There's no *problem* with that
per se. If you ae uncomfortable with it configure the timeouts in the
Tomcat connector *and* mod_jk.

> - in such case, I find that tomcat spawns new threads when a new request 
> comes in

"request" -> "connection"

> - this continues and finally tomcat runs out of threads

That's to simple, usually the "new requests" should be handled by
existing Apache processes that already have a connection to Tomcat and
will not create a new one.

> - Setting connectionTimeout in server.xml seems to have resolved the issue - 
> but I am wondering if that was just a workaround i.e. whether so many threads 
> remaining RUNNABLE indicate a flaw in our webapp i.e. it not doing whatever's 
> necessary to close them and return them to WAITING state.

No it is a misconifguration of your web server, mod_jk and Tomcat. The
use of persistent AJP connections is opaque to the web application.

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to