You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bart Wood <ba...@gmail.com> on 2016/02/11 22:54:57 UTC

NIO Thread Behavior With Http Connections

Will the NIO connector reuse a thread for multiple http connections in
flight?

For example, an nio thread begins processing a request for an http
connection. The thread begins blocking on a slow database socket read. Will
Tomcat let the thread be reused in flight for other http connections? If
code was storing data in thread local storage I'd imagine there could be
problems.

Thanks,
-Bart Wood

Re: NIO Thread Behavior With Http Connections

Posted by Mark Thomas <ma...@apache.org>.
On 11/02/2016 22:11, Bart Wood wrote:
> Thanks Mark.
> 
> I normally see around 20 active http connections and around 10 active NIO
> threads.  Why isn't there a 1-to-1 ratio between active http connections
> and active nio threads?  What is happening when a connection is "active"
> but it isn't being processed via the filter chain?

Connections in HTTP keep-alive are managed by the Poller thread until
there is some data on it that needs processing. Connections are then
passed to a container thread for processing. Tomcat will use
non-blocking (i.e. only allocate a thread to a conenction when there is
data to process) until the HTTP request headers have been fully read at
which point it will switch to blocking mode until the exit of the
service() method (plus some internal processing).

Mark


> 
> On Thu, Feb 11, 2016 at 2:59 PM, Mark Thomas <ma...@apache.org> wrote:
> 
>> On 11/02/2016 21:54, Bart Wood wrote:
>>> Will the NIO connector reuse a thread for multiple http connections in
>>> flight?
>>
>> No. Once a thread enters the filter chain it is dedicated to that
>> request until it exists the filter chain (plus some Tomcat internal
>> processing).
>>
>>> For example, an nio thread begins processing a request for an http
>>> connection. The thread begins blocking on a slow database socket read.
>> Will
>>> Tomcat let the thread be reused in flight for other http connections? If
>>> code was storing data in thread local storage I'd imagine there could be
>>> problems.
>>
>> ThreadLocals are problematic in a container environment for all sorts of
>> reasons. See the archives for details.
>>
>> Mark
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 


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


Re: NIO Thread Behavior With Http Connections

Posted by Bart Wood <ba...@gmail.com>.
Thanks Mark.

I normally see around 20 active http connections and around 10 active NIO
threads.  Why isn't there a 1-to-1 ratio between active http connections
and active nio threads?  What is happening when a connection is "active"
but it isn't being processed via the filter chain?

On Thu, Feb 11, 2016 at 2:59 PM, Mark Thomas <ma...@apache.org> wrote:

> On 11/02/2016 21:54, Bart Wood wrote:
> > Will the NIO connector reuse a thread for multiple http connections in
> > flight?
>
> No. Once a thread enters the filter chain it is dedicated to that
> request until it exists the filter chain (plus some Tomcat internal
> processing).
>
> > For example, an nio thread begins processing a request for an http
> > connection. The thread begins blocking on a slow database socket read.
> Will
> > Tomcat let the thread be reused in flight for other http connections? If
> > code was storing data in thread local storage I'd imagine there could be
> > problems.
>
> ThreadLocals are problematic in a container environment for all sorts of
> reasons. See the archives for details.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: NIO Thread Behavior With Http Connections

Posted by Mark Thomas <ma...@apache.org>.
On 11/02/2016 21:54, Bart Wood wrote:
> Will the NIO connector reuse a thread for multiple http connections in
> flight?

No. Once a thread enters the filter chain it is dedicated to that
request until it exists the filter chain (plus some Tomcat internal
processing).

> For example, an nio thread begins processing a request for an http
> connection. The thread begins blocking on a slow database socket read. Will
> Tomcat let the thread be reused in flight for other http connections? If
> code was storing data in thread local storage I'd imagine there could be
> problems.

ThreadLocals are problematic in a container environment for all sorts of
reasons. See the archives for details.

Mark


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