Return-Path: X-Original-To: apmail-openjpa-dev-archive@www.apache.org Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7303111A2B for ; Fri, 6 Jun 2014 14:06:22 +0000 (UTC) Received: (qmail 91211 invoked by uid 500); 6 Jun 2014 14:06:22 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 91150 invoked by uid 500); 6 Jun 2014 14:06:22 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 91139 invoked by uid 99); 6 Jun 2014 14:06:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jun 2014 14:06:22 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kamalasini@gmail.com designates 209.85.217.180 as permitted sender) Received: from [209.85.217.180] (HELO mail-lb0-f180.google.com) (209.85.217.180) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jun 2014 14:06:18 +0000 Received: by mail-lb0-f180.google.com with SMTP id p9so1503477lbv.25 for ; Fri, 06 Jun 2014 07:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=zkkFE74ivkanIxT8sZh+wb96ION8+hHPGCrLoc8mRng=; b=W91SkdYlfl9FHfWCJSksU6JHis/zbuaPxk5dbXU44EXyyI6V2T1I5hTdiizavQiUtM sNY/e0GaXGX+W5WriIwwiEdzDAaqCeKQ5kPAtRsHVJPQ+rm676mt4jYduRyMcTzxX/lg ReED2SU7mT4O+f/HAyXHMNyLdNVrb7dfL3phYk5++/y2FUiUXj6OPpd858zK1+QXIcay aQhiDqrgDtFhqv4tuyBwqMYNgwMwff2NYGN5TvkSrchGkY1Uet2vFYLwQXtJNV54Bb23 ZV+hO0eqF6hZrNRoGNmivUhrqOMVQAVgbTyBqbrlSwvjres/Zn0E27Ndhx+qFPSk6a0Q 6SIg== X-Received: by 10.112.34.210 with SMTP id b18mr3680096lbj.42.1402063554310; Fri, 06 Jun 2014 07:05:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.189.2 with HTTP; Fri, 6 Jun 2014 07:05:33 -0700 (PDT) In-Reply-To: References: From: Chathuri Wimalasena Date: Fri, 6 Jun 2014 10:05:33 -0400 Message-ID: Subject: Re: Is there a memory leak with org.apache.openjpa.kernel.FinalizingBrokerImpl To: dev@openjpa.apache.org Content-Type: multipart/alternative; boundary=14dae93d93801b77a404fb2b5cf9 X-Virus-Checked: Checked by ClamAV on apache.org --14dae93d93801b77a404fb2b5cf9 Content-Type: text/plain; charset=UTF-8 Appreciate someone's insight on this issue. Thanks.. Chathuri On Tue, Jun 3, 2014 at 12:22 PM, Chathuri Wimalasena 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 *" 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 *" 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 properties = new HashMap(); > 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 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(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 > > >> 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 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 >> > *"> > > > 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* >> > > >> > >> > > --14dae93d93801b77a404fb2b5cf9--