Stale DB-connections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Stale DB-connections

Hans Holmlund
I have just upgraded to the latest version of Entity Engine and stumbled
upon a problem. The problem I had was that db-connections were dropped
after awhile but without actually closing the TCP session with the
database. So when I checked with netstat I had a lot of connections in a
CLOSE_WAIT state. I'm using MySQL but I guess this may happen with other
databases too.
I had a look in the code and come up with a fix. In
DBCPConnectionFactory (row 96) there is a line saying:
    pool.setTimeBetweenEvictionRunsMillis(600000);

In GenericPool to set this parameter has the effect of creating an
eviction thread, so every 10 minutes the pool will be checked if there
exist any unused objects. The problem seems to be when the object is
evicted, I'm not sure what is happening but the object is not correctly
removed.
I don't think that this cleaning procedure is necessary, if I have set
the pool-maxsize to 200 I can probably live with that the actual
pool-size never shrinks.
So I made this change:
    pool.setTimeBetweenEvictionRunsMillis(-1);
The eviction thread will not be created. And after I made this change I
have not had any problems with stale DB-connections.

/ Hans Holmlund
Reply | Threaded
Open this post in threaded view
|

Re: Stale DB-connections

David E Jones

This is an interesting find Hans.

Has anyone noticed, or tested, this with other databases (ie other  
than MySQL which is what Hans mentions testing with)?

The big question in my mind is do we turn it off altogether, or make  
it a configurable option with recommended settings for different  
databases?

If anyone can take a peek at their system(s) and offer feedback that  
would be great.

-David


On Jan 31, 2008, at 12:37 AM, Hans Holmlund wrote:

> I have just upgraded to the latest version of Entity Engine and  
> stumbled upon a problem. The problem I had was that db-connections  
> were dropped after awhile but without actually closing the TCP  
> session with the database. So when I checked with netstat I had a  
> lot of connections in a CLOSE_WAIT state. I'm using MySQL but I  
> guess this may happen with other databases too.
> I had a look in the code and come up with a fix. In  
> DBCPConnectionFactory (row 96) there is a line saying:
>   pool.setTimeBetweenEvictionRunsMillis(600000);
>
> In GenericPool to set this parameter has the effect of creating an  
> eviction thread, so every 10 minutes the pool will be checked if  
> there exist any unused objects. The problem seems to be when the  
> object is evicted, I'm not sure what is happening but the object is  
> not correctly removed.
> I don't think that this cleaning procedure is necessary, if I have  
> set the pool-maxsize to 200 I can probably live with that the actual  
> pool-size never shrinks.
> So I made this change:
>   pool.setTimeBetweenEvictionRunsMillis(-1);
> The eviction thread will not be created. And after I made this  
> change I have not had any problems with stale DB-connections.
>
> / Hans Holmlund

Reply | Threaded
Open this post in threaded view
|

RE: Stale DB-connections

LECOCQ Michel (CAMPUS)
Hello

I've tested  with the two connection factory classes (minerva and dbcp)
on mysql and oracle databases.
With minerva, no problem occured.
With DBCP, the limit of pool-maxsize value  from the datasource is not
respected and the connections increase until reaching the connections
max value defined on the database.
The db-connections are not correctly removed too.

Regards.

Michael.

-----Original Message-----
From: David E Jones [mailto:[hidden email]]
Sent: Thursday, January 31, 2008 7:10 PM
To: [hidden email]
Subject: Re: Stale DB-connections


This is an interesting find Hans.

Has anyone noticed, or tested, this with other databases (ie other than
MySQL which is what Hans mentions testing with)?

The big question in my mind is do we turn it off altogether, or make it
a configurable option with recommended settings for different databases?

If anyone can take a peek at their system(s) and offer feedback that
would be great.

-David


On Jan 31, 2008, at 12:37 AM, Hans Holmlund wrote:

> I have just upgraded to the latest version of Entity Engine and
> stumbled upon a problem. The problem I had was that db-connections
> were dropped after awhile but without actually closing the TCP session

> with the database. So when I checked with netstat I had a lot of
> connections in a CLOSE_WAIT state. I'm using MySQL but I guess this
> may happen with other databases too.
> I had a look in the code and come up with a fix. In
> DBCPConnectionFactory (row 96) there is a line saying:
>   pool.setTimeBetweenEvictionRunsMillis(600000);
>
> In GenericPool to set this parameter has the effect of creating an
> eviction thread, so every 10 minutes the pool will be checked if there

> exist any unused objects. The problem seems to be when the object is
> evicted, I'm not sure what is happening but the object is not
> correctly removed.
> I don't think that this cleaning procedure is necessary, if I have set

> the pool-maxsize to 200 I can probably live with that the actual
> pool-size never shrinks.
> So I made this change:
>   pool.setTimeBetweenEvictionRunsMillis(-1);
> The eviction thread will not be created. And after I made this change
> I have not had any problems with stale DB-connections.
>
> / Hans Holmlund
Reply | Threaded
Open this post in threaded view
|

Re: Stale DB-connections

Jacques Le Roux-2
In reply to this post by David E Jones
Sorry to bring back this old user thread on dev ML, but I think we should defintively made this configurable. At least to allow
people to easily
try 2 basic configurations (ie -1 or 600000) and especially to make people aware of possible problems there.
The related doc is here http://commons.apache.org/dbcp/configuration.html.

Jacques

From: "David E Jones" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, January 31, 2008 8:10 PM
Subject: Re: Stale DB-connections


>
> This is an interesting find Hans.
>
> Has anyone noticed, or tested, this with other databases (ie other  than MySQL which is what Hans mentions testing with)?
>
> The big question in my mind is do we turn it off altogether, or make  it a configurable option with recommended settings for
> different  databases?
>
> If anyone can take a peek at their system(s) and offer feedback that  would be great.
>
> -David
>
>
> On Jan 31, 2008, at 12:37 AM, Hans Holmlund wrote:
>
>> I have just upgraded to the latest version of Entity Engine and  stumbled upon a problem. The problem I had was that
>> db-connections  were dropped after awhile but without actually closing the TCP  session with the database. So when I checked with
>> netstat I had a  lot of connections in a CLOSE_WAIT state. I'm using MySQL but I  guess this may happen with other databases too.
>> I had a look in the code and come up with a fix. In  DBCPConnectionFactory (row 96) there is a line saying:
>>   pool.setTimeBetweenEvictionRunsMillis(600000);
>>
>> In GenericPool to set this parameter has the effect of creating an  eviction thread, so every 10 minutes the pool will be checked
>> if  there exist any unused objects. The problem seems to be when the  object is evicted, I'm not sure what is happening but the
>> object is  not correctly removed.
>> I don't think that this cleaning procedure is necessary, if I have  set the pool-maxsize to 200 I can probably live with that the
>> actual  pool-size never shrinks.
>> So I made this change:
>>   pool.setTimeBetweenEvictionRunsMillis(-1);
>> The eviction thread will not be created. And after I made this  change I have not had any problems with stale DB-connections.
>>
>> / Hans Holmlund
>
>