You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Chathuri Wimalasena <ka...@gmail.com> on 2014/06/02 19:20:11 UTC
Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Hi Devs,
We are using apache openJPA 2.2 version and we experience some memory leak
issues. While analyzing the memory dump, I see
*org.apache.openjpa.kernel.FinalizingBrokerImpl
*as one suspect for the memory leak.
311,437 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
*585,849,792
(55.60%)* bytes. These instances are referenced from one instance of
*"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
class loader>"*
*Keywords*
java.util.concurrent.ConcurrentHashMap$Segment[]
sun.misc.Launcher$AppClassLoader @ 0x117a09088
org.apache.openjpa.kernel.FinalizingBrokerImpl
While searching, I found [1] which is still open. Does this patch applied
in openJPA 2.2 version ? Any idea why I might get this issue and any
suggestions to avoid this ?
Thanks..
Chathuri
[1] https://issues.apache.org/jira/browse/OPENJPA-1193
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Chathuri Wimalasena <ka...@gmail.com>.
Hi Rick,
Thank you so much for your help. I added
if (em.getTransaction().isActive()){
em.getTransaction().rollback();
}
before closing entityManager and now I do not see a memory leak as before.
Attaching the memory graphs before and after applying the fix.
Thanks..
Chathuri
On Fri, Jun 6, 2014 at 2:50 PM, Rick Curtis <cu...@gmail.com> wrote:
> Thanks for that data. I'm digging into the heapdump and I suspect there is
> something odd going on with your transactions. Is it possible that
> something is causing transactions to not complete? This will cause OpenJPA
> to keep a hold of Broker instances that have an active tran.
>
> I'll be in #openjpa on freenode irc for the next 30 min or so if you want
> to discuss.
>
>
> On Fri, Jun 6, 2014 at 1:45 PM, Chathuri Wimalasena <ka...@gmail.com>
> wrote:
>
> > Hi Rick,
> >
> > This is the link of the persistence xml -
> >
> >
> https://github.com/apache/airavata/blob/master/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml
> >
> > All the JPA models are at
> >
> >
> https://github.com/apache/airavata/tree/master/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model
> > .
> >
> > Thanks for looking in to this.
> >
> > Regards,
> > Chathuri
> >
> >
> > On Fri, Jun 6, 2014 at 2:39 PM, Rick Curtis <cu...@gmail.com> wrote:
> >
> > > Yes, I was able to download the heapdump. Will you post the contents of
> > > your persistence.xml file?
> > >
> > >
> > > On Fri, Jun 6, 2014 at 10:02 AM, Chathuri Wimalasena <
> > kamalasini@gmail.com
> > > >
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > Can you check whether this is accessible.
> > > >
> > > > https://iu.box.com/s/ah9dp1deko6p3wn8rfrg. It is something around 3
> > GB.
> > > >
> > > > Thanks..
> > > > Chathuri
> > > >
> > > >
> > > > On Fri, Jun 6, 2014 at 10:42 AM, Rick Curtis <cu...@gmail.com>
> > wrote:
> > > >
> > > > > Can you post your heapdump somewhere?
> > > > >
> > > > >
> > > > > On Fri, Jun 6, 2014 at 9:05 AM, Chathuri Wimalasena <
> > > > kamalasini@gmail.com>
> > > > > wrote:
> > > > >
> > > > > > Appreciate someone's insight on this issue.
> > > > > >
> > > > > > Thanks..
> > > > > > Chathuri
> > > > > >
> > > > > >
> > > > > > On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <
> > > > > kamalasini@gmail.com
> > > > > > >
> > > > > > wrote:
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > > Thanks for the responses. I checked almost all the places where
> > we
> > > > are
> > > > > > > using entityManager instance and make sure they are closed
> after
> > > they
> > > > > > have
> > > > > > > been used.
> > > > > > >
> > > > > > > Here are the two suspect classes I'm getting when analysing the
> > > > memory
> > > > > > > dump.
> > > > > > >
> > > > > > > *Problem Suspect 1*
> > > > > > >
> > > > > > > 546,326 instances of
> > > > > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"*
> > occupy
> > > > > > *1,031,525,848
> > > > > > > (56.39%)* bytes. These instances are referenced from one
> instance
> > > of
> > > > > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > > > > *"<system
> > > > > > > class loader>"*
> > > > > > >
> > > > > > > *Keywords*
> > > > > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > > > >
> > > > > > >
> > > > > > > *Problem Suspect 2*
> > > > > > >
> > > > > > > 546,300 instances of
> > > > *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> > > > > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"*
> > occupy
> > > > > > *680,034,240
> > > > > > > (37.17%)* bytes. These instances are referenced from one
> instance
> > > of
> > > > > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > > > > *"<system
> > > > > > > class loader>"*
> > > > > > >
> > > > > > > *Keywords*
> > > > > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > > > > org.apache.openjpa.kernel.LocalManagedRuntime
> > > > > > >
> > > > > > > This is how we create the Entity manager instance.
> > > > > > > public static EntityManager getEntityManager(){
> > > > > > > if (factory == null) {
> > > > > > > String connectionProperties = "DriverClassName=" +
> > > > > > > Utils.getJDBCDriver() + "," + "Url=" +
> > > > > > > Utils.getJDBCURL() + "," +"Username=" +
> > > > > > Utils.getJDBCUser() +
> > > > > > > "," + "Password=" +
> > > > > > > Utils.getJDBCPassword() + ",validationQuery=" +
> > > > > > > Utils.getValidationQuery() + "," +
> > > > > > >
> > > > > > > Utils.getJPAConnectionProperties();
> > > > > > > Map<String, String> properties = new
> HashMap<String,
> > > > > > String>();
> > > > > > > properties.put("openjpa.ConnectionDriverName",
> > > > > > > "org.apache.commons.dbcp.BasicDataSource");\
> > > > > > > properties.put("openjpa.ConnectionProperties",
> > > > > > > connectionProperties);
> > > > > > > properties.put("openjpa.DynamicEnhancementAgent",
> > > > "true");
> > > > > > > properties.put("openjpa.RuntimeUnenhancedClasses",
> > > > > > > "unsupported");
> > > > > > >
> > > properties.put("openjpa.DataCache","true(CacheSize=5000,
> > > > > > > SoftReferenceSize=0)");
> > > > > > >
> > > properties.put("openjpa.QueryCache","true(CacheSize=5000,
> > > > > > > SoftReferenceSize=0)");
> > > > > > >
> > properties.put("openjpa.RemoteCommitProvider","sjvm");
> > > > > > > properties.put("openjpa.Log","DefaultLevel=INFO,
> > > > > > Runtime=INFO,
> > > > > > > Tool=INFO, SQL=INFO");
> > > > > > > properties.put("openjpa.jdbc.SynchronizeMappings",
> > > > > > > "buildSchema(ForeignKeys=true)");
> > > > > > > properties.put("openjpa.jdbc.QuerySQLCache",
> > "false");
> > > > > > >
> > > > > > > factory =
> > > > > > > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
> > > > > > properties);
> > > > > > > }
> > > > > > > return factory.createEntityManager();
> > > > > > > }
> > > > > > >
> > > > > > > This is how we use entityManager and close it.
> > > > > > > public void save() throws RegistryException {
> > > > > > > EntityManager em = null;
> > > > > > > try {
> > > > > > > em = ResourceUtils.getEntityManager();
> > > > > > > Gateway existingGateway = em.find(Gateway.class,
> > > > > > gatewayName);
> > > > > > > em.close();
> > > > > > >
> > > > > > > em = ResourceUtils.getEntityManager();
> > > > > > > em.getTransaction().begin();
> > > > > > > Gateway gateway = new Gateway();
> > > > > > > gateway.setGateway_name(gatewayName);
> > > > > > > gateway.setOwner(owner);
> > > > > > > if (existingGateway != null) {
> > > > > > > existingGateway.setOwner(owner);
> > > > > > > gateway = em.merge(existingGateway);
> > > > > > > } else {
> > > > > > > em.persist(gateway);
> > > > > > > }
> > > > > > > em.getTransaction().commit();
> > > > > > > em.close();
> > > > > > > } catch (Exception e) {
> > > > > > > logger.error(e.getMessage(), e);
> > > > > > > throw new RegistryException(e);
> > > > > > > } finally {
> > > > > > > if (em != null && em.isOpen()) {
> > > > > > > em.close();
> > > > > > > }
> > > > > > > }
> > > > > > > }
> > > > > > >
> > > > > > > Do you see any issues with this implementation ?
> > > > > > >
> > > > > > >
> > > > > > > Thanks..
> > > > > > > Chathuri
> > > > > > >
> > > > > > >
> > > > > > > On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <
> kwsutter@gmail.com
> > >
> > > > > wrote:
> > > > > > >
> > > > > > >> The scary part of the proposed patch is what impact this will
> > have
> > > > on
> > > > > > the
> > > > > > >> "more important" non-finalizing BrokerImpl... That is, if
> these
> > > two
> > > > > > >> assignments would get reversed now to correct this supposed
> > memory
> > > > > leak
> > > > > > >> with FinalizingBrokerImpl, what impact would this have on
> > > > > non-finalizing
> > > > > > >> BrokerImpls?
> > > > > > >>
> > > > > > >> if
> > > > > > >>
> > > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> >
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> > > > > > >> {
> > > > > > >> return MapBackedSet.decorate(new
> > ConcurrentHashMap(),
> > > > new
> > > > > > >> Object() { });
> > > > > > >> } else {
> > > > > > >> return new
> > > > > > >>
> > > ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> > > > > > >> }
> > > > > > >>
> > > > > > >> I mean "more important" since in most cases we want the
> > container
> > > to
> > > > > > >> manage
> > > > > > >> the lifecycle and, thus, avoid the overhead associated with
> the
> > > > > > >> FinalizingBrokerImpl...
> > > > > > >>
> > > > > > >>
> > > > > > >>
> > > > > > >> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <
> > > > > > kamalasini@gmail.com
> > > > > > >> >
> > > > > > >> wrote:
> > > > > > >>
> > > > > > >> > I'm closing all the EntityManagers in a finally block. I
> will
> > > > check
> > > > > > if I
> > > > > > >> > miss any place.
> > > > > > >> >
> > > > > > >> >
> > > > > > >> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <
> > curtisr7@gmail.com
> > > >
> > > > > > wrote:
> > > > > > >> >
> > > > > > >> > > > Any idea why I might get this issue and any suggestions
> to
> > > > avoid
> > > > > > >> this ?
> > > > > > >> > > Please make sure that your application closes all
> > > EntityManagers
> > > > > > when
> > > > > > >> > > you're through with them.
> > > > > > >> > >
> > > > > > >> > > Thanks,
> > > > > > >> > > Rick
> > > > > > >> > >
> > > > > > >> > >
> > > > > > >> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> > > > > > >> > kamalasini@gmail.com
> > > > > > >> > > >
> > > > > > >> > > wrote:
> > > > > > >> > >
> > > > > > >> > > > Hi Devs,
> > > > > > >> > > >
> > > > > > >> > > > We are using apache openJPA 2.2 version and we
> experience
> > > some
> > > > > > >> memory
> > > > > > >> > > leak
> > > > > > >> > > > issues. While analyzing the memory dump, I see
> > > > > > >> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > > > >> > > > *as one suspect for the memory leak.
> > > > > > >> > > >
> > > > > > >> > > > 311,437 instances of
> > > > > > >> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > > > >> > > > loaded by *"sun.misc.Launcher$AppClassLoader @
> > 0x117a09088"*
> > > > > > occupy
> > > > > > >> > > > *585,849,792
> > > > > > >> > > > (55.60%)* bytes. These instances are referenced from one
> > > > > instance
> > > > > > of
> > > > > > >> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*,
> > loaded
> > > > by
> > > > > > >> > *"<system
> > > > > > >> > > > class loader>"*
> > > > > > >> > > >
> > > > > > >> > > > *Keywords*
> > > > > > >> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > > >> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > > > > > >> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > > > >> > > >
> > > > > > >> > > > While searching, I found [1] which is still open. Does
> > this
> > > > > patch
> > > > > > >> > applied
> > > > > > >> > > > in openJPA 2.2 version ? Any idea why I might get this
> > issue
> > > > and
> > > > > > any
> > > > > > >> > > > suggestions to avoid this ?
> > > > > > >> > > >
> > > > > > >> > > > Thanks..
> > > > > > >> > > > Chathuri
> > > > > > >> > > >
> > > > > > >> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > > > > > >> > > >
> > > > > > >> > >
> > > > > > >> > >
> > > > > > >> > >
> > > > > > >> > > --
> > > > > > >> > > *Rick Curtis*
> > > > > > >> > >
> > > > > > >> >
> > > > > > >>
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > *Rick Curtis*
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > *Rick Curtis*
> > >
> >
>
>
>
> --
> *Rick Curtis*
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Rick Curtis <cu...@gmail.com>.
Thanks for that data. I'm digging into the heapdump and I suspect there is
something odd going on with your transactions. Is it possible that
something is causing transactions to not complete? This will cause OpenJPA
to keep a hold of Broker instances that have an active tran.
I'll be in #openjpa on freenode irc for the next 30 min or so if you want
to discuss.
On Fri, Jun 6, 2014 at 1:45 PM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> Hi Rick,
>
> This is the link of the persistence xml -
>
> https://github.com/apache/airavata/blob/master/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml
>
> All the JPA models are at
>
> https://github.com/apache/airavata/tree/master/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model
> .
>
> Thanks for looking in to this.
>
> Regards,
> Chathuri
>
>
> On Fri, Jun 6, 2014 at 2:39 PM, Rick Curtis <cu...@gmail.com> wrote:
>
> > Yes, I was able to download the heapdump. Will you post the contents of
> > your persistence.xml file?
> >
> >
> > On Fri, Jun 6, 2014 at 10:02 AM, Chathuri Wimalasena <
> kamalasini@gmail.com
> > >
> > wrote:
> >
> > > Hi,
> > >
> > > Can you check whether this is accessible.
> > >
> > > https://iu.box.com/s/ah9dp1deko6p3wn8rfrg. It is something around 3
> GB.
> > >
> > > Thanks..
> > > Chathuri
> > >
> > >
> > > On Fri, Jun 6, 2014 at 10:42 AM, Rick Curtis <cu...@gmail.com>
> wrote:
> > >
> > > > Can you post your heapdump somewhere?
> > > >
> > > >
> > > > On Fri, Jun 6, 2014 at 9:05 AM, Chathuri Wimalasena <
> > > kamalasini@gmail.com>
> > > > wrote:
> > > >
> > > > > Appreciate someone's insight on this issue.
> > > > >
> > > > > Thanks..
> > > > > Chathuri
> > > > >
> > > > >
> > > > > On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <
> > > > kamalasini@gmail.com
> > > > > >
> > > > > wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > Thanks for the responses. I checked almost all the places where
> we
> > > are
> > > > > > using entityManager instance and make sure they are closed after
> > they
> > > > > have
> > > > > > been used.
> > > > > >
> > > > > > Here are the two suspect classes I'm getting when analysing the
> > > memory
> > > > > > dump.
> > > > > >
> > > > > > *Problem Suspect 1*
> > > > > >
> > > > > > 546,326 instances of
> > > > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"*
> occupy
> > > > > *1,031,525,848
> > > > > > (56.39%)* bytes. These instances are referenced from one instance
> > of
> > > > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > > > *"<system
> > > > > > class loader>"*
> > > > > >
> > > > > > *Keywords*
> > > > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > > >
> > > > > >
> > > > > > *Problem Suspect 2*
> > > > > >
> > > > > > 546,300 instances of
> > > *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> > > > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"*
> occupy
> > > > > *680,034,240
> > > > > > (37.17%)* bytes. These instances are referenced from one instance
> > of
> > > > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > > > *"<system
> > > > > > class loader>"*
> > > > > >
> > > > > > *Keywords*
> > > > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > > > org.apache.openjpa.kernel.LocalManagedRuntime
> > > > > >
> > > > > > This is how we create the Entity manager instance.
> > > > > > public static EntityManager getEntityManager(){
> > > > > > if (factory == null) {
> > > > > > String connectionProperties = "DriverClassName=" +
> > > > > > Utils.getJDBCDriver() + "," + "Url=" +
> > > > > > Utils.getJDBCURL() + "," +"Username=" +
> > > > > Utils.getJDBCUser() +
> > > > > > "," + "Password=" +
> > > > > > Utils.getJDBCPassword() + ",validationQuery=" +
> > > > > > Utils.getValidationQuery() + "," +
> > > > > >
> > > > > > Utils.getJPAConnectionProperties();
> > > > > > Map<String, String> properties = new HashMap<String,
> > > > > String>();
> > > > > > properties.put("openjpa.ConnectionDriverName",
> > > > > > "org.apache.commons.dbcp.BasicDataSource");\
> > > > > > properties.put("openjpa.ConnectionProperties",
> > > > > > connectionProperties);
> > > > > > properties.put("openjpa.DynamicEnhancementAgent",
> > > "true");
> > > > > > properties.put("openjpa.RuntimeUnenhancedClasses",
> > > > > > "unsupported");
> > > > > >
> > properties.put("openjpa.DataCache","true(CacheSize=5000,
> > > > > > SoftReferenceSize=0)");
> > > > > >
> > properties.put("openjpa.QueryCache","true(CacheSize=5000,
> > > > > > SoftReferenceSize=0)");
> > > > > >
> properties.put("openjpa.RemoteCommitProvider","sjvm");
> > > > > > properties.put("openjpa.Log","DefaultLevel=INFO,
> > > > > Runtime=INFO,
> > > > > > Tool=INFO, SQL=INFO");
> > > > > > properties.put("openjpa.jdbc.SynchronizeMappings",
> > > > > > "buildSchema(ForeignKeys=true)");
> > > > > > properties.put("openjpa.jdbc.QuerySQLCache",
> "false");
> > > > > >
> > > > > > factory =
> > > > > > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
> > > > > properties);
> > > > > > }
> > > > > > return factory.createEntityManager();
> > > > > > }
> > > > > >
> > > > > > This is how we use entityManager and close it.
> > > > > > public void save() throws RegistryException {
> > > > > > EntityManager em = null;
> > > > > > try {
> > > > > > em = ResourceUtils.getEntityManager();
> > > > > > Gateway existingGateway = em.find(Gateway.class,
> > > > > gatewayName);
> > > > > > em.close();
> > > > > >
> > > > > > em = ResourceUtils.getEntityManager();
> > > > > > em.getTransaction().begin();
> > > > > > Gateway gateway = new Gateway();
> > > > > > gateway.setGateway_name(gatewayName);
> > > > > > gateway.setOwner(owner);
> > > > > > if (existingGateway != null) {
> > > > > > existingGateway.setOwner(owner);
> > > > > > gateway = em.merge(existingGateway);
> > > > > > } else {
> > > > > > em.persist(gateway);
> > > > > > }
> > > > > > em.getTransaction().commit();
> > > > > > em.close();
> > > > > > } catch (Exception e) {
> > > > > > logger.error(e.getMessage(), e);
> > > > > > throw new RegistryException(e);
> > > > > > } finally {
> > > > > > if (em != null && em.isOpen()) {
> > > > > > em.close();
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > Do you see any issues with this implementation ?
> > > > > >
> > > > > >
> > > > > > Thanks..
> > > > > > Chathuri
> > > > > >
> > > > > >
> > > > > > On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kwsutter@gmail.com
> >
> > > > wrote:
> > > > > >
> > > > > >> The scary part of the proposed patch is what impact this will
> have
> > > on
> > > > > the
> > > > > >> "more important" non-finalizing BrokerImpl... That is, if these
> > two
> > > > > >> assignments would get reversed now to correct this supposed
> memory
> > > > leak
> > > > > >> with FinalizingBrokerImpl, what impact would this have on
> > > > non-finalizing
> > > > > >> BrokerImpls?
> > > > > >>
> > > > > >> if
> > > > > >>
> > > > > >>
> > > > >
> > > >
> > >
> >
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> > > > > >> {
> > > > > >> return MapBackedSet.decorate(new
> ConcurrentHashMap(),
> > > new
> > > > > >> Object() { });
> > > > > >> } else {
> > > > > >> return new
> > > > > >>
> > ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> > > > > >> }
> > > > > >>
> > > > > >> I mean "more important" since in most cases we want the
> container
> > to
> > > > > >> manage
> > > > > >> the lifecycle and, thus, avoid the overhead associated with the
> > > > > >> FinalizingBrokerImpl...
> > > > > >>
> > > > > >>
> > > > > >>
> > > > > >> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <
> > > > > kamalasini@gmail.com
> > > > > >> >
> > > > > >> wrote:
> > > > > >>
> > > > > >> > I'm closing all the EntityManagers in a finally block. I will
> > > check
> > > > > if I
> > > > > >> > miss any place.
> > > > > >> >
> > > > > >> >
> > > > > >> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <
> curtisr7@gmail.com
> > >
> > > > > wrote:
> > > > > >> >
> > > > > >> > > > Any idea why I might get this issue and any suggestions to
> > > avoid
> > > > > >> this ?
> > > > > >> > > Please make sure that your application closes all
> > EntityManagers
> > > > > when
> > > > > >> > > you're through with them.
> > > > > >> > >
> > > > > >> > > Thanks,
> > > > > >> > > Rick
> > > > > >> > >
> > > > > >> > >
> > > > > >> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> > > > > >> > kamalasini@gmail.com
> > > > > >> > > >
> > > > > >> > > wrote:
> > > > > >> > >
> > > > > >> > > > Hi Devs,
> > > > > >> > > >
> > > > > >> > > > We are using apache openJPA 2.2 version and we experience
> > some
> > > > > >> memory
> > > > > >> > > leak
> > > > > >> > > > issues. While analyzing the memory dump, I see
> > > > > >> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > > >> > > > *as one suspect for the memory leak.
> > > > > >> > > >
> > > > > >> > > > 311,437 instances of
> > > > > >> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > > >> > > > loaded by *"sun.misc.Launcher$AppClassLoader @
> 0x117a09088"*
> > > > > occupy
> > > > > >> > > > *585,849,792
> > > > > >> > > > (55.60%)* bytes. These instances are referenced from one
> > > > instance
> > > > > of
> > > > > >> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*,
> loaded
> > > by
> > > > > >> > *"<system
> > > > > >> > > > class loader>"*
> > > > > >> > > >
> > > > > >> > > > *Keywords*
> > > > > >> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > >> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > > > > >> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > > >> > > >
> > > > > >> > > > While searching, I found [1] which is still open. Does
> this
> > > > patch
> > > > > >> > applied
> > > > > >> > > > in openJPA 2.2 version ? Any idea why I might get this
> issue
> > > and
> > > > > any
> > > > > >> > > > suggestions to avoid this ?
> > > > > >> > > >
> > > > > >> > > > Thanks..
> > > > > >> > > > Chathuri
> > > > > >> > > >
> > > > > >> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > > > > >> > > >
> > > > > >> > >
> > > > > >> > >
> > > > > >> > >
> > > > > >> > > --
> > > > > >> > > *Rick Curtis*
> > > > > >> > >
> > > > > >> >
> > > > > >>
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > *Rick Curtis*
> > > >
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
--
*Rick Curtis*
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Chathuri Wimalasena <ka...@gmail.com>.
Hi Rick,
This is the link of the persistence xml -
https://github.com/apache/airavata/blob/master/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml
All the JPA models are at
https://github.com/apache/airavata/tree/master/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/model
.
Thanks for looking in to this.
Regards,
Chathuri
On Fri, Jun 6, 2014 at 2:39 PM, Rick Curtis <cu...@gmail.com> wrote:
> Yes, I was able to download the heapdump. Will you post the contents of
> your persistence.xml file?
>
>
> On Fri, Jun 6, 2014 at 10:02 AM, Chathuri Wimalasena <kamalasini@gmail.com
> >
> wrote:
>
> > Hi,
> >
> > Can you check whether this is accessible.
> >
> > https://iu.box.com/s/ah9dp1deko6p3wn8rfrg. It is something around 3 GB.
> >
> > Thanks..
> > Chathuri
> >
> >
> > On Fri, Jun 6, 2014 at 10:42 AM, Rick Curtis <cu...@gmail.com> wrote:
> >
> > > Can you post your heapdump somewhere?
> > >
> > >
> > > On Fri, Jun 6, 2014 at 9:05 AM, Chathuri Wimalasena <
> > kamalasini@gmail.com>
> > > wrote:
> > >
> > > > Appreciate someone's insight on this issue.
> > > >
> > > > Thanks..
> > > > Chathuri
> > > >
> > > >
> > > > On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <
> > > kamalasini@gmail.com
> > > > >
> > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Thanks for the responses. I checked almost all the places where we
> > are
> > > > > using entityManager instance and make sure they are closed after
> they
> > > > have
> > > > > been used.
> > > > >
> > > > > Here are the two suspect classes I'm getting when analysing the
> > memory
> > > > > dump.
> > > > >
> > > > > *Problem Suspect 1*
> > > > >
> > > > > 546,326 instances of
> > > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> > > > *1,031,525,848
> > > > > (56.39%)* bytes. These instances are referenced from one instance
> of
> > > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > > *"<system
> > > > > class loader>"*
> > > > >
> > > > > *Keywords*
> > > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > >
> > > > >
> > > > > *Problem Suspect 2*
> > > > >
> > > > > 546,300 instances of
> > *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> > > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> > > > *680,034,240
> > > > > (37.17%)* bytes. These instances are referenced from one instance
> of
> > > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > > *"<system
> > > > > class loader>"*
> > > > >
> > > > > *Keywords*
> > > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > > org.apache.openjpa.kernel.LocalManagedRuntime
> > > > >
> > > > > This is how we create the Entity manager instance.
> > > > > public static EntityManager getEntityManager(){
> > > > > if (factory == null) {
> > > > > String connectionProperties = "DriverClassName=" +
> > > > > Utils.getJDBCDriver() + "," + "Url=" +
> > > > > Utils.getJDBCURL() + "," +"Username=" +
> > > > Utils.getJDBCUser() +
> > > > > "," + "Password=" +
> > > > > Utils.getJDBCPassword() + ",validationQuery=" +
> > > > > Utils.getValidationQuery() + "," +
> > > > >
> > > > > Utils.getJPAConnectionProperties();
> > > > > Map<String, String> properties = new HashMap<String,
> > > > String>();
> > > > > properties.put("openjpa.ConnectionDriverName",
> > > > > "org.apache.commons.dbcp.BasicDataSource");\
> > > > > properties.put("openjpa.ConnectionProperties",
> > > > > connectionProperties);
> > > > > properties.put("openjpa.DynamicEnhancementAgent",
> > "true");
> > > > > properties.put("openjpa.RuntimeUnenhancedClasses",
> > > > > "unsupported");
> > > > >
> properties.put("openjpa.DataCache","true(CacheSize=5000,
> > > > > SoftReferenceSize=0)");
> > > > >
> properties.put("openjpa.QueryCache","true(CacheSize=5000,
> > > > > SoftReferenceSize=0)");
> > > > > properties.put("openjpa.RemoteCommitProvider","sjvm");
> > > > > properties.put("openjpa.Log","DefaultLevel=INFO,
> > > > Runtime=INFO,
> > > > > Tool=INFO, SQL=INFO");
> > > > > properties.put("openjpa.jdbc.SynchronizeMappings",
> > > > > "buildSchema(ForeignKeys=true)");
> > > > > properties.put("openjpa.jdbc.QuerySQLCache", "false");
> > > > >
> > > > > factory =
> > > > > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
> > > > properties);
> > > > > }
> > > > > return factory.createEntityManager();
> > > > > }
> > > > >
> > > > > This is how we use entityManager and close it.
> > > > > public void save() throws RegistryException {
> > > > > EntityManager em = null;
> > > > > try {
> > > > > em = ResourceUtils.getEntityManager();
> > > > > Gateway existingGateway = em.find(Gateway.class,
> > > > gatewayName);
> > > > > em.close();
> > > > >
> > > > > em = ResourceUtils.getEntityManager();
> > > > > em.getTransaction().begin();
> > > > > Gateway gateway = new Gateway();
> > > > > gateway.setGateway_name(gatewayName);
> > > > > gateway.setOwner(owner);
> > > > > if (existingGateway != null) {
> > > > > existingGateway.setOwner(owner);
> > > > > gateway = em.merge(existingGateway);
> > > > > } else {
> > > > > em.persist(gateway);
> > > > > }
> > > > > em.getTransaction().commit();
> > > > > em.close();
> > > > > } catch (Exception e) {
> > > > > logger.error(e.getMessage(), e);
> > > > > throw new RegistryException(e);
> > > > > } finally {
> > > > > if (em != null && em.isOpen()) {
> > > > > em.close();
> > > > > }
> > > > > }
> > > > > }
> > > > >
> > > > > Do you see any issues with this implementation ?
> > > > >
> > > > >
> > > > > Thanks..
> > > > > Chathuri
> > > > >
> > > > >
> > > > > On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kw...@gmail.com>
> > > wrote:
> > > > >
> > > > >> The scary part of the proposed patch is what impact this will have
> > on
> > > > the
> > > > >> "more important" non-finalizing BrokerImpl... That is, if these
> two
> > > > >> assignments would get reversed now to correct this supposed memory
> > > leak
> > > > >> with FinalizingBrokerImpl, what impact would this have on
> > > non-finalizing
> > > > >> BrokerImpls?
> > > > >>
> > > > >> if
> > > > >>
> > > > >>
> > > >
> > >
> >
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> > > > >> {
> > > > >> return MapBackedSet.decorate(new ConcurrentHashMap(),
> > new
> > > > >> Object() { });
> > > > >> } else {
> > > > >> return new
> > > > >>
> ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> > > > >> }
> > > > >>
> > > > >> I mean "more important" since in most cases we want the container
> to
> > > > >> manage
> > > > >> the lifecycle and, thus, avoid the overhead associated with the
> > > > >> FinalizingBrokerImpl...
> > > > >>
> > > > >>
> > > > >>
> > > > >> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <
> > > > kamalasini@gmail.com
> > > > >> >
> > > > >> wrote:
> > > > >>
> > > > >> > I'm closing all the EntityManagers in a finally block. I will
> > check
> > > > if I
> > > > >> > miss any place.
> > > > >> >
> > > > >> >
> > > > >> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <curtisr7@gmail.com
> >
> > > > wrote:
> > > > >> >
> > > > >> > > > Any idea why I might get this issue and any suggestions to
> > avoid
> > > > >> this ?
> > > > >> > > Please make sure that your application closes all
> EntityManagers
> > > > when
> > > > >> > > you're through with them.
> > > > >> > >
> > > > >> > > Thanks,
> > > > >> > > Rick
> > > > >> > >
> > > > >> > >
> > > > >> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> > > > >> > kamalasini@gmail.com
> > > > >> > > >
> > > > >> > > wrote:
> > > > >> > >
> > > > >> > > > Hi Devs,
> > > > >> > > >
> > > > >> > > > We are using apache openJPA 2.2 version and we experience
> some
> > > > >> memory
> > > > >> > > leak
> > > > >> > > > issues. While analyzing the memory dump, I see
> > > > >> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > >> > > > *as one suspect for the memory leak.
> > > > >> > > >
> > > > >> > > > 311,437 instances of
> > > > >> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > >> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"*
> > > > occupy
> > > > >> > > > *585,849,792
> > > > >> > > > (55.60%)* bytes. These instances are referenced from one
> > > instance
> > > > of
> > > > >> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded
> > by
> > > > >> > *"<system
> > > > >> > > > class loader>"*
> > > > >> > > >
> > > > >> > > > *Keywords*
> > > > >> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > >> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > > > >> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > >> > > >
> > > > >> > > > While searching, I found [1] which is still open. Does this
> > > patch
> > > > >> > applied
> > > > >> > > > in openJPA 2.2 version ? Any idea why I might get this issue
> > and
> > > > any
> > > > >> > > > suggestions to avoid this ?
> > > > >> > > >
> > > > >> > > > Thanks..
> > > > >> > > > Chathuri
> > > > >> > > >
> > > > >> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > > > >> > > >
> > > > >> > >
> > > > >> > >
> > > > >> > >
> > > > >> > > --
> > > > >> > > *Rick Curtis*
> > > > >> > >
> > > > >> >
> > > > >>
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > *Rick Curtis*
> > >
> >
>
>
>
> --
> *Rick Curtis*
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Rick Curtis <cu...@gmail.com>.
Yes, I was able to download the heapdump. Will you post the contents of
your persistence.xml file?
On Fri, Jun 6, 2014 at 10:02 AM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> Hi,
>
> Can you check whether this is accessible.
>
> https://iu.box.com/s/ah9dp1deko6p3wn8rfrg. It is something around 3 GB.
>
> Thanks..
> Chathuri
>
>
> On Fri, Jun 6, 2014 at 10:42 AM, Rick Curtis <cu...@gmail.com> wrote:
>
> > Can you post your heapdump somewhere?
> >
> >
> > On Fri, Jun 6, 2014 at 9:05 AM, Chathuri Wimalasena <
> kamalasini@gmail.com>
> > wrote:
> >
> > > Appreciate someone's insight on this issue.
> > >
> > > Thanks..
> > > Chathuri
> > >
> > >
> > > On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <
> > kamalasini@gmail.com
> > > >
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > Thanks for the responses. I checked almost all the places where we
> are
> > > > using entityManager instance and make sure they are closed after they
> > > have
> > > > been used.
> > > >
> > > > Here are the two suspect classes I'm getting when analysing the
> memory
> > > > dump.
> > > >
> > > > *Problem Suspect 1*
> > > >
> > > > 546,326 instances of
> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> > > *1,031,525,848
> > > > (56.39%)* bytes. These instances are referenced from one instance of
> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > *"<system
> > > > class loader>"*
> > > >
> > > > *Keywords*
> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > >
> > > >
> > > > *Problem Suspect 2*
> > > >
> > > > 546,300 instances of
> *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> > > *680,034,240
> > > > (37.17%)* bytes. These instances are referenced from one instance of
> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > *"<system
> > > > class loader>"*
> > > >
> > > > *Keywords*
> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > > org.apache.openjpa.kernel.LocalManagedRuntime
> > > >
> > > > This is how we create the Entity manager instance.
> > > > public static EntityManager getEntityManager(){
> > > > if (factory == null) {
> > > > String connectionProperties = "DriverClassName=" +
> > > > Utils.getJDBCDriver() + "," + "Url=" +
> > > > Utils.getJDBCURL() + "," +"Username=" +
> > > Utils.getJDBCUser() +
> > > > "," + "Password=" +
> > > > Utils.getJDBCPassword() + ",validationQuery=" +
> > > > Utils.getValidationQuery() + "," +
> > > >
> > > > Utils.getJPAConnectionProperties();
> > > > Map<String, String> properties = new HashMap<String,
> > > String>();
> > > > properties.put("openjpa.ConnectionDriverName",
> > > > "org.apache.commons.dbcp.BasicDataSource");\
> > > > properties.put("openjpa.ConnectionProperties",
> > > > connectionProperties);
> > > > properties.put("openjpa.DynamicEnhancementAgent",
> "true");
> > > > properties.put("openjpa.RuntimeUnenhancedClasses",
> > > > "unsupported");
> > > > properties.put("openjpa.DataCache","true(CacheSize=5000,
> > > > SoftReferenceSize=0)");
> > > > properties.put("openjpa.QueryCache","true(CacheSize=5000,
> > > > SoftReferenceSize=0)");
> > > > properties.put("openjpa.RemoteCommitProvider","sjvm");
> > > > properties.put("openjpa.Log","DefaultLevel=INFO,
> > > Runtime=INFO,
> > > > Tool=INFO, SQL=INFO");
> > > > properties.put("openjpa.jdbc.SynchronizeMappings",
> > > > "buildSchema(ForeignKeys=true)");
> > > > properties.put("openjpa.jdbc.QuerySQLCache", "false");
> > > >
> > > > factory =
> > > > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
> > > properties);
> > > > }
> > > > return factory.createEntityManager();
> > > > }
> > > >
> > > > This is how we use entityManager and close it.
> > > > public void save() throws RegistryException {
> > > > EntityManager em = null;
> > > > try {
> > > > em = ResourceUtils.getEntityManager();
> > > > Gateway existingGateway = em.find(Gateway.class,
> > > gatewayName);
> > > > em.close();
> > > >
> > > > em = ResourceUtils.getEntityManager();
> > > > em.getTransaction().begin();
> > > > Gateway gateway = new Gateway();
> > > > gateway.setGateway_name(gatewayName);
> > > > gateway.setOwner(owner);
> > > > if (existingGateway != null) {
> > > > existingGateway.setOwner(owner);
> > > > gateway = em.merge(existingGateway);
> > > > } else {
> > > > em.persist(gateway);
> > > > }
> > > > em.getTransaction().commit();
> > > > em.close();
> > > > } catch (Exception e) {
> > > > logger.error(e.getMessage(), e);
> > > > throw new RegistryException(e);
> > > > } finally {
> > > > if (em != null && em.isOpen()) {
> > > > em.close();
> > > > }
> > > > }
> > > > }
> > > >
> > > > Do you see any issues with this implementation ?
> > > >
> > > >
> > > > Thanks..
> > > > Chathuri
> > > >
> > > >
> > > > On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kw...@gmail.com>
> > wrote:
> > > >
> > > >> The scary part of the proposed patch is what impact this will have
> on
> > > the
> > > >> "more important" non-finalizing BrokerImpl... That is, if these two
> > > >> assignments would get reversed now to correct this supposed memory
> > leak
> > > >> with FinalizingBrokerImpl, what impact would this have on
> > non-finalizing
> > > >> BrokerImpls?
> > > >>
> > > >> if
> > > >>
> > > >>
> > >
> >
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> > > >> {
> > > >> return MapBackedSet.decorate(new ConcurrentHashMap(),
> new
> > > >> Object() { });
> > > >> } else {
> > > >> return new
> > > >> ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> > > >> }
> > > >>
> > > >> I mean "more important" since in most cases we want the container to
> > > >> manage
> > > >> the lifecycle and, thus, avoid the overhead associated with the
> > > >> FinalizingBrokerImpl...
> > > >>
> > > >>
> > > >>
> > > >> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <
> > > kamalasini@gmail.com
> > > >> >
> > > >> wrote:
> > > >>
> > > >> > I'm closing all the EntityManagers in a finally block. I will
> check
> > > if I
> > > >> > miss any place.
> > > >> >
> > > >> >
> > > >> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com>
> > > wrote:
> > > >> >
> > > >> > > > Any idea why I might get this issue and any suggestions to
> avoid
> > > >> this ?
> > > >> > > Please make sure that your application closes all EntityManagers
> > > when
> > > >> > > you're through with them.
> > > >> > >
> > > >> > > Thanks,
> > > >> > > Rick
> > > >> > >
> > > >> > >
> > > >> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> > > >> > kamalasini@gmail.com
> > > >> > > >
> > > >> > > wrote:
> > > >> > >
> > > >> > > > Hi Devs,
> > > >> > > >
> > > >> > > > We are using apache openJPA 2.2 version and we experience some
> > > >> memory
> > > >> > > leak
> > > >> > > > issues. While analyzing the memory dump, I see
> > > >> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > >> > > > *as one suspect for the memory leak.
> > > >> > > >
> > > >> > > > 311,437 instances of
> > > >> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > >> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"*
> > > occupy
> > > >> > > > *585,849,792
> > > >> > > > (55.60%)* bytes. These instances are referenced from one
> > instance
> > > of
> > > >> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded
> by
> > > >> > *"<system
> > > >> > > > class loader>"*
> > > >> > > >
> > > >> > > > *Keywords*
> > > >> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > >> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > > >> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > >> > > >
> > > >> > > > While searching, I found [1] which is still open. Does this
> > patch
> > > >> > applied
> > > >> > > > in openJPA 2.2 version ? Any idea why I might get this issue
> and
> > > any
> > > >> > > > suggestions to avoid this ?
> > > >> > > >
> > > >> > > > Thanks..
> > > >> > > > Chathuri
> > > >> > > >
> > > >> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > > >> > > >
> > > >> > >
> > > >> > >
> > > >> > >
> > > >> > > --
> > > >> > > *Rick Curtis*
> > > >> > >
> > > >> >
> > > >>
> > > >
> > > >
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
--
*Rick Curtis*
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Chathuri Wimalasena <ka...@gmail.com>.
Hi,
Can you check whether this is accessible.
https://iu.box.com/s/ah9dp1deko6p3wn8rfrg. It is something around 3 GB.
Thanks..
Chathuri
On Fri, Jun 6, 2014 at 10:42 AM, Rick Curtis <cu...@gmail.com> wrote:
> Can you post your heapdump somewhere?
>
>
> On Fri, Jun 6, 2014 at 9:05 AM, Chathuri Wimalasena <ka...@gmail.com>
> wrote:
>
> > Appreciate someone's insight on this issue.
> >
> > Thanks..
> > Chathuri
> >
> >
> > On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <
> kamalasini@gmail.com
> > >
> > wrote:
> >
> > > Hi,
> > >
> > > Thanks for the responses. I checked almost all the places where we are
> > > using entityManager instance and make sure they are closed after they
> > have
> > > been used.
> > >
> > > Here are the two suspect classes I'm getting when analysing the memory
> > > dump.
> > >
> > > *Problem Suspect 1*
> > >
> > > 546,326 instances of
> *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> > *1,031,525,848
> > > (56.39%)* bytes. These instances are referenced from one instance of
> > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> *"<system
> > > class loader>"*
> > >
> > > *Keywords*
> > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > >
> > >
> > > *Problem Suspect 2*
> > >
> > > 546,300 instances of *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> > *680,034,240
> > > (37.17%)* bytes. These instances are referenced from one instance of
> > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> *"<system
> > > class loader>"*
> > >
> > > *Keywords*
> > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > > org.apache.openjpa.kernel.LocalManagedRuntime
> > >
> > > This is how we create the Entity manager instance.
> > > public static EntityManager getEntityManager(){
> > > if (factory == null) {
> > > String connectionProperties = "DriverClassName=" +
> > > Utils.getJDBCDriver() + "," + "Url=" +
> > > Utils.getJDBCURL() + "," +"Username=" +
> > Utils.getJDBCUser() +
> > > "," + "Password=" +
> > > Utils.getJDBCPassword() + ",validationQuery=" +
> > > Utils.getValidationQuery() + "," +
> > >
> > > Utils.getJPAConnectionProperties();
> > > Map<String, String> properties = new HashMap<String,
> > String>();
> > > properties.put("openjpa.ConnectionDriverName",
> > > "org.apache.commons.dbcp.BasicDataSource");\
> > > properties.put("openjpa.ConnectionProperties",
> > > connectionProperties);
> > > properties.put("openjpa.DynamicEnhancementAgent", "true");
> > > properties.put("openjpa.RuntimeUnenhancedClasses",
> > > "unsupported");
> > > properties.put("openjpa.DataCache","true(CacheSize=5000,
> > > SoftReferenceSize=0)");
> > > properties.put("openjpa.QueryCache","true(CacheSize=5000,
> > > SoftReferenceSize=0)");
> > > properties.put("openjpa.RemoteCommitProvider","sjvm");
> > > properties.put("openjpa.Log","DefaultLevel=INFO,
> > Runtime=INFO,
> > > Tool=INFO, SQL=INFO");
> > > properties.put("openjpa.jdbc.SynchronizeMappings",
> > > "buildSchema(ForeignKeys=true)");
> > > properties.put("openjpa.jdbc.QuerySQLCache", "false");
> > >
> > > factory =
> > > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
> > properties);
> > > }
> > > return factory.createEntityManager();
> > > }
> > >
> > > This is how we use entityManager and close it.
> > > public void save() throws RegistryException {
> > > EntityManager em = null;
> > > try {
> > > em = ResourceUtils.getEntityManager();
> > > Gateway existingGateway = em.find(Gateway.class,
> > gatewayName);
> > > em.close();
> > >
> > > em = ResourceUtils.getEntityManager();
> > > em.getTransaction().begin();
> > > Gateway gateway = new Gateway();
> > > gateway.setGateway_name(gatewayName);
> > > gateway.setOwner(owner);
> > > if (existingGateway != null) {
> > > existingGateway.setOwner(owner);
> > > gateway = em.merge(existingGateway);
> > > } else {
> > > em.persist(gateway);
> > > }
> > > em.getTransaction().commit();
> > > em.close();
> > > } catch (Exception e) {
> > > logger.error(e.getMessage(), e);
> > > throw new RegistryException(e);
> > > } finally {
> > > if (em != null && em.isOpen()) {
> > > em.close();
> > > }
> > > }
> > > }
> > >
> > > Do you see any issues with this implementation ?
> > >
> > >
> > > Thanks..
> > > Chathuri
> > >
> > >
> > > On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kw...@gmail.com>
> wrote:
> > >
> > >> The scary part of the proposed patch is what impact this will have on
> > the
> > >> "more important" non-finalizing BrokerImpl... That is, if these two
> > >> assignments would get reversed now to correct this supposed memory
> leak
> > >> with FinalizingBrokerImpl, what impact would this have on
> non-finalizing
> > >> BrokerImpls?
> > >>
> > >> if
> > >>
> > >>
> >
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> > >> {
> > >> return MapBackedSet.decorate(new ConcurrentHashMap(), new
> > >> Object() { });
> > >> } else {
> > >> return new
> > >> ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> > >> }
> > >>
> > >> I mean "more important" since in most cases we want the container to
> > >> manage
> > >> the lifecycle and, thus, avoid the overhead associated with the
> > >> FinalizingBrokerImpl...
> > >>
> > >>
> > >>
> > >> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <
> > kamalasini@gmail.com
> > >> >
> > >> wrote:
> > >>
> > >> > I'm closing all the EntityManagers in a finally block. I will check
> > if I
> > >> > miss any place.
> > >> >
> > >> >
> > >> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com>
> > wrote:
> > >> >
> > >> > > > Any idea why I might get this issue and any suggestions to avoid
> > >> this ?
> > >> > > Please make sure that your application closes all EntityManagers
> > when
> > >> > > you're through with them.
> > >> > >
> > >> > > Thanks,
> > >> > > Rick
> > >> > >
> > >> > >
> > >> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> > >> > kamalasini@gmail.com
> > >> > > >
> > >> > > wrote:
> > >> > >
> > >> > > > Hi Devs,
> > >> > > >
> > >> > > > We are using apache openJPA 2.2 version and we experience some
> > >> memory
> > >> > > leak
> > >> > > > issues. While analyzing the memory dump, I see
> > >> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > >> > > > *as one suspect for the memory leak.
> > >> > > >
> > >> > > > 311,437 instances of
> > >> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > >> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"*
> > occupy
> > >> > > > *585,849,792
> > >> > > > (55.60%)* bytes. These instances are referenced from one
> instance
> > of
> > >> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > >> > *"<system
> > >> > > > class loader>"*
> > >> > > >
> > >> > > > *Keywords*
> > >> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > >> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > >> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > >> > > >
> > >> > > > While searching, I found [1] which is still open. Does this
> patch
> > >> > applied
> > >> > > > in openJPA 2.2 version ? Any idea why I might get this issue and
> > any
> > >> > > > suggestions to avoid this ?
> > >> > > >
> > >> > > > Thanks..
> > >> > > > Chathuri
> > >> > > >
> > >> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > >> > > >
> > >> > >
> > >> > >
> > >> > >
> > >> > > --
> > >> > > *Rick Curtis*
> > >> > >
> > >> >
> > >>
> > >
> > >
> >
>
>
>
> --
> *Rick Curtis*
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Rick Curtis <cu...@gmail.com>.
Can you post your heapdump somewhere?
On Fri, Jun 6, 2014 at 9:05 AM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> Appreciate someone's insight on this issue.
>
> Thanks..
> Chathuri
>
>
> On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <kamalasini@gmail.com
> >
> wrote:
>
> > Hi,
> >
> > Thanks for the responses. I checked almost all the places where we are
> > using entityManager instance and make sure they are closed after they
> have
> > been used.
> >
> > Here are the two suspect classes I'm getting when analysing the memory
> > dump.
> >
> > *Problem Suspect 1*
> >
> > 546,326 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> *1,031,525,848
> > (56.39%)* bytes. These instances are referenced from one instance of
> > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> > class loader>"*
> >
> > *Keywords*
> > java.util.concurrent.ConcurrentHashMap$Segment[]
> > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > org.apache.openjpa.kernel.FinalizingBrokerImpl
> >
> >
> > *Problem Suspect 2*
> >
> > 546,300 instances of *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
> *680,034,240
> > (37.17%)* bytes. These instances are referenced from one instance of
> > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> > class loader>"*
> >
> > *Keywords*
> > java.util.concurrent.ConcurrentHashMap$Segment[]
> > sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> > org.apache.openjpa.kernel.LocalManagedRuntime
> >
> > This is how we create the Entity manager instance.
> > public static EntityManager getEntityManager(){
> > if (factory == null) {
> > String connectionProperties = "DriverClassName=" +
> > Utils.getJDBCDriver() + "," + "Url=" +
> > Utils.getJDBCURL() + "," +"Username=" +
> Utils.getJDBCUser() +
> > "," + "Password=" +
> > Utils.getJDBCPassword() + ",validationQuery=" +
> > Utils.getValidationQuery() + "," +
> >
> > Utils.getJPAConnectionProperties();
> > Map<String, String> properties = new HashMap<String,
> String>();
> > properties.put("openjpa.ConnectionDriverName",
> > "org.apache.commons.dbcp.BasicDataSource");\
> > properties.put("openjpa.ConnectionProperties",
> > connectionProperties);
> > properties.put("openjpa.DynamicEnhancementAgent", "true");
> > properties.put("openjpa.RuntimeUnenhancedClasses",
> > "unsupported");
> > properties.put("openjpa.DataCache","true(CacheSize=5000,
> > SoftReferenceSize=0)");
> > properties.put("openjpa.QueryCache","true(CacheSize=5000,
> > SoftReferenceSize=0)");
> > properties.put("openjpa.RemoteCommitProvider","sjvm");
> > properties.put("openjpa.Log","DefaultLevel=INFO,
> Runtime=INFO,
> > Tool=INFO, SQL=INFO");
> > properties.put("openjpa.jdbc.SynchronizeMappings",
> > "buildSchema(ForeignKeys=true)");
> > properties.put("openjpa.jdbc.QuerySQLCache", "false");
> >
> > factory =
> > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
> properties);
> > }
> > return factory.createEntityManager();
> > }
> >
> > This is how we use entityManager and close it.
> > public void save() throws RegistryException {
> > EntityManager em = null;
> > try {
> > em = ResourceUtils.getEntityManager();
> > Gateway existingGateway = em.find(Gateway.class,
> gatewayName);
> > em.close();
> >
> > em = ResourceUtils.getEntityManager();
> > em.getTransaction().begin();
> > Gateway gateway = new Gateway();
> > gateway.setGateway_name(gatewayName);
> > gateway.setOwner(owner);
> > if (existingGateway != null) {
> > existingGateway.setOwner(owner);
> > gateway = em.merge(existingGateway);
> > } else {
> > em.persist(gateway);
> > }
> > em.getTransaction().commit();
> > em.close();
> > } catch (Exception e) {
> > logger.error(e.getMessage(), e);
> > throw new RegistryException(e);
> > } finally {
> > if (em != null && em.isOpen()) {
> > em.close();
> > }
> > }
> > }
> >
> > Do you see any issues with this implementation ?
> >
> >
> > Thanks..
> > Chathuri
> >
> >
> > On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kw...@gmail.com> wrote:
> >
> >> The scary part of the proposed patch is what impact this will have on
> the
> >> "more important" non-finalizing BrokerImpl... That is, if these two
> >> assignments would get reversed now to correct this supposed memory leak
> >> with FinalizingBrokerImpl, what impact would this have on non-finalizing
> >> BrokerImpls?
> >>
> >> if
> >>
> >>
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> >> {
> >> return MapBackedSet.decorate(new ConcurrentHashMap(), new
> >> Object() { });
> >> } else {
> >> return new
> >> ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> >> }
> >>
> >> I mean "more important" since in most cases we want the container to
> >> manage
> >> the lifecycle and, thus, avoid the overhead associated with the
> >> FinalizingBrokerImpl...
> >>
> >>
> >>
> >> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <
> kamalasini@gmail.com
> >> >
> >> wrote:
> >>
> >> > I'm closing all the EntityManagers in a finally block. I will check
> if I
> >> > miss any place.
> >> >
> >> >
> >> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com>
> wrote:
> >> >
> >> > > > Any idea why I might get this issue and any suggestions to avoid
> >> this ?
> >> > > Please make sure that your application closes all EntityManagers
> when
> >> > > you're through with them.
> >> > >
> >> > > Thanks,
> >> > > Rick
> >> > >
> >> > >
> >> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> >> > kamalasini@gmail.com
> >> > > >
> >> > > wrote:
> >> > >
> >> > > > Hi Devs,
> >> > > >
> >> > > > We are using apache openJPA 2.2 version and we experience some
> >> memory
> >> > > leak
> >> > > > issues. While analyzing the memory dump, I see
> >> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> >> > > > *as one suspect for the memory leak.
> >> > > >
> >> > > > 311,437 instances of
> >> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> >> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"*
> occupy
> >> > > > *585,849,792
> >> > > > (55.60%)* bytes. These instances are referenced from one instance
> of
> >> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> >> > *"<system
> >> > > > class loader>"*
> >> > > >
> >> > > > *Keywords*
> >> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> >> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> >> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> >> > > >
> >> > > > While searching, I found [1] which is still open. Does this patch
> >> > applied
> >> > > > in openJPA 2.2 version ? Any idea why I might get this issue and
> any
> >> > > > suggestions to avoid this ?
> >> > > >
> >> > > > Thanks..
> >> > > > Chathuri
> >> > > >
> >> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> >> > > >
> >> > >
> >> > >
> >> > >
> >> > > --
> >> > > *Rick Curtis*
> >> > >
> >> >
> >>
> >
> >
>
--
*Rick Curtis*
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Chathuri Wimalasena <ka...@gmail.com>.
Appreciate someone's insight on this issue.
Thanks..
Chathuri
On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> Hi,
>
> Thanks for the responses. I checked almost all the places where we are
> using entityManager instance and make sure they are closed after they have
> been used.
>
> Here are the two suspect classes I'm getting when analysing the memory
> dump.
>
> *Problem Suspect 1*
>
> 546,326 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy *1,031,525,848
> (56.39%)* bytes. These instances are referenced from one instance of
> *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> class loader>"*
>
> *Keywords*
> java.util.concurrent.ConcurrentHashMap$Segment[]
> sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> org.apache.openjpa.kernel.FinalizingBrokerImpl
>
>
> *Problem Suspect 2*
>
> 546,300 instances of *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
> loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy *680,034,240
> (37.17%)* bytes. These instances are referenced from one instance of
> *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> class loader>"*
>
> *Keywords*
> java.util.concurrent.ConcurrentHashMap$Segment[]
> sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
> org.apache.openjpa.kernel.LocalManagedRuntime
>
> This is how we create the Entity manager instance.
> public static EntityManager getEntityManager(){
> if (factory == null) {
> String connectionProperties = "DriverClassName=" +
> Utils.getJDBCDriver() + "," + "Url=" +
> Utils.getJDBCURL() + "," +"Username=" + Utils.getJDBCUser() +
> "," + "Password=" +
> Utils.getJDBCPassword() + ",validationQuery=" +
> Utils.getValidationQuery() + "," +
>
> Utils.getJPAConnectionProperties();
> Map<String, String> properties = new HashMap<String, String>();
> properties.put("openjpa.ConnectionDriverName",
> "org.apache.commons.dbcp.BasicDataSource");\
> properties.put("openjpa.ConnectionProperties",
> connectionProperties);
> properties.put("openjpa.DynamicEnhancementAgent", "true");
> properties.put("openjpa.RuntimeUnenhancedClasses",
> "unsupported");
> properties.put("openjpa.DataCache","true(CacheSize=5000,
> SoftReferenceSize=0)");
> properties.put("openjpa.QueryCache","true(CacheSize=5000,
> SoftReferenceSize=0)");
> properties.put("openjpa.RemoteCommitProvider","sjvm");
> properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO,
> Tool=INFO, SQL=INFO");
> properties.put("openjpa.jdbc.SynchronizeMappings",
> "buildSchema(ForeignKeys=true)");
> properties.put("openjpa.jdbc.QuerySQLCache", "false");
>
> factory =
> Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
> }
> return factory.createEntityManager();
> }
>
> This is how we use entityManager and close it.
> public void save() throws RegistryException {
> EntityManager em = null;
> try {
> em = ResourceUtils.getEntityManager();
> Gateway existingGateway = em.find(Gateway.class, gatewayName);
> em.close();
>
> em = ResourceUtils.getEntityManager();
> em.getTransaction().begin();
> Gateway gateway = new Gateway();
> gateway.setGateway_name(gatewayName);
> gateway.setOwner(owner);
> if (existingGateway != null) {
> existingGateway.setOwner(owner);
> gateway = em.merge(existingGateway);
> } else {
> em.persist(gateway);
> }
> em.getTransaction().commit();
> em.close();
> } catch (Exception e) {
> logger.error(e.getMessage(), e);
> throw new RegistryException(e);
> } finally {
> if (em != null && em.isOpen()) {
> em.close();
> }
> }
> }
>
> Do you see any issues with this implementation ?
>
>
> Thanks..
> Chathuri
>
>
> On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kw...@gmail.com> wrote:
>
>> The scary part of the proposed patch is what impact this will have on the
>> "more important" non-finalizing BrokerImpl... That is, if these two
>> assignments would get reversed now to correct this supposed memory leak
>> with FinalizingBrokerImpl, what impact would this have on non-finalizing
>> BrokerImpls?
>>
>> if
>>
>> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
>> {
>> return MapBackedSet.decorate(new ConcurrentHashMap(), new
>> Object() { });
>> } else {
>> return new
>> ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
>> }
>>
>> I mean "more important" since in most cases we want the container to
>> manage
>> the lifecycle and, thus, avoid the overhead associated with the
>> FinalizingBrokerImpl...
>>
>>
>>
>> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <kamalasini@gmail.com
>> >
>> wrote:
>>
>> > I'm closing all the EntityManagers in a finally block. I will check if I
>> > miss any place.
>> >
>> >
>> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com> wrote:
>> >
>> > > > Any idea why I might get this issue and any suggestions to avoid
>> this ?
>> > > Please make sure that your application closes all EntityManagers when
>> > > you're through with them.
>> > >
>> > > Thanks,
>> > > Rick
>> > >
>> > >
>> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
>> > kamalasini@gmail.com
>> > > >
>> > > wrote:
>> > >
>> > > > Hi Devs,
>> > > >
>> > > > We are using apache openJPA 2.2 version and we experience some
>> memory
>> > > leak
>> > > > issues. While analyzing the memory dump, I see
>> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
>> > > > *as one suspect for the memory leak.
>> > > >
>> > > > 311,437 instances of
>> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
>> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
>> > > > *585,849,792
>> > > > (55.60%)* bytes. These instances are referenced from one instance of
>> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
>> > *"<system
>> > > > class loader>"*
>> > > >
>> > > > *Keywords*
>> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
>> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
>> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
>> > > >
>> > > > While searching, I found [1] which is still open. Does this patch
>> > applied
>> > > > in openJPA 2.2 version ? Any idea why I might get this issue and any
>> > > > suggestions to avoid this ?
>> > > >
>> > > > Thanks..
>> > > > Chathuri
>> > > >
>> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
>> > > >
>> > >
>> > >
>> > >
>> > > --
>> > > *Rick Curtis*
>> > >
>> >
>>
>
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Chathuri Wimalasena <ka...@gmail.com>.
Hi,
Thanks for the responses. I checked almost all the places where we are
using entityManager instance and make sure they are closed after they have
been used.
Here are the two suspect classes I'm getting when analysing the memory dump.
*Problem Suspect 1*
546,326 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
*1,031,525,848
(56.39%)* bytes. These instances are referenced from one instance of
*"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
class loader>"*
*Keywords*
java.util.concurrent.ConcurrentHashMap$Segment[]
sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
org.apache.openjpa.kernel.FinalizingBrokerImpl
*Problem Suspect 2*
546,300 instances of *"org.apache.openjpa.kernel.LocalManagedRuntime"*,
loaded by *"sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0"* occupy
*680,034,240
(37.17%)* bytes. These instances are referenced from one instance of
*"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
class loader>"*
*Keywords*
java.util.concurrent.ConcurrentHashMap$Segment[]
sun.misc.Launcher$AppClassLoader @ 0x7007c7bc0
org.apache.openjpa.kernel.LocalManagedRuntime
This is how we create the Entity manager instance.
public static EntityManager getEntityManager(){
if (factory == null) {
String connectionProperties = "DriverClassName=" +
Utils.getJDBCDriver() + "," + "Url=" +
Utils.getJDBCURL() + "," +"Username=" + Utils.getJDBCUser() +
"," + "Password=" +
Utils.getJDBCPassword() + ",validationQuery=" +
Utils.getValidationQuery() + "," +
Utils.getJPAConnectionProperties();
Map<String, String> properties = new HashMap<String, String>();
properties.put("openjpa.ConnectionDriverName",
"org.apache.commons.dbcp.BasicDataSource");\
properties.put("openjpa.ConnectionProperties",
connectionProperties);
properties.put("openjpa.DynamicEnhancementAgent", "true");
properties.put("openjpa.RuntimeUnenhancedClasses",
"unsupported");
properties.put("openjpa.DataCache","true(CacheSize=5000,
SoftReferenceSize=0)");
properties.put("openjpa.QueryCache","true(CacheSize=5000,
SoftReferenceSize=0)");
properties.put("openjpa.RemoteCommitProvider","sjvm");
properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO,
Tool=INFO, SQL=INFO");
properties.put("openjpa.jdbc.SynchronizeMappings",
"buildSchema(ForeignKeys=true)");
properties.put("openjpa.jdbc.QuerySQLCache", "false");
factory =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
}
return factory.createEntityManager();
}
This is how we use entityManager and close it.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ResourceUtils.getEntityManager();
Gateway existingGateway = em.find(Gateway.class, gatewayName);
em.close();
em = ResourceUtils.getEntityManager();
em.getTransaction().begin();
Gateway gateway = new Gateway();
gateway.setGateway_name(gatewayName);
gateway.setOwner(owner);
if (existingGateway != null) {
existingGateway.setOwner(owner);
gateway = em.merge(existingGateway);
} else {
em.persist(gateway);
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
em.close();
}
}
}
Do you see any issues with this implementation ?
Thanks..
Chathuri
On Mon, Jun 2, 2014 at 6:52 PM, Kevin Sutter <kw...@gmail.com> wrote:
> The scary part of the proposed patch is what impact this will have on the
> "more important" non-finalizing BrokerImpl... That is, if these two
> assignments would get reversed now to correct this supposed memory leak
> with FinalizingBrokerImpl, what impact would this have on non-finalizing
> BrokerImpls?
>
> if
>
> (FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
> {
> return MapBackedSet.decorate(new ConcurrentHashMap(), new
> Object() { });
> } else {
> return new
> ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
> }
>
> I mean "more important" since in most cases we want the container to manage
> the lifecycle and, thus, avoid the overhead associated with the
> FinalizingBrokerImpl...
>
>
>
> On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <ka...@gmail.com>
> wrote:
>
> > I'm closing all the EntityManagers in a finally block. I will check if I
> > miss any place.
> >
> >
> > On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com> wrote:
> >
> > > > Any idea why I might get this issue and any suggestions to avoid
> this ?
> > > Please make sure that your application closes all EntityManagers when
> > > you're through with them.
> > >
> > > Thanks,
> > > Rick
> > >
> > >
> > > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> > kamalasini@gmail.com
> > > >
> > > wrote:
> > >
> > > > Hi Devs,
> > > >
> > > > We are using apache openJPA 2.2 version and we experience some memory
> > > leak
> > > > issues. While analyzing the memory dump, I see
> > > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > > *as one suspect for the memory leak.
> > > >
> > > > 311,437 instances of
> > *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
> > > > *585,849,792
> > > > (55.60%)* bytes. These instances are referenced from one instance of
> > > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> > *"<system
> > > > class loader>"*
> > > >
> > > > *Keywords*
> > > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > >
> > > > While searching, I found [1] which is still open. Does this patch
> > applied
> > > > in openJPA 2.2 version ? Any idea why I might get this issue and any
> > > > suggestions to avoid this ?
> > > >
> > > > Thanks..
> > > > Chathuri
> > > >
> > > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > > >
> > >
> > >
> > >
> > > --
> > > *Rick Curtis*
> > >
> >
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Kevin Sutter <kw...@gmail.com>.
The scary part of the proposed patch is what impact this will have on the
"more important" non-finalizing BrokerImpl... That is, if these two
assignments would get reversed now to correct this supposed memory leak
with FinalizingBrokerImpl, what impact would this have on non-finalizing
BrokerImpls?
if
(FinalizingBrokerImpl.class.isAssignableFrom(bv.getTemplateBrokerType(_conf)))
{
return MapBackedSet.decorate(new ConcurrentHashMap(), new
Object() { });
} else {
return new
ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
}
I mean "more important" since in most cases we want the container to manage
the lifecycle and, thus, avoid the overhead associated with the
FinalizingBrokerImpl...
On Mon, Jun 2, 2014 at 1:26 PM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> I'm closing all the EntityManagers in a finally block. I will check if I
> miss any place.
>
>
> On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com> wrote:
>
> > > Any idea why I might get this issue and any suggestions to avoid this ?
> > Please make sure that your application closes all EntityManagers when
> > you're through with them.
> >
> > Thanks,
> > Rick
> >
> >
> > On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <
> kamalasini@gmail.com
> > >
> > wrote:
> >
> > > Hi Devs,
> > >
> > > We are using apache openJPA 2.2 version and we experience some memory
> > leak
> > > issues. While analyzing the memory dump, I see
> > > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > > *as one suspect for the memory leak.
> > >
> > > 311,437 instances of
> *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
> > > *585,849,792
> > > (55.60%)* bytes. These instances are referenced from one instance of
> > > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by
> *"<system
> > > class loader>"*
> > >
> > > *Keywords*
> > > java.util.concurrent.ConcurrentHashMap$Segment[]
> > > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > > org.apache.openjpa.kernel.FinalizingBrokerImpl
> > >
> > > While searching, I found [1] which is still open. Does this patch
> applied
> > > in openJPA 2.2 version ? Any idea why I might get this issue and any
> > > suggestions to avoid this ?
> > >
> > > Thanks..
> > > Chathuri
> > >
> > > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Chathuri Wimalasena <ka...@gmail.com>.
I'm closing all the EntityManagers in a finally block. I will check if I
miss any place.
On Mon, Jun 2, 2014 at 2:17 PM, Rick Curtis <cu...@gmail.com> wrote:
> > Any idea why I might get this issue and any suggestions to avoid this ?
> Please make sure that your application closes all EntityManagers when
> you're through with them.
>
> Thanks,
> Rick
>
>
> On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <kamalasini@gmail.com
> >
> wrote:
>
> > Hi Devs,
> >
> > We are using apache openJPA 2.2 version and we experience some memory
> leak
> > issues. While analyzing the memory dump, I see
> > *org.apache.openjpa.kernel.FinalizingBrokerImpl
> > *as one suspect for the memory leak.
> >
> > 311,437 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> > loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
> > *585,849,792
> > (55.60%)* bytes. These instances are referenced from one instance of
> > *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> > class loader>"*
> >
> > *Keywords*
> > java.util.concurrent.ConcurrentHashMap$Segment[]
> > sun.misc.Launcher$AppClassLoader @ 0x117a09088
> > org.apache.openjpa.kernel.FinalizingBrokerImpl
> >
> > While searching, I found [1] which is still open. Does this patch applied
> > in openJPA 2.2 version ? Any idea why I might get this issue and any
> > suggestions to avoid this ?
> >
> > Thanks..
> > Chathuri
> >
> > [1] https://issues.apache.org/jira/browse/OPENJPA-1193
> >
>
>
>
> --
> *Rick Curtis*
>
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Rick Curtis <cu...@gmail.com>.
> Any idea why I might get this issue and any suggestions to avoid this ?
Please make sure that your application closes all EntityManagers when
you're through with them.
Thanks,
Rick
On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> Hi Devs,
>
> We are using apache openJPA 2.2 version and we experience some memory leak
> issues. While analyzing the memory dump, I see
> *org.apache.openjpa.kernel.FinalizingBrokerImpl
> *as one suspect for the memory leak.
>
> 311,437 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
> *585,849,792
> (55.60%)* bytes. These instances are referenced from one instance of
> *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> class loader>"*
>
> *Keywords*
> java.util.concurrent.ConcurrentHashMap$Segment[]
> sun.misc.Launcher$AppClassLoader @ 0x117a09088
> org.apache.openjpa.kernel.FinalizingBrokerImpl
>
> While searching, I found [1] which is still open. Does this patch applied
> in openJPA 2.2 version ? Any idea why I might get this issue and any
> suggestions to avoid this ?
>
> Thanks..
> Chathuri
>
> [1] https://issues.apache.org/jira/browse/OPENJPA-1193
>
--
*Rick Curtis*
Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl
Posted by Kevin Sutter <kw...@gmail.com>.
Interesting! Looking at this JIRA, it looks like the proposed change was
put into 1.3.0 and tentatively put into the 2.0 stream. But, then it was
backed out to some performance concern...
Any chance you could run with this patch and see if it helps with your
memory leak?
As Patrick indicated in the nabble post, the use of FinalizingBrokerImpl is
a "stop gap" measure. But, if you must run with it, then we should try to
identify the source of the memory leak and resolve it.
Kevin
On Mon, Jun 2, 2014 at 12:20 PM, Chathuri Wimalasena <ka...@gmail.com>
wrote:
> Hi Devs,
>
> We are using apache openJPA 2.2 version and we experience some memory leak
> issues. While analyzing the memory dump, I see
> *org.apache.openjpa.kernel.FinalizingBrokerImpl
> *as one suspect for the memory leak.
>
> 311,437 instances of *"org.apache.openjpa.kernel.FinalizingBrokerImpl"*,
> loaded by *"sun.misc.Launcher$AppClassLoader @ 0x117a09088"* occupy
> *585,849,792
> (55.60%)* bytes. These instances are referenced from one instance of
> *"java.util.concurrent.ConcurrentHashMap$Segment[]"*, loaded by *"<system
> class loader>"*
>
> *Keywords*
> java.util.concurrent.ConcurrentHashMap$Segment[]
> sun.misc.Launcher$AppClassLoader @ 0x117a09088
> org.apache.openjpa.kernel.FinalizingBrokerImpl
>
> While searching, I found [1] which is still open. Does this patch applied
> in openJPA 2.2 version ? Any idea why I might get this issue and any
> suggestions to avoid this ?
>
> Thanks..
> Chathuri
>
> [1] https://issues.apache.org/jira/browse/OPENJPA-1193
>