You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Bikram B Kapoor <bi...@pugmarksdesign.com> on 2004/12/17 10:07:35 UTC

Connection Problem : Connection not bieng closed

Hi All,
I am using PersistanceBroker in one of my code along with struts.


I use the following code
try {
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();

// ......
..... DATABASE CALLS
..... RECORD FETCHING

}
catch(Exception e) {
    //Logging functions
}
finally {
    if(broker != null) {
        broker.close();
    }

}


But what I notice in process that after some time the number of Mysql
Instances increase, the more user try to access the site, the slow it gets
and more mysql processes/instances are created.

I tried using
PersistenceBrokerFactory.releaseAllInstances();
after broker.close();

but to no avail. Can any body tell me where the problem is or where do I
have to make changes in order to resolve this problem. Because if the number
of user reaches a higher number then I would face "To many connections open"
problem.


Please help.

Regards
Bikram B Kapoor




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Connection Problem : Connection not bieng closed

Posted by Armin Waibel <ar...@apache.org>.

Bikram B Kapoor wrote:
> Hi Armin,
> I checked the complete code and every time PB is retrieved it is closed.
> I used the PersistenceBrokerFactoryFactory.instance().activePersistenceBroker() function for debugging
> 
>    System.out.println("\n\n Active Instances[BEFORE CLOSING]: " + PersistenceBrokerFactoryFactory.instance().activePersistenceBroker());
>    if(broker != null) {
>             broker.close();
>    }
>    System.out.println("\n\n Active Instances[AFTER CLOSING]: " + PersistenceBrokerFactoryFactory.instance().activePersistenceBroker());
> 
> The output I get is 
> 
>  Active Instances[BEFORE CLOSING]: 1
> [org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: PB.close was called: org.apache.ojb.broker.core.PersistenceBrokerImpl@1fcf790
>  Active Instances[AFTER CLOSING]: 0
> 
> It is releasing the instance to the pool, but my problem or question is that why are mysql instances increasing
> I checked the server proccess they where 10 before PB was called
> but after closing PB (PB.close())
> The active instances are back to zero, but the mysql instances increase to 11
> 
> Why is this happening. The only thing I changed in OJB.properties file was whenExhaustedAction=0 to
> whenExhaustedAction=2, this change I made so that when the connections exhaust it should not crash or give an error.
> 

Do you run more than ten concurrent threads at the same time in your 
test? If all threads need a DB access then the grow of connections is 
normal behavior. To reduce the idle connections in pool you can use the 
attributes 'maxIdle' and 'timeBetweenEvictionRunsMillis'
More details see
http://db.apache.org/ojb/docu/guides/repository.html#connection-pool-N10230

Do you change other OJB.properties settings?

regards,
Armin


> 
> 
> 
> 
> ----- Original Message ----- 
> From: "Armin Waibel" <ar...@apache.org>
> Newsgroups: gmane.comp.jakarta.ojb.user
> Sent: Friday, December 17, 2004 5:06 PM
> Subject: Re: Connection Problem : Connection not bieng closed
> 
> 
> 
>>Hi Bikram,
>>
>>Bikram B Kapoor wrote:
>>
>>>Hi All,
>>>I am using PersistanceBroker in one of my code along with struts.
>>>
>>>
>>>I use the following code
>>>try {
>>>PersistenceBroker broker =
>>>PersistenceBrokerFactory.defaultPersistenceBroker();
>>>
>>>// ......
>>>..... DATABASE CALLS
>>>..... RECORD FETCHING
>>>
>>>}
>>>catch(Exception e) {
>>>    //Logging functions
>>>}
>>>finally {
>>>    if(broker != null) {
>>>        broker.close();
>>>    }
>>>
>>>}
>>>
>>>
>>>But what I notice in process that after some time the number of Mysql
>>>Instances increase, the more user try to access the site, the slow it gets
>>>and more mysql processes/instances are created.
>>>
>>
>>hmm, assume you are using OJB default settings, when you call PB.close() 
>>the PB instance was returned to PB-pool and it's guaranteed that the 
>>used connection was released and returned to connection-pool.
>>Maybe you missed to close a used PB instance?
>>You can get the number of active PB instance with 
>>PersistenceBrokerFactoryFactory.instance().activePersistenceBroker()
>>
>>
>>
>>>I tried using
>>>PersistenceBrokerFactory.releaseAllInstances();
>>
>>this only clear the PB pool and does not cleanup abandoned PB instances.
>>Assume you have a PB leak.
>>
>>regards,
>>Armin
>>
>>
>>
>>>after broker.close();
>>>
>>>but to no avail. Can any body tell me where the problem is or where do I
>>>have to make changes in order to resolve this problem. Because if the number
>>>of user reaches a higher number then I would face "To many connections open"
>>>problem.
>>>
>>>
>>>Please help.
>>>
>>>Regards
>>>Bikram B Kapoor
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: File descriptor leak

Posted by Armin Waibel <ar...@apache.org>.
Hi Raghavan,

thanks for the hint! Should be fixed in CVS.

regards,
Armin

Kollivakkam R. Raghavan wrote:
> I was running my program that uses OJB 1.0 as the persistence layer through
> a profiler and found a leak in the file descriptor.  It reported that the
> OJB.properties file is not being closed.  The line where it is being opened
> is LoggingConfiguration.java, line 85 in the load method.  For some dumb
> reason, I am unable to copy the trace of the calls and place it here.
> Raghavan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


File descriptor leak

Posted by "Kollivakkam R. Raghavan" <rk...@cisco.com>.
I was running my program that uses OJB 1.0 as the persistence layer through
a profiler and found a leak in the file descriptor.  It reported that the
OJB.properties file is not being closed.  The line where it is being opened
is LoggingConfiguration.java, line 85 in the load method.  For some dumb
reason, I am unable to copy the trace of the calls and place it here.
Raghavan

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Connection Problem : Connection not bieng closed

Posted by Bikram B Kapoor <bi...@pugmarksdesign.com>.
Hi Armin,
I checked the complete code and every time PB is retrieved it is closed.
I used the PersistenceBrokerFactoryFactory.instance().activePersistenceBroker() function for debugging

   System.out.println("\n\n Active Instances[BEFORE CLOSING]: " + PersistenceBrokerFactoryFactory.instance().activePersistenceBroker());
   if(broker != null) {
            broker.close();
   }
   System.out.println("\n\n Active Instances[AFTER CLOSING]: " + PersistenceBrokerFactoryFactory.instance().activePersistenceBroker());

The output I get is 

 Active Instances[BEFORE CLOSING]: 1
[org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: PB.close was called: org.apache.ojb.broker.core.PersistenceBrokerImpl@1fcf790
 Active Instances[AFTER CLOSING]: 0

It is releasing the instance to the pool, but my problem or question is that why are mysql instances increasing
I checked the server proccess they where 10 before PB was called
but after closing PB (PB.close())
The active instances are back to zero, but the mysql instances increase to 11

Why is this happening. The only thing I changed in OJB.properties file was whenExhaustedAction=0 to whenExhaustedAction=2, this change I made so that when the connections exhaust it should not crash or give an error.





----- Original Message ----- 
From: "Armin Waibel" <ar...@apache.org>
Newsgroups: gmane.comp.jakarta.ojb.user
Sent: Friday, December 17, 2004 5:06 PM
Subject: Re: Connection Problem : Connection not bieng closed


> Hi Bikram,
> 
> Bikram B Kapoor wrote:
> > Hi All,
> > I am using PersistanceBroker in one of my code along with struts.
> > 
> > 
> > I use the following code
> > try {
> > PersistenceBroker broker =
> > PersistenceBrokerFactory.defaultPersistenceBroker();
> > 
> > // ......
> > ..... DATABASE CALLS
> > ..... RECORD FETCHING
> > 
> > }
> > catch(Exception e) {
> >     //Logging functions
> > }
> > finally {
> >     if(broker != null) {
> >         broker.close();
> >     }
> > 
> > }
> > 
> > 
> > But what I notice in process that after some time the number of Mysql
> > Instances increase, the more user try to access the site, the slow it gets
> > and more mysql processes/instances are created.
> > 
> 
> hmm, assume you are using OJB default settings, when you call PB.close() 
> the PB instance was returned to PB-pool and it's guaranteed that the 
> used connection was released and returned to connection-pool.
> Maybe you missed to close a used PB instance?
> You can get the number of active PB instance with 
> PersistenceBrokerFactoryFactory.instance().activePersistenceBroker()
> 
> 
> > I tried using
> > PersistenceBrokerFactory.releaseAllInstances();
> 
> this only clear the PB pool and does not cleanup abandoned PB instances.
> Assume you have a PB leak.
> 
> regards,
> Armin
> 
> 
> > after broker.close();
> > 
> > but to no avail. Can any body tell me where the problem is or where do I
> > have to make changes in order to resolve this problem. Because if the number
> > of user reaches a higher number then I would face "To many connections open"
> > problem.
> > 
> > 
> > Please help.
> > 
> > Regards
> > Bikram B Kapoor
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> > 
> > 
> >

Re: Connection Problem : Connection not bieng closed

Posted by Armin Waibel <ar...@apache.org>.
Hi Bikram,

Bikram B Kapoor wrote:
> Hi All,
> I am using PersistanceBroker in one of my code along with struts.
> 
> 
> I use the following code
> try {
> PersistenceBroker broker =
> PersistenceBrokerFactory.defaultPersistenceBroker();
> 
> // ......
> ..... DATABASE CALLS
> ..... RECORD FETCHING
> 
> }
> catch(Exception e) {
>     //Logging functions
> }
> finally {
>     if(broker != null) {
>         broker.close();
>     }
> 
> }
> 
> 
> But what I notice in process that after some time the number of Mysql
> Instances increase, the more user try to access the site, the slow it gets
> and more mysql processes/instances are created.
> 

hmm, assume you are using OJB default settings, when you call PB.close() 
the PB instance was returned to PB-pool and it's guaranteed that the 
used connection was released and returned to connection-pool.
Maybe you missed to close a used PB instance?
You can get the number of active PB instance with 
PersistenceBrokerFactoryFactory.instance().activePersistenceBroker()


> I tried using
> PersistenceBrokerFactory.releaseAllInstances();

this only clear the PB pool and does not cleanup abandoned PB instances.
Assume you have a PB leak.

regards,
Armin


> after broker.close();
> 
> but to no avail. Can any body tell me where the problem is or where do I
> have to make changes in order to resolve this problem. Because if the number
> of user reaches a higher number then I would face "To many connections open"
> problem.
> 
> 
> Please help.
> 
> Regards
> Bikram B Kapoor
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org