You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ja kub <jj...@gmail.com> on 2016/05/23 15:38:38 UTC

nio connector

Hello,

In which scenario nio connector will outerform basic io connector and vice
versa ?

What would be high level design of corresponding performance tests showing
advantages of each connector ?

BR
Jakub

Re: nio connector

Posted by Ja kub <jj...@gmail.com>.
Christopher, Great Thanks.
BR
Jakub

On Tue, May 24, 2016 at 4:33 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Jakub,
>
> On 5/23/16 8:03 PM, Ja kub wrote:
> > Christopher, Thx for response, pleas confirm or deny if I
> > understand well.
> >
> > BIO uses thread per http connection (tcp connection). (Shame I
> > didn't realize it!) NIO uses thread per request.
>
> It's more complicated than that, but very close.
>
> > With NIO thread is returned to pool as soon as request is finished
> > (doGet ends).
>
> Yes.
>
> > With BIO thread is returned to pool only when tcp connection is
> > closed !!!
>
> Yes, but even HTTP keepalive has a timeout, and the connection will be
> dropped after that timeout, releasing the thread.
>
> > Given http://kb.mozillazine.org/Network.http.keep-alive.timeout -
> > Amount of time in seconds to keep keep-alive connections alive.
> > Default: 115 seconds. default tomcat keepAliveTimeout 60 s default
> > tomcat maxThreads is 200 With 200 browsers with ajax pooling server
> > every 50 seconds tomcat connector thread pool will be depleted and
> > client no 201 will not be able to connect to tomcat ?
>
> Yes.
>
> > So with default configuration tomcat 7 will have problem with just
> > 201 on-line clients of an ajax application (with only 4
> > requests/second) ?
>
> If the browse doesn't close those HTTP connections from the Ajax
> clients, the yes, you can trivially DOS your server.
>
> > Why is BIO connector still default one in tomcat 7 server.xml?
>
> Because it was the default when Tomcat 7 shipped and changing defaults
> that are that important is a big deal. You are welcome to change it
> yourself.
>
> > Is there any problem with backward compatibility (don't think so,
> > cause than BIO wouldn't be totally removed in 8.5, but left
> > available ) ?
>
> BIO is 100% gone in Tomcat 8.5.
>
> The protocol (HTTP) and the API (servlet) are still identical, so
> there should be no problems for your application in general.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBCAAGBQJXQ71tAAoJEBzwKT+lPKRYZHIP/jbN3vhtHkLHny6kNXguh5Pl
> BpwaRNHojlOqzXQUWidrmQpQPZ+8GKSUcJp3hcwCklRYNqLS9GdENodwYJFhyKRE
> jVFG2KRSVI+difWKpuX+gIVEiFxUV/fQ+1ZhrNUXusElprqku+s15dqsgI5GYu3u
> BlvEUVs5/rYG+KqZFCYXw5lpe/pRd3fs+zNJFKOXYqY2qQRICzXQJDCvICgPp7fZ
> I804dDIR8mhOfffemgaB1OyOy4F3NsPodBA2LsVcbJpecfQy3vWPCSNkLmUT1Nee
> a30Q6VjdMsq+w/C1cGnxxDwxqoK8mXnyUEIH8GmtGyiak4lzJzSXmqO3RjqXHwm8
> tJnJdWNK+lP4EY9dJQrzv4NokZN+rYb9WCogMXKHvTdpmWDzMiMQs3zyFPkbLfKw
> EGeZKaY3zJFIGltPvpk/QRj0+VcXh6x3g9TUtR8ypoETrchAszCJPVUYy8H5yBaX
> N3H9wrJ2OlFmjrXKNRsY1OtuTABiKjVZXtfuTIgyK4tSddM+4gme5iydmURRISMY
> 7G1UQRNtLng8WFpCaIPrrBVUgXXrfkmYu9pEyjgzuMNc1/gf5stQNWH/AagOVt+J
> WR2Nz4nCSjsMDCyo3+AW6pcesp7aPOJ/uAsNAZHJbZvE2mTxsw857jZxonTF1bVN
> V7EDZv5G8d/FFtZuzVzf
> =UEDx
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: nio connector

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

Igor,

On 5/24/16 6:52 PM, Igor Cicimov wrote:
> On 24 May 2016 12:33 pm, "Christopher Schultz"
> <ch...@christopherschultz.net> wrote:
>> 
> Jakub,
> 
> On 5/23/16 8:03 PM, Ja kub wrote:
>>>> Christopher, Thx for response, pleas confirm or deny if I 
>>>> understand well.
>>>> 
>>>> BIO uses thread per http connection (tcp connection). (Shame
>>>> I didn't realize it!) NIO uses thread per request.
> 
> It's more complicated than that, but very close.
> 
>>>> With NIO thread is returned to pool as soon as request is
>>>> finished (doGet ends).
> 
> Yes.
> 
>>>> With BIO thread is returned to pool only when tcp connection
>>>> is closed !!!
> 
> Yes, but even HTTP keepalive has a timeout, and the connection will
> be dropped after that timeout, releasing the thread.
> 
>>>> Given
>>>> http://kb.mozillazine.org/Network.http.keep-alive.timeout - 
>>>> Amount of time in seconds to keep keep-alive connections
>>>> alive. Default: 115 seconds. default tomcat keepAliveTimeout
>>>> 60 s default tomcat maxThreads is 200 With 200 browsers with
>>>> ajax pooling server every 50 seconds tomcat connector thread
>>>> pool will be depleted and client no 201 will not be able to
>>>> connect to tomcat ?
> 
> Yes.
> 
>> Although there is default accept queue of 100 so theoretically
>> the conn 301 will be rejected. Right?

Theoretically, yes. The OS has a separate accept queue, so things get
a little murky when it comes to exactly which connection will be the
first one rejected.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAldFr38ACgkQ9CaO5/Lv0PCehQCbBnv3VIlGsCzDvU+UTgjcc9i0
ckMAoLC9OKCMkhI7euMOdzQgZKgMAHnP
=7eqe
-----END PGP SIGNATURE-----

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


Re: nio connector

Posted by Igor Cicimov <ic...@gmail.com>.
On 24 May 2016 12:33 pm, "Christopher Schultz" <ch...@christopherschultz.net>
wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Jakub,
>
> On 5/23/16 8:03 PM, Ja kub wrote:
> > Christopher, Thx for response, pleas confirm or deny if I
> > understand well.
> >
> > BIO uses thread per http connection (tcp connection). (Shame I
> > didn't realize it!) NIO uses thread per request.
>
> It's more complicated than that, but very close.
>
> > With NIO thread is returned to pool as soon as request is finished
> > (doGet ends).
>
> Yes.
>
> > With BIO thread is returned to pool only when tcp connection is
> > closed !!!
>
> Yes, but even HTTP keepalive has a timeout, and the connection will be
> dropped after that timeout, releasing the thread.
>
> > Given http://kb.mozillazine.org/Network.http.keep-alive.timeout -
> > Amount of time in seconds to keep keep-alive connections alive.
> > Default: 115 seconds. default tomcat keepAliveTimeout 60 s default
> > tomcat maxThreads is 200 With 200 browsers with ajax pooling server
> > every 50 seconds tomcat connector thread pool will be depleted and
> > client no 201 will not be able to connect to tomcat ?
>
> Yes.
>
Although there is default accept queue of 100 so theoretically the conn 301
will be rejected. Right?

> > So with default configuration tomcat 7 will have problem with just
> > 201 on-line clients of an ajax application (with only 4
> > requests/second) ?
>
> If the browse doesn't close those HTTP connections from the Ajax
> clients, the yes, you can trivially DOS your server.
>
> > Why is BIO connector still default one in tomcat 7 server.xml?
>
> Because it was the default when Tomcat 7 shipped and changing defaults
> that are that important is a big deal. You are welcome to change it
> yourself.
>
> > Is there any problem with backward compatibility (don't think so,
> > cause than BIO wouldn't be totally removed in 8.5, but left
> > available ) ?
>
> BIO is 100% gone in Tomcat 8.5.
>
> The protocol (HTTP) and the API (servlet) are still identical, so
> there should be no problems for your application in general.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBCAAGBQJXQ71tAAoJEBzwKT+lPKRYZHIP/jbN3vhtHkLHny6kNXguh5Pl
> BpwaRNHojlOqzXQUWidrmQpQPZ+8GKSUcJp3hcwCklRYNqLS9GdENodwYJFhyKRE
> jVFG2KRSVI+difWKpuX+gIVEiFxUV/fQ+1ZhrNUXusElprqku+s15dqsgI5GYu3u
> BlvEUVs5/rYG+KqZFCYXw5lpe/pRd3fs+zNJFKOXYqY2qQRICzXQJDCvICgPp7fZ
> I804dDIR8mhOfffemgaB1OyOy4F3NsPodBA2LsVcbJpecfQy3vWPCSNkLmUT1Nee
> a30Q6VjdMsq+w/C1cGnxxDwxqoK8mXnyUEIH8GmtGyiak4lzJzSXmqO3RjqXHwm8
> tJnJdWNK+lP4EY9dJQrzv4NokZN+rYb9WCogMXKHvTdpmWDzMiMQs3zyFPkbLfKw
> EGeZKaY3zJFIGltPvpk/QRj0+VcXh6x3g9TUtR8ypoETrchAszCJPVUYy8H5yBaX
> N3H9wrJ2OlFmjrXKNRsY1OtuTABiKjVZXtfuTIgyK4tSddM+4gme5iydmURRISMY
> 7G1UQRNtLng8WFpCaIPrrBVUgXXrfkmYu9pEyjgzuMNc1/gf5stQNWH/AagOVt+J
> WR2Nz4nCSjsMDCyo3+AW6pcesp7aPOJ/uAsNAZHJbZvE2mTxsw857jZxonTF1bVN
> V7EDZv5G8d/FFtZuzVzf
> =UEDx
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Re: nio connector

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

Jakub,

On 5/23/16 8:03 PM, Ja kub wrote:
> Christopher, Thx for response, pleas confirm or deny if I
> understand well.
> 
> BIO uses thread per http connection (tcp connection). (Shame I
> didn't realize it!) NIO uses thread per request.

It's more complicated than that, but very close.

> With NIO thread is returned to pool as soon as request is finished
> (doGet ends).

Yes.

> With BIO thread is returned to pool only when tcp connection is
> closed !!!

Yes, but even HTTP keepalive has a timeout, and the connection will be
dropped after that timeout, releasing the thread.

> Given http://kb.mozillazine.org/Network.http.keep-alive.timeout -
> Amount of time in seconds to keep keep-alive connections alive.
> Default: 115 seconds. default tomcat keepAliveTimeout 60 s default
> tomcat maxThreads is 200 With 200 browsers with ajax pooling server
> every 50 seconds tomcat connector thread pool will be depleted and
> client no 201 will not be able to connect to tomcat ?

Yes.

> So with default configuration tomcat 7 will have problem with just
> 201 on-line clients of an ajax application (with only 4
> requests/second) ?

If the browse doesn't close those HTTP connections from the Ajax
clients, the yes, you can trivially DOS your server.

> Why is BIO connector still default one in tomcat 7 server.xml?

Because it was the default when Tomcat 7 shipped and changing defaults
that are that important is a big deal. You are welcome to change it
yourself.

> Is there any problem with backward compatibility (don't think so,
> cause than BIO wouldn't be totally removed in 8.5, but left
> available ) ?

BIO is 100% gone in Tomcat 8.5.

The protocol (HTTP) and the API (servlet) are still identical, so
there should be no problems for your application in general.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJXQ71tAAoJEBzwKT+lPKRYZHIP/jbN3vhtHkLHny6kNXguh5Pl
BpwaRNHojlOqzXQUWidrmQpQPZ+8GKSUcJp3hcwCklRYNqLS9GdENodwYJFhyKRE
jVFG2KRSVI+difWKpuX+gIVEiFxUV/fQ+1ZhrNUXusElprqku+s15dqsgI5GYu3u
BlvEUVs5/rYG+KqZFCYXw5lpe/pRd3fs+zNJFKOXYqY2qQRICzXQJDCvICgPp7fZ
I804dDIR8mhOfffemgaB1OyOy4F3NsPodBA2LsVcbJpecfQy3vWPCSNkLmUT1Nee
a30Q6VjdMsq+w/C1cGnxxDwxqoK8mXnyUEIH8GmtGyiak4lzJzSXmqO3RjqXHwm8
tJnJdWNK+lP4EY9dJQrzv4NokZN+rYb9WCogMXKHvTdpmWDzMiMQs3zyFPkbLfKw
EGeZKaY3zJFIGltPvpk/QRj0+VcXh6x3g9TUtR8ypoETrchAszCJPVUYy8H5yBaX
N3H9wrJ2OlFmjrXKNRsY1OtuTABiKjVZXtfuTIgyK4tSddM+4gme5iydmURRISMY
7G1UQRNtLng8WFpCaIPrrBVUgXXrfkmYu9pEyjgzuMNc1/gf5stQNWH/AagOVt+J
WR2Nz4nCSjsMDCyo3+AW6pcesp7aPOJ/uAsNAZHJbZvE2mTxsw857jZxonTF1bVN
V7EDZv5G8d/FFtZuzVzf
=UEDx
-----END PGP SIGNATURE-----

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


Re: nio connector

Posted by Ja kub <jj...@gmail.com>.
Christopher,
Thx for response, pleas confirm or deny if I understand well.

BIO uses thread per http connection (tcp connection). (Shame I didn't
realize it!)
NIO uses thread per request.

With NIO thread is returned to pool as soon as request is finished (doGet
ends).
With BIO thread is returned to pool only when tcp connection is closed !!!
Given
  http://kb.mozillazine.org/Network.http.keep-alive.timeout - Amount of
time in seconds to keep keep-alive connections alive. Default: 115 seconds.
  default tomcat keepAliveTimeout 60 s
  default tomcat maxThreads is 200
With 200 browsers with ajax pooling server every 50 seconds tomcat
connector thread pool will be depleted and client no 201 will not be able
to connect to tomcat ?
So with default configuration tomcat 7 will have problem with just 201
on-line clients of an ajax application (with only 4 requests/second) ?

Why is BIO connector still default one in tomcat 7 server.xml ? Is there
any problem with backward compatibility (don't think so, cause than BIO
wouldn't be totally removed in 8.5, but left available ) ?

BR
Jakub



On Mon, May 23, 2016 at 7:31 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Jakub,
>
> On 5/23/16 11:38 AM, Ja kub wrote:
> > In which scenario nio connector will outerform basic io connector
> > and vice versa ?
>
> In Tomcat 8.5 and higher, NIO will always outperform the BIO connector
> because the BIO connector has been completely removed. BIO cannot be
> meaningfully-used with any asynchronous use such as Comet and, more
> recently, Websocket.
>
> NIO will always outperform BIO in other cases when you are measuring
> the performance of requests-per-thread. With NIO, you can handle a
> much higher number of simultaneous requests with a smaller number of
> request-processing threads, especially when HTTP keepalive is being
> used (which should pretty much be "always").
>
> In terms of throughput, the difference between NIO and BIO is
> negligible. In terms of CPU, NIO is a bit more stressful for the CPU
> than BIO, but the benefits far outweigh the difference.
>
> > What would be high level design of corresponding performance tests
> > showing advantages of each connector ?
>
> Jean-Frederic has some recently-presented slides comparing BIO to NIO.
> I'll see if I can find them and put them online.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBCAAGBQJXQz6DAAoJEBzwKT+lPKRYnJsP/j6Aa3+Ss86WdMfWZ1+j2O+j
> qoplBMOPicZDsfnucG1W8ztUprJcgjzcnxFbww8jvpjQs8xuoF/enRVY4Lq2nIbc
> vIU5xVB684CKL401Ram0hIdJLSkrl/y4XaeLeywOwsXVx6qvIrML8qdsHUQLp1xC
> g6kZqaqhAibxKT1LuK9/WtURXXYMWc70lt7bTu7y6PRLybUWnYvBMwQWGMsavKKu
> jVALCJeJznEos3TdM5P/1C2k/27M1Mh+CyPIbL/az2lVP/7S7Q7RydBrh205WU6r
> AvDJ8KA8mbhiQ57DDhK96KOXcCjDinGYOBGMdGfY8Uv0KGrtz6s6bDYx4O40UKtH
> bRLNxNqz7/hfl8Pzmgho+UOg2/vAIIUcbZ78+i2Hx+tQKiNIASbg73LJ34V1Ms24
> iu0QHNpCQI9MaYgnjXe40a3bwPYK79wzD2i459bxkiRmneuBaaH1KQ9PsG3amVgW
> 56iCbyfAvfnK5Ooqp+ag038kUfqWa//ACtLXKGsGjEa5V9iKiTrDcKUNxysC5zsR
> uAr8tXqeNuAPKZA+ET0oCKY/gUa4iU+9rlMqW3XXrWDS7BkQKng44W0h3bEo5evt
> Vy5/isS8bDQ+53ZyQr3jatneTpHz4Ka+BOFkrRgNY2kkTU+PbFwLV8lUB4fZgwY8
> +SqV8S0CfEfxUGrqHrNb
> =e1cY
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: nio connector

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

Jakub,

On 5/23/16 11:38 AM, Ja kub wrote:
> In which scenario nio connector will outerform basic io connector
> and vice versa ?

In Tomcat 8.5 and higher, NIO will always outperform the BIO connector
because the BIO connector has been completely removed. BIO cannot be
meaningfully-used with any asynchronous use such as Comet and, more
recently, Websocket.

NIO will always outperform BIO in other cases when you are measuring
the performance of requests-per-thread. With NIO, you can handle a
much higher number of simultaneous requests with a smaller number of
request-processing threads, especially when HTTP keepalive is being
used (which should pretty much be "always").

In terms of throughput, the difference between NIO and BIO is
negligible. In terms of CPU, NIO is a bit more stressful for the CPU
than BIO, but the benefits far outweigh the difference.

> What would be high level design of corresponding performance tests
> showing advantages of each connector ?

Jean-Frederic has some recently-presented slides comparing BIO to NIO.
I'll see if I can find them and put them online.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJXQz6DAAoJEBzwKT+lPKRYnJsP/j6Aa3+Ss86WdMfWZ1+j2O+j
qoplBMOPicZDsfnucG1W8ztUprJcgjzcnxFbww8jvpjQs8xuoF/enRVY4Lq2nIbc
vIU5xVB684CKL401Ram0hIdJLSkrl/y4XaeLeywOwsXVx6qvIrML8qdsHUQLp1xC
g6kZqaqhAibxKT1LuK9/WtURXXYMWc70lt7bTu7y6PRLybUWnYvBMwQWGMsavKKu
jVALCJeJznEos3TdM5P/1C2k/27M1Mh+CyPIbL/az2lVP/7S7Q7RydBrh205WU6r
AvDJ8KA8mbhiQ57DDhK96KOXcCjDinGYOBGMdGfY8Uv0KGrtz6s6bDYx4O40UKtH
bRLNxNqz7/hfl8Pzmgho+UOg2/vAIIUcbZ78+i2Hx+tQKiNIASbg73LJ34V1Ms24
iu0QHNpCQI9MaYgnjXe40a3bwPYK79wzD2i459bxkiRmneuBaaH1KQ9PsG3amVgW
56iCbyfAvfnK5Ooqp+ag038kUfqWa//ACtLXKGsGjEa5V9iKiTrDcKUNxysC5zsR
uAr8tXqeNuAPKZA+ET0oCKY/gUa4iU+9rlMqW3XXrWDS7BkQKng44W0h3bEo5evt
Vy5/isS8bDQ+53ZyQr3jatneTpHz4Ka+BOFkrRgNY2kkTU+PbFwLV8lUB4fZgwY8
+SqV8S0CfEfxUGrqHrNb
=e1cY
-----END PGP SIGNATURE-----

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