You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Phil Steitz <ph...@gmail.com> on 2015/08/01 17:12:20 UTC

Re: "Too Many Connections" exceptions after moving to Tomcat 8

On 7/31/15 8:16 AM, Christopher Schultz wrote:
> Phil,
>
> On 7/30/15 8:05 PM, Phil Steitz wrote:
> > On 7/30/15 9:03 AM, Christopher Schultz wrote:
> >> Jerry,
> >>
> >> On 7/29/15 3:25 PM, Jerry Malcolm wrote:
> >>> Well, it appears that we are slowly getting to the bottom of
> >>> this. But with every answer, I get a few more questions....
> >>
> >>> First, I installed the latest TC8 on my laptop, copied my
> >>> server.conf and conf/catalina folder to it and started it up
> >>> just to see what errors I got.  After changing out an obsolete
> >>> listener, it came up.  I found all of the <resource> parm
> >>> exceptions in stderr.  So that question is cleared up.  Thanks
> >>> for clarifying where to find that.
> >>
> >> If you have an obsolete Listener, you probably copied your
> >> server.xml from Tomcat 7 to Tomcat 8 which, while being less of a
> >> disaster than with previous version-pairs, is not good practice.
> >>
> >> Instead, start with the stock server.xml that comes with your
> >> Tomcat version and modify it to suit. These days, you should
> >> pretty much only have to configure the <Executor> and <Connector>
> >> elements, unless you have a particularly exotic <Host>
> >> configuration.
> >>
> >>> The site is a wedding vendor advertiser site that spans two
> >>> major cities.  There is no user login.  Simply a very huge
> >>> online catalog. I'm certain it's deployed only once.  Whether I
> >>> need that many connections is a valid question.  As far as I
> >>> know, I haven't hit the limit in normal operation until now.
> >>> Could possibly reduce the count if I collect statistics.
> >>
> >> Our user load is roughly 250 concurrently logged-in users per
> >> Tomcat node, and we have maxTotal="20". I never get alarms about
> >> hitting that maximum. Your requirements may be different.
> >>
> >>> I've been monitoring the production server logs all day
> >>> watching to be sure connection pool doesn't dry up again.
> >>> About an hour ago, there was a single huge dump in stdout of
> >>> approx 2000 'logAbandoned' exceptions. They showed connections
> >>> from 1am right after my last bounce of the server thru 1:35pm.
> >>
> >> It looks like your startup process (likely loading and caching
> >> stuff from the db on launch) is leaky. That can run-up your
> >> connection could quite quickly.
> >>
> >>> The good news is with the stack trace on one of them I was able
> >>> to see the bug causing the leak.
> >>
> >> Good.
> >>> But why did it decide to wait over 12 hours accumulating
> >>> abandoned connections before dumping them back in the pool?
> >>
> >> I was about to say the following, but markt says it might be a
> >> bug in DBCP.
>
> > The bug is in Commons Pool (POOL-300).  It is not flushing its
> > abandoned object log.  That means abandoned traces won't appear
> > (in the default System.out configuration) until some have been
> > accumulated.
>
> Thanks for the correction.
>
> >> I'll say it anyway:
> >>
> >> DBCP 2 looks like it only checks for abandoned connections "on
> >> borrow" so it might only log their abandonment when you see a
> >> flurry of connection-checkouts occurring, not when the
> >> connections are returned to the pool. DBCP 1 would complain
> >> pretty much immediately when the timeout was reached and the
> >> connection hadn't been returned.
>
> > When DBCP checks for abandoned connections depends in its
> > configuration properties.  There are two relevant properties:
> > removeAbandonedOnBorrow and removeAbandonedOnMaintenance.
>
> Right. I think most people don't use the "maintenance" mode, so I was
> being sloppy. I haven't read the code, but the configuration options
> make it sound like the connection isn't checked until it's borrowed
> again from the pool, which could be a very long time after it would be
> expected to have been "abandoned".

Sorry the docs are not that clear.  The problem is that the config
properties work together to determine behavior and documenting them
individually makes it hard to put the whole picture together. 
Improvement patches most welcome :)  In any case, here is how it works:

Connections are evaluated for abandonment when they are out in
circulation - checked out to clients.  If you have set
timeBetweenEvictionRunsMillis to a positive value, pool maintenance
runs every timeBetweenEvictionRunsMillis milliseconds.  If you have
removeAbandonedOnMaintenance set to true, each time maintenance runs
the pool removes abandoned connections.  If you have
removeAbandonedOnBorrow set to true, the pool removes abandoned
connections if it is nearing depletion when a borrow request
arrives.  In both cases, the pool looks at the statistics that it
maintains on the list of all objects checked out by clients to
determine which ones appear to be abandoned.  To appear abandoned
means to be checked out by a client but not used for longer than the
removeAbandonedTimeout.  For DBCP, "used" means the connection has
been used.

Phil

>
> >>> I realize from now knowing the code bug that the leak is a
> >>> slow drip that is continually leaking on a regular basis. But
> >>> since that last 12-hour accumulated dump, the abandoning has
> >>> returned to silence. Since leaks are occurring regularly and
> >>> would be timing out regularly, shouldn't I see a similar 'slow
> >>> drip' of logAbandoned entries in stdout instead of a big dump
> >>> every 12 hours?
> >>
> >>> It's going to take a day or two to fix the leak, test, and
> >>> deploy.
> >>
> >> For testing, set maxTotal="1". You'll find your leaks *very
> >> quickly* that way, because everything will come grinding to a
> >> halt when you try to fetch that second connection from the pool.
> >>
> >>> If indeed abandoned connections are now correctly being
> >>> returned to the pool, then I presume we are back to working the
> >>> way it did on TC7. Still not sure why it started working now.
> >>> But I guess once I get the leak fixed and if TC8 is now
> >>> configured to handle abandoned connections, I'm good.  Still
> >>> would like to know about the mega-dump vs. trickle of abandoned
> >>> connections being logged.
> >>
> >> You should be able to run in testing with an upgraded DBCP 2.
> >> You might have to build it from trunk, though. I'm not sure if
> >> you are okay with that, but it might help you with your testing.
>
> > The thing to swap out is Commons Pool.
>
> Yep, thanks for the clarification.
>
> > There is a release VOTE in progress now for an RC including a fix
> > for POOL-300.
>
> Good news!
>
> > A workaround that should work is to get a reference to the
> > BasicDataSource instance, say, bds and do
>
> > bds.setAbandonedLogWriter(new PrintWriter(System.out, true));
>
> > before using the pool.
>
> > Not sure if this will work correctly to get the output properly
> > directed under tomcat; but it is worth a try.
>
> Definitely.
>
> -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: [OT] "Too Many Connections" exceptions after moving to Tomcat 8

Posted by Phil Steitz <ph...@gmail.com>.
On 8/4/15 2:03 PM, Christopher Schultz wrote:
> Phil,
>
> On 8/1/15 9:34 PM, Phil Steitz wrote:
> > On 8/1/15 6:14 PM, Christopher Schultz wrote:
> >> Phil,
> >>
> >> On 8/1/15 11:12 AM, Phil Steitz wrote:
> >>> Sorry the docs are not that clear.  The problem is that the
> >>> config properties work together to determine behavior and
> >>> documenting them individually makes it hard to put the whole
> >>> picture together. Improvement patches most welcome :)  In any
> >>> case, here is how it works:
> >>
> >>> Connections are evaluated for abandonment when they are out in
> >>> circulation - checked out to clients.  If you have set
> >>> timeBetweenEvictionRunsMillis to a positive value, pool
> >>> maintenance runs every timeBetweenEvictionRunsMillis
> >>> milliseconds. If you have removeAbandonedOnMaintenance set to
> >>> true, each time maintenance runs the pool removes abandoned
> >>> connections.  If you have removeAbandonedOnBorrow set to true,
> >>> the pool removes abandoned connections if it is nearing
> >>> depletion when a borrow request arrives.  In both cases, the
> >>> pool looks at the statistics that it maintains on the list of
> >>> all objects checked out by clients to determine which ones
> >>> appear to be abandoned.  To appear abandoned means to be
> >>> checked out by a client but not used for longer than the
> >>> removeAbandonedTimeout.  For DBCP, "used" means the connection
> >>> has been used.
> >>
> >> So when during all that does the abandoned connection get
> >> "logged"?
>
> > The log message is written when the abandoned connection is closed
> > by the pool.
>
> So if the client code never calls close(), does that mean the
> amandonment is never logged? IIRC, DBCP 1.x would log the stack trace
> as soon as removeAbandonedTimeout elapsed if the connection hadn't
> been returned.

The behavior is the same in 2.x as 1.x with the exception that in
2.x, pool maintenance can also trigger abandoned object removal.  In
1.x, it is necessary to attempt a borrow to get abandoned
connections to be removed.  Both 1.x and 2.x essentially remove
abandoned connections in batches, closing the connections and
logging the traces when the batches run.  In 1.x, the only way to
trigger an abandoned cleanup batch is to request a connection when
the pool is near depletion.  In 2.x, if removeAbandonedOnMaintenance
is true, an abandoned cleanup batch will run every
timeBetweenEvictionRunsMillis ms.
>
> > (The pool bug was basically delaying the effective write; but the
> > stack trace goes to the buffer when the close happens)
> >>
> >> If I have a pool with two connections in it, and the first one
> >> gets leaked (after, lets say, 10 seconds) but the second one is
> >> returned properly, and the application continues to borrow and
> >> return the second connection, what happens?
>
> > That depends on the settings.  See below.
> >>
> >> Are you only checking connections for "abandonment" after they
> >> are returned and then when a client attempts to borrow that
> >> specific connection? Or, are all currently-borrowed connections
> >> checked for abandonment whenever any borrow operation is
> >> requested?
>
> > It is the latter, assuming removeAbandonedOnBorrow is true.
> > Removal on borrow also requires that the pool be near depletion
> > when the borrow happens (see the javadoc for precise description
> > of conditions).  There are two things that can trigger abandoned
> > object removal - a borrow request and pool maintenance.  In each
> > case, if the config setting to enable the check on that event is
> > on, all checked out objects are examined.  The ones that appear
> > abandoned are destroyed (in DBCP that means physical connections
> > are closed).
>
> Why is there no option to dump a warning as soon as the timeout
> elapses? 

Ideas / patches welcome on how to do that efficiently.

> I suppose if the pool is being used slightly more than
> /never/, the abandoned notice will happen pretty quickly, but for
> testing purposes, it means that a single-user will have to perform
> some operation, wait, and then perform another operation in order to
> get the feedback about the abandonment. That's surprising behavior if
> you ask me.

See above.  If you set removeAbandonedOnMaintenance and
maxTimeBetweenEvictionRunsMillis, abandoned connection removal will
happen regularly.

Phil


>
> -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: [OT] "Too Many Connections" exceptions after moving to Tomcat 8

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

Phil,

On 8/1/15 9:34 PM, Phil Steitz wrote:
> On 8/1/15 6:14 PM, Christopher Schultz wrote:
>> Phil,
>> 
>> On 8/1/15 11:12 AM, Phil Steitz wrote:
>>> Sorry the docs are not that clear.  The problem is that the
>>> config properties work together to determine behavior and
>>> documenting them individually makes it hard to put the whole
>>> picture together. Improvement patches most welcome :)  In any
>>> case, here is how it works:
>> 
>>> Connections are evaluated for abandonment when they are out in 
>>> circulation - checked out to clients.  If you have set 
>>> timeBetweenEvictionRunsMillis to a positive value, pool 
>>> maintenance runs every timeBetweenEvictionRunsMillis
>>> milliseconds. If you have removeAbandonedOnMaintenance set to
>>> true, each time maintenance runs the pool removes abandoned
>>> connections.  If you have removeAbandonedOnBorrow set to true,
>>> the pool removes abandoned connections if it is nearing
>>> depletion when a borrow request arrives.  In both cases, the
>>> pool looks at the statistics that it maintains on the list of
>>> all objects checked out by clients to determine which ones
>>> appear to be abandoned.  To appear abandoned means to be
>>> checked out by a client but not used for longer than the
>>> removeAbandonedTimeout.  For DBCP, "used" means the connection
>>> has been used.
>> 
>> So when during all that does the abandoned connection get
>> "logged"?
> 
> The log message is written when the abandoned connection is closed 
> by the pool.

So if the client code never calls close(), does that mean the
amandonment is never logged? IIRC, DBCP 1.x would log the stack trace
as soon as removeAbandonedTimeout elapsed if the connection hadn't
been returned.

> (The pool bug was basically delaying the effective write; but the
> stack trace goes to the buffer when the close happens)
>> 
>> If I have a pool with two connections in it, and the first one
>> gets leaked (after, lets say, 10 seconds) but the second one is
>> returned properly, and the application continues to borrow and
>> return the second connection, what happens?
> 
> That depends on the settings.  See below.
>> 
>> Are you only checking connections for "abandonment" after they
>> are returned and then when a client attempts to borrow that
>> specific connection? Or, are all currently-borrowed connections
>> checked for abandonment whenever any borrow operation is
>> requested?
> 
> It is the latter, assuming removeAbandonedOnBorrow is true.
> Removal on borrow also requires that the pool be near depletion
> when the borrow happens (see the javadoc for precise description
> of conditions).  There are two things that can trigger abandoned
> object removal - a borrow request and pool maintenance.  In each
> case, if the config setting to enable the check on that event is
> on, all checked out objects are examined.  The ones that appear
> abandoned are destroyed (in DBCP that means physical connections
> are closed).

Why is there no option to dump a warning as soon as the timeout
elapses? I suppose if the pool is being used slightly more than
/never/, the abandoned notice will happen pretty quickly, but for
testing purposes, it means that a single-user will have to perform
some operation, wait, and then perform another operation in order to
get the feedback about the abandonment. That's surprising behavior if
you ask me.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJVwSifAAoJEBzwKT+lPKRYoaAP/jLgMP3BWm3j5OTvAFw55Sbm
GyDQel0X0LxlXC1Nn/YETjTvUGh3d1sv0FE0zyuNFfrmEGi35hX6vEIFA+aAx5wb
1LjUR4gUTbMR/4mYGbVyHb65Pt+7CY/oMuGbp22o+2DwXEy/+1sS7lHAXK/xKkbb
F+HcLN7bU2khLp/1JuSp7NfmSEpBKkpuitkTUyGR27ijorYRRqpLfM80/aJV8aTh
MSMhgFuJ6igkJv29oTMqTXY3k+xIfZeIpJuYQ0yFLFwKmZuxPgSP+9hSfOyQAbDs
fev2bcwE9yYmypWOJrPBFR+T7xt61BSLzi1LwUixuTDP6eZEOYrYDvXd0lrB+Ohv
jS5Md182lWiAwbF+8grMwALDTUCE4cCfq/BqO1gSWNaZSDJoFhmm0QmPPgB2iVU+
ZEX9rkwCfY0SKal2x7uJzMwCJYgtPlXq88Fr2aX+Wvg90nXKqwVucAMBf+zOyaP3
tEIuw4H20ug6OPgbfUmdKS1qYLyjS5V7XzP/LoZCNjzDK+pqrmdkRneNdSiIlTzv
2HIQKtIYFZXHEMOmnBGiMWrGfF8lUrAk/rpmFerXk2RI/e6H9ufAExSIz7xhKZEG
AToWrGhb7DOCBOAsABoGnU4R9qE27FuWBcceKdDmSRZzqThmT+9o2tLjXEGJfcc1
Bmt9TxMpWJYKboZkaj/w
=eTpv
-----END PGP SIGNATURE-----

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


Re: [OT] "Too Many Connections" exceptions after moving to Tomcat 8

Posted by Phil Steitz <ph...@gmail.com>.
On 8/1/15 6:14 PM, Christopher Schultz wrote:
> Phil,
>
> On 8/1/15 11:12 AM, Phil Steitz wrote:
> > Sorry the docs are not that clear.  The problem is that the config
> > properties work together to determine behavior and documenting
> > them individually makes it hard to put the whole picture together.
> >  Improvement patches most welcome :)  In any case, here is how it
> > works:
>
> > Connections are evaluated for abandonment when they are out in
> > circulation - checked out to clients.  If you have set
> > timeBetweenEvictionRunsMillis to a positive value, pool
> > maintenance runs every timeBetweenEvictionRunsMillis milliseconds.
> > If you have removeAbandonedOnMaintenance set to true, each time
> > maintenance runs the pool removes abandoned connections.  If you
> > have removeAbandonedOnBorrow set to true, the pool removes
> > abandoned connections if it is nearing depletion when a borrow
> > request arrives.  In both cases, the pool looks at the statistics
> > that it maintains on the list of all objects checked out by clients
> > to determine which ones appear to be abandoned.  To appear
> > abandoned means to be checked out by a client but not used for
> > longer than the removeAbandonedTimeout.  For DBCP, "used" means the
> > connection has been used.
>
> So when during all that does the abandoned connection get "logged"?

The log message is written when the abandoned connection is closed
by the pool.  (The pool bug was basically delaying the effective
write; but the stack trace goes to the buffer when the close happens)
>
> If I have a pool with two connections in it, and the first one gets
> leaked (after, lets say, 10 seconds) but the second one is returned
> properly, and the application continues to borrow and return the
> second connection, what happens?

That depends on the settings.  See below.
>
> Are you only checking connections for "abandonment" after they are
> returned and then when a client attempts to borrow that specific
> connection? Or, are all currently-borrowed connections checked for
> abandonment whenever any borrow operation is requested?

It is the latter, assuming removeAbandonedOnBorrow is true.  Removal
on borrow also requires that the pool be near depletion when the
borrow happens (see the javadoc for precise description of
conditions).  There are two things that can trigger abandoned object
removal - a borrow request and pool maintenance.  In each case, if
the config setting to enable the check on that event is on, all
checked out objects are examined.  The ones that appear abandoned
are destroyed (in DBCP that means physical connections are closed).

Phil
>
> Thanks,
> -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: [OT] "Too Many Connections" exceptions after moving to Tomcat 8

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

Phil,

On 8/1/15 11:12 AM, Phil Steitz wrote:
> Sorry the docs are not that clear.  The problem is that the config 
> properties work together to determine behavior and documenting
> them individually makes it hard to put the whole picture together.
>  Improvement patches most welcome :)  In any case, here is how it
> works:
> 
> Connections are evaluated for abandonment when they are out in 
> circulation - checked out to clients.  If you have set 
> timeBetweenEvictionRunsMillis to a positive value, pool
> maintenance runs every timeBetweenEvictionRunsMillis milliseconds.
> If you have removeAbandonedOnMaintenance set to true, each time
> maintenance runs the pool removes abandoned connections.  If you
> have removeAbandonedOnBorrow set to true, the pool removes
> abandoned connections if it is nearing depletion when a borrow
> request arrives.  In both cases, the pool looks at the statistics
> that it maintains on the list of all objects checked out by clients
> to determine which ones appear to be abandoned.  To appear
> abandoned means to be checked out by a client but not used for
> longer than the removeAbandonedTimeout.  For DBCP, "used" means the
> connection has been used.

So when during all that does the abandoned connection get "logged"?

If I have a pool with two connections in it, and the first one gets
leaked (after, lets say, 10 seconds) but the second one is returned
properly, and the application continues to borrow and return the
second connection, what happens?

Are you only checking connections for "abandonment" after they are
returned and then when a client attempts to borrow that specific
connection? Or, are all currently-borrowed connections checked for
abandonment whenever any borrow operation is requested?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJVvW7pAAoJEBzwKT+lPKRYY0UQAIBXTrkBRNC9j7KBYw8DZFcJ
UY+U1WrHi7osxEseupCjSjP/xmmOHoC16LkEXqtil5k8rd5yQ9D5I1imPKYZSjiE
GBBkkjrbvlwDq/sRp3fxN8La6ueTed4yyh96J5DFfx0opcTtX06YMnpkJDTN2iTt
R3GUKbBo4dNZKIFNGhicR4j9JbSwerxbfJDVpEtb0igO7fQu1dRTDQh7gijyUsZ7
PPa0owq9WOBl5dr4ebsoipirArbLbB4WZqCtteOj5QpafEOYyGuKAjFs6PhodVAR
A2BlikA9+s6AUcKVnqP+CabZFNYO/1raZWl61q7vSWNR9YMrSSI6TapCsBgzNDQW
p8KloJYqjaZFNGtVW23eDtRjTehABnQqoXrB4OL2CEFqgZVjnfpCDl1K0b8wc01y
QNnA0eo40462XkwsRSyMOwtunLu02mGayOrzrn7blJ0f2Kj594+/U6HKqAttRlOX
0Sr2VnYJTaBRACHVjycKjjQh1A1lIIfRoIQ0enMBiw8kZ4rVpQsCvwk/5h54/oap
5osEzulFO7zwqhAxWaHigFG9hCeHJHGr7eT4XUXfUqw+/zg6vI//r5rLExIwSi4D
p/R214PYSkEMiz+i4uSu+sUOYpOJbaAnJH0R6kXSKkoDmaaylTyLuHujPvLKPF6b
ZV739LJI+k5cgcDEWmjv
=PKZ/
-----END PGP SIGNATURE-----

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