You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Beichert <pb...@web.de> on 2010/01/06 09:03:57 UTC

limit number of connections tomcat accepts

Hi,

I like to limit the number of connections tomcat (6.0.20) accepts. However, 
this is not possible. 

For testing purpose I use the following connector statement:

<Connector port="8080" acceptCount="5" maxThreads="3" minSpareThread="1" 
maxSpareThreads="2" />

Here only 3 threads should process the requests and 5 more requests should be 
queued. 

If I start 100 parallel requests to a servlet which does nothing else than 
waiting 5 seconds, I would expect that only 8 requests would be accepted, the 
rest should receive a connection refused. 
However all 100 Requests a accepted and it takes a long time until they finish.

I use Debian Linux and have the same behavior with suns jdk1.6.0_17 and the 
ibm-jdk.

I appreciate any help how to solve this problem.

Regards
Peter 

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


Re: limit number of connections tomcat accepts

Posted by Peter Beichert <pb...@web.de>.
Am Mittwoch, 6. Januar 2010 09:15:23 schrieb Mark Thomas:
> On 06/01/2010 08:03, Peter Beichert wrote:
> > Hi,
> >
> > I like to limit the number of connections tomcat (6.0.20) accepts.
> > However, this is not possible.
> >
> > For testing purpose I use the following connector statement:
> >
> > <Connector port="8080" acceptCount="5" maxThreads="3" minSpareThread="1"
> > maxSpareThreads="2" />
> 
> minSpareThread & maxSpareThreads do nothing and will be ignored.
> 
> > Here only 3 threads should process the requests and 5 more requests
> > should be queued.
> >
> > If I start 100 parallel requests to a servlet which does nothing else
> > than waiting 5 seconds, I would expect that only 8 requests would be
> > accepted, the rest should receive a connection refused.
> > However all 100 Requests a accepted and it takes a long time until they
> > finish.
> >
> > I use Debian Linux and have the same behavior with suns jdk1.6.0_17 and
> > the ibm-jdk.
> >
> > I appreciate any help how to solve this problem.
> 
> This works as expected for me using JMeter as the test client. How are
> you testing this?
I used jmeter and in addition I started 100 requests in parallel by a shell-
script with wget. With wget I could observe all the waiting threads. Their 
number got reduced by 3 every 5 seconds. All requests got answered with Status 
200. I did not get any connection refused.
> 
> 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: limit number of connections tomcat accepts

Posted by Mark Thomas <ma...@apache.org>.
On 06/01/2010 08:03, Peter Beichert wrote:
> Hi,
> 
> I like to limit the number of connections tomcat (6.0.20) accepts. However, 
> this is not possible. 
> 
> For testing purpose I use the following connector statement:
> 
> <Connector port="8080" acceptCount="5" maxThreads="3" minSpareThread="1" 
> maxSpareThreads="2" />

minSpareThread & maxSpareThreads do nothing and will be ignored.

> Here only 3 threads should process the requests and 5 more requests should be 
> queued. 
> 
> If I start 100 parallel requests to a servlet which does nothing else than 
> waiting 5 seconds, I would expect that only 8 requests would be accepted, the 
> rest should receive a connection refused. 
> However all 100 Requests a accepted and it takes a long time until they finish.
> 
> I use Debian Linux and have the same behavior with suns jdk1.6.0_17 and the 
> ibm-jdk.
> 
> I appreciate any help how to solve this problem.

This works as expected for me using JMeter as the test client. How are
you testing this?

Mark



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


Re: limit number of connections tomcat accepts

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

Peter,

On 1/8/2010 3:02 AM, Peter Beichert wrote:
> Thank you for your help. The good new is, that Tomcat really works like it 
> supposed to. The problem is, that the operating system holds all the 
> connections which did not receive an acknowledgement from the server.

This is what "acceptCount" is supposed to configure. Is that not working
for you? What JVM are you using?

> When monitoring the tcp-connections during the tests with netstat, I could 
> see, that the number of established connections was the sum of threads plus 
> the number of queued requests. All other connections could be observed at the 
> server with a SYN_RECV state. As soon as tomcat finished one request, a new 
> connection was acknowledged and the number of connections with the SYN_RECV 
> state decreased by one.
> 
> The value of the maximum remembered connection requests in Linux is the Kernel 
> parameter tcp_max_syn_backlog which is by default 1024. It can be reduced with 
> the /sbin/sysctl command.

Good to know, though I would have expected acceptCount to work properly.
My understanding of acceptCount is that the socket listener will receive
at most maxActive concurrent requests. After that, acceptCount incoming
requests will be queued in the TCP/IP stack, and subsequent requests
will get a connection refused. If the client has a timeout and/or retry
configured, then that will confuse the issue but the initial connection
should be refused.

Once a request has been completed and the socket is closed, the queue is
processed and another incoming request is free to be queued by the
TCP/IP stack.

I'm curious as to exactly how your observations stack up against that:
are you saying that, in spite of your acceptCount="5", you're
effectively getting acceptCount="1024" because of how your kernel behaves?

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

iEYEARECAAYFAktHqDQACgkQ9CaO5/Lv0PCM5QCgjkVT7rZYAS6Z50sGlqLGAqkx
hp0An3jV9aklDaTm8or65Gwyot8Xc5Gb
=PC+9
-----END PGP SIGNATURE-----

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


Re: limit number of connections tomcat accepts

Posted by Peter Beichert <pb...@web.de>.
Thank you for your help. The good new is, that Tomcat really works like it 
supposed to. The problem is, that the operating system holds all the 
connections which did not receive an acknowledgement from the server.

When monitoring the tcp-connections during the tests with netstat, I could 
see, that the number of established connections was the sum of threads plus 
the number of queued requests. All other connections could be observed at the 
server with a SYN_RECV state. As soon as tomcat finished one request, a new 
connection was acknowledged and the number of connections with the SYN_RECV 
state decreased by one.

The value of the maximum remembered connection requests in Linux is the Kernel 
parameter tcp_max_syn_backlog which is by default 1024. It can be reduced with 
the /sbin/sysctl command.

best regards
Peter
 
Am Mittwoch, 6. Januar 2010 14:50:18 schrieb Christopher Schultz:
> Peter,
> 
> On 1/6/2010 3:03 AM, Peter Beichert wrote:
> > If I start 100 parallel requests to a servlet which does nothing else
> > than waiting 5 seconds, I would expect that only 8 requests would be
> > accepted, the rest should receive a connection refused.
> 
> A lot here depends upon the behavior of the client. Some clients will
> try until they get a connection rather than giving up. Is this how you
> have configured JMeter and/or wget?
> 
> -chris
> 
> ---------------------------------------------------------------------
> 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: limit number of connections tomcat accepts

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

Peter,

On 1/6/2010 3:03 AM, Peter Beichert wrote:
> If I start 100 parallel requests to a servlet which does nothing else than 
> waiting 5 seconds, I would expect that only 8 requests would be accepted, the 
> rest should receive a connection refused. 

A lot here depends upon the behavior of the client. Some clients will
try until they get a connection rather than giving up. Is this how you
have configured JMeter and/or wget?

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

iEYEARECAAYFAktElRoACgkQ9CaO5/Lv0PAQOgCfd3PP+2CBzWgucpCknu7BVObJ
hFMAoKpvb+l+8pYOeKEJLSqzi7aHFazR
=16aL
-----END PGP SIGNATURE-----

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