You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by sol myr <so...@yahoo.com> on 2010/11/29 17:23:31 UTC

(Tomcat) Does NIO connector make a difference outside of 'Comet' ?

Hi,

I've just started looking into the NIO Connector.
And I see why it's great to combine NIO+Comet...
But does it makes any difference outside of Comet?

1) Namely, if I only have old-fashioned Servlets (not a "CometProcessor") - will it improve performance to use NIO connector (versus the good old HTTP connector)?
I ran a test with such old-fashioned Servlet, and got the impression that Tomcat opens a thread-per-request. So it didn't take advantage of the "non blocking" feature of NIO.
But then again, perhaps it takes advantage of other NIO features? Such as native buffers, etc?

2) Also, what about static resources (such as images), assuming they're distributed by Tomcat (with no Apache server at the front)?
Will they be perform better with NIO connector?

Thanks :)



      

Re: (Tomcat) Does NIO connector make a difference outside of 'Comet' ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sol,

On 11/29/2010 11:23 AM, sol myr wrote:
> I've just started looking into the NIO Connector.
> And I see why it's great to combine NIO+Comet...
> But does it makes any difference outside of Comet?

Some data: please read the initial slides to understand exactly what has
been tested.

http://people.apache.org/~schultz/ApacheCon%20NA%202010/ApacheCon%20NA%202010%20Slides.pdf

NB: Mladen has insinuated that my tests were entirely useless because
everything was localhost :)

Good advice: test it under your own configuration to see if you'll get
better performance. Remember that performance also includes GC activity,
memory usage, and CPU usage - not simply response time and/or throughput.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzz3C4ACgkQ9CaO5/Lv0PDhQQCdFoRvRz6YnmxlKpNeCb4QFXoX
GRYAoK0+hKKufZ+FDV/S43+HDBndOt2W
=o0WY
-----END PGP SIGNATURE-----

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


Re: (Tomcat) Does NIO connector make a difference outside of 'Comet' ?

Posted by Michael Ludwig <mi...@gmx.de>.
Caldarale, Charles R schrieb am 29.11.2010 um 22:47 (-0600):
> > From: Michael Ludwig [mailto:milu71@gmx.de] 
> 
> > can we say that:
> 
> > (a) blocking IO requires one thread (or, in some other
> > server environments, one process) per socket
> 
> Well, sort of.  The actual requirement is one thread per established
> HTTP connection, where a connection is typically done using sockets.
> There's no switching overhead until traffic arrives on the connection,
> and the waiting thread is activated to process it.  Otherwise, the
> thread is stalled until either input arrives or a timeout occurs.
> 
> > (b) non-blocking IO allows a thread or process to switch
> > between sockets, thus providing scheduling and concurrency
> > on just another level, possibly with advantages?
> 
> Again, kind of.  There's one thread that polls the connections for
> traffic

Which is where the non-blocking comes in, because if it were blocking
the thread would block on checking the connection (reading from the
socket).

> and when something arrives, it passes the connection off to a
> request handler to do something useful with it.  When the request
> handling is finished, the worker thread goes back to the pool, and
> control of the connection is relinquished to the polling thread.
> Consequently, you only need as many threads as there are active
> requests, as opposed to needing one per active (and usually idle)
> connection.

That makes sense. Thanks.

> I suspect you'd be hard pressed to measure any switching difference
> between the two (NIO may actually be slightly worse); the main
> advantage of NIO is that fewer resources (threads) are tied up doing
> nothing while waiting for clients to send something.

-- 
Michael Ludwig

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


RE: (Tomcat) Does NIO connector make a difference outside of 'Comet' ?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Michael Ludwig [mailto:milu71@gmx.de] 
> Subject: Re: (Tomcat) Does NIO connector make a difference outside of 'Comet' ?

> can we say that:

> (a) blocking IO requires one thread (or, in some other
> server environments, one process) per socket

Well, sort of.  The actual requirement is one thread per established HTTP connection, where a connection is typically done using sockets.  There's no switching overhead until traffic arrives on the connection, and the waiting thread is activated to process it.  Otherwise, the thread is stalled until either input arrives or a timeout occurs.

> (b) non-blocking IO allows a thread or process to switch
> between sockets, thus providing scheduling and concurrency
> on just another level, possibly with advantages?

Again, kind of.  There's one thread that polls the connections for traffic, and when something arrives, it passes the connection off to a request handler to do something useful with it.  When the request handling is finished, the worker thread goes back to the pool, and control of the connection is relinquished to the polling thread.  Consequently, you only need as many threads as there are active requests, as opposed to needing one per active (and usually idle) connection.

I suspect you'd be hard pressed to measure any switching difference between the two (NIO may actually be slightly worse); the main advantage of NIO is that fewer resources (threads) are tied up doing nothing while waiting for clients to send something.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


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


Re: (Tomcat) Does NIO connector make a difference outside of 'Comet' ?

Posted by Michael Ludwig <mi...@gmx.de>.
Mark Thomas schrieb am 29.11.2010 um 16:34 (+0000):
> On 29/11/2010 16:23, sol myr wrote:
> > I've just started looking into the NIO Connector.
> > And I see why it's great to combine NIO+Comet...
> > But does it makes any difference outside of Comet?
> 
> Yes.
> 
> > 1) Namely, if I only have old-fashioned Servlets (not a
> > "CometProcessor") - will it improve performance to use
> > NIO connector (versus the good old HTTP connector)?
> 
> That depends on how you define performance.
> 
> > I ran a test with such old-fashioned Servlet, and got
> > the impression that Tomcat opens a thread-per-request.
> > So it didn't take advantage of the "non blocking"
> > feature of NIO.
> 
> Thread per request - yes (it has to due to how the servlet
> API is defined) but not a thread per connection. That is a
> big difference.

I'd like to understand this non-blocking IO thing. Given Sol
Myr's example, can we say that:

(a) blocking IO requires one thread (or, in some other
server environments, one process) per socket, so the OS
gets to switch between processes or threads a lot since
they're likely to be waiting on IO; whereas

(b) non-blocking IO allows a thread or process to switch
between sockets, thus providing scheduling and concurrency
on just another level, possibly with advantages?

Thanks for your comments.

-- 
Michael Ludwig

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


Re: (Tomcat) Does NIO connector make a difference outside of 'Comet' ?

Posted by Mark Thomas <ma...@apache.org>.
On 29/11/2010 16:23, sol myr wrote:
> Hi,
> 
> I've just started looking into the NIO Connector.
> And I see why it's great to combine NIO+Comet...
> But does it makes any difference outside of Comet?

Yes.

> 
> 1) Namely, if I only have old-fashioned Servlets (not a "CometProcessor") - will it improve performance to use NIO connector (versus the good old HTTP connector)?

That depends on how you define performance.

> I ran a test with such old-fashioned Servlet, and got the impression that Tomcat opens a thread-per-request. So it didn't take advantage of the "non blocking" feature of NIO.

Thread per request - yes (it has to due to how the servlet API is
defined) but not a thread per connection. That is a big difference.

> But then again, perhaps it takes advantage of other NIO features? Such as native buffers, etc?

Nope.

> 2) Also, what about static resources (such as images), assuming they're distributed by Tomcat (with no Apache server at the front)?
> Will they be perform better with NIO connector?

It depends. sendfile is available but that doe snot guarantee better
static content performance.

Mark

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