-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Jboss OutOfMemoryError after 30K-40K inserts/updates
PostPosted: Tue Aug 24, 2004 5:23 pm 
Newbie

Joined: Tue Aug 24, 2004 4:54 pm
Posts: 4
Hello, I am getting OutOfMemory Errors. I have looked through the Forums and attempted to find similar problems. I have discovered many things there and attempted to incorporate them in my code.

What is happening is that I have a test harness which is calling the saveEventAndAlarm() method (listed below) 100,000 times. I am trying to determine performance characteristics, as well as determine what happens when I call the routine this many times. I am flushing, clearing, and closing my session in an attempt to get rid of the caches.

What I am seeing is that approximately 30K to 40K entries are entered, and then the OutOfMemoryError that is shown occurs.

One thing of note. The alarm that is passed is kept in a hashtable. This is done for quick access. The number of alarms is small, and in my test case, there are only two that are ever created. However, the same object is used over and over to do an update, as the time on the alarm needs to be updated.

I do not keep the event.

Am I doing something incorrectly?

Thank you,
Roger


Hibernate version:

2.1.6, 9.8.2004

JBoss

JBoss Version 3.2.3

The jboss_service.xml I am using
Code:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
                            name=HibernateFactory">
    <depends>jboss.jca:service=RARDeployer</depends>
    <depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>  <!-- Make it deploy ONLY after DataSource had been started -->
    <attribute name="MapResources">
         mappings/SVAlarm.hbm.xml,
         mappings/SVAlarmEvent.hbm.xml
    </attribute>
    <attribute name="JndiName">java:/HibernateFactory</attribute>
    <attribute name="Datasource">java:/MySqlDS</attribute>
    <attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
    <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
    <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
    <attribute name="ShowSql">true</attribute>
    <attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>


Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.cedarpointcom.safariview2.common.alarms">
    <class name="SVAlarm" table="svalarms">
            <id name="eid" column="uid" type="long">
                    <generator class="increment"/>
            </id>
            <property name="name" not-null="true">
                <column name="name" sql-type="char(25)"/>
            </property>
            <property name="severity" not-null="true">
                <column name="severity" sql-type="char(25)"/>
            </property>
            <property name="entityType" not-null="true">
                <column name="entitytype" sql-type="char(25)"/>
            </property>
            <property name="entityKey" not-null="true">
                <column name="entitykey" sql-type="char(50)"/>
            </property>
            <property name="deviceId" not-null="true"> <!-- this should be fk to device -->
                <column name="deviceid" sql-type="char(25)"/>
            </property>
            <property name="setState" not-null="true"/>
            <property name="suppressState" />
            <property name="timeCreated" not-null="true"/>
            <property name="timeModified" not-null="true"/>
            <property name="owner"> <!-- the user assigned to, users not stored in db-->
                <column name="owner" sql-type="char(25)"/>
            </property>
            <property name="notes" />
            <property name="managedObjType">
                <column name="managedObjType" sql-type="char(25)"/>
            </property>
            <property name="managedObjKey">
                <column name="managedObjKey" sql-type="char(50)"/>
            </property>
    </class>

</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.cedarpointcom.safariview2.common.alarms">
    <class name="SVAlarmEvent" table="svevents" lazy="true">
            <id name="eid" column="uid" type="long">
                    <generator class="increment"/>
            </id>
            <property name="name" not-null="true">
                <column name="name" sql-type="char(25)"/>
            </property>
            <property name="severity" not-null="true">
                <column name="severity" sql-type="char(25)"/>
            </property>
            <property name="entityType" not-null="true">
                <column name="entitytype" sql-type="char(25)"/>
            </property>
            <property name="entityKey" not-null="true">
                <column name="entitykey" sql-type="char(50)"/>
            </property>
            <property name="deviceId" not-null="true">
                <column name="deviceid" sql-type="char(25)"/>
            </property>
            <property name="timeStamp" not-null="true"/>
            <property name="setAction" not-null="true"/>
            <property name="reasonCode" not-null="true"/>
            <property name="alarmId" not-null="true"/>
    </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
public class HibernateUtil
{
    // TODO: find out if this is safe
   
    static SessionFactory factory = null;
    public static SessionFactory getSessionFactory() throws NamingException
    {
        if ( factory == null )
        {
            InitialContext initialContext = new InitialContext();
            factory = (SessionFactory)initialContext.lookup("java:/HibernateFactory");
        }
        return factory;
    }

    public static Session getSession() throws SafariViewException
    {
        Session session = null;
        try
        {
            SessionFactory factory = getSessionFactory();
            session = factory.openSession();
        }
        catch(NamingException ne)
        {
            ne.printStackTrace();
            throw new SafariViewException("UNABLE TO GET DB (HIBERNATE) SESSION FACTORY!",ne);
        }
        catch (HibernateException he)
        {
            he.printStackTrace();
            throw new SafariViewException("UNABLE TO OBTAIN DB (HIBERNATE) SESSION!", he);
        }
        return session;
    }

    public static Transaction getTransaction(Session session) throws SafariViewException
    {
        Transaction tx = null;
        try
        {
            tx = session.beginTransaction();
        }
        catch(HibernateException he)
        {
            he.printStackTrace();
            try
            {
                session.close();
            }
            catch(HibernateException closeex)
            {
                closeex.printStackTrace();               
                throw new SafariViewException("Could Not Close Session: Transaction could not be created", closeex);
            }
            throw new SafariViewException("UNABLE TO BEGIN TRANSACTION", he);
        }
        return tx;
    }
}


Code:
    void saveEventAndAlarm(SVAlarmEvent event, SVAlarm alarm) throws SafariViewException
    {
        Session session = HibernateUtil.getSession();
        session.clear();
        Transaction tx = HibernateUtil.getTransaction(session);
        boolean rollbackfailed = false;
        try
        {
            session.saveOrUpdate(alarm);
            System.out.println("alarm Eid is " + alarm.getEid());

            event.setAlarmId(alarm.getEid());
            session.saveOrUpdate(event);
            tx.commit();
        }
        catch(HibernateException he)
        {
            he.printStackTrace();
            try{ tx.rollback(); }
            catch(HibernateException rollbacke)
            {
                rollbackfailed = true;
                rollbacke.printStackTrace();
            }
            throw new SafariViewException("Could Not Save Event and Alarm", he);
        }
        finally
        {
            try
            {
                session.flush();
                session.clear();
                session.close();
            }
            catch(HibernateException closeException)
            {
                StringBuffer error = new StringBuffer("Call to Session.Close() failed:");
                if ( rollbackfailed )
                    error.append(" A Rollback Failure also indicates that the Event and Alarm were not saved.");
                throw new SafariViewException(error.toString(), closeException);
            }
        }
    }

Full stack trace of any exception that occurs:

16:36:10,763 INFO [STDOUT] Error occurred during test: javax.transaction.Transa
ctionRolledbackException: null; nested exception is:
java.lang.OutOfMemoryError
16:36:10,763 ERROR [STDERR] javax.transaction.TransactionRolledbackException: nu
ll; nested exception is:
java.lang.OutOfMemoryError
16:36:10,763 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:214)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:267)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:128)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
oke(SecurityInterceptor.java:118)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
ogInterceptor.java:191)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.inter
nalInvoke(StatelessSessionContainer.java:331)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java
:700)
16:36:10,779 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor37.invoke(
Unknown Source)
16:36:10,779 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
16:36:10,779 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
16:36:10,779 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatc
her.invoke(ReflectedMBeanDispatcher.java:284)
16:36:10,779 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
eanServerImpl.java:546)
16:36:10,779 ERROR [STDERR] at org.jboss.invocation.local.LocalInvoker.invok
e(LocalInvoker.java:101)
16:36:10,779 ERROR [STDERR] at org.jboss.invocation.InvokerInterceptor.invok
e(InvokerInterceptor.java:90)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.TransactionInterceptor.invoke
(TransactionInterceptor.java:46)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.SecurityInterceptor.invoke(Se
curityInterceptor.java:45)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.ejb.StatelessSessionIntercept
or.invoke(StatelessSessionInterceptor.java:100)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.ClientContainer.invoke(Client
Container.java:85)
16:36:10,779 ERROR [STDERR] at $Proxy52.makeRequest(Unknown Source)
16:36:10,779 ERROR [STDERR] at com.cedarpointcom.safariview2.server.alarms.A
larmManagerEJB.test(Unknown Source)
16:36:10,779 ERROR [STDERR] at com.cedarpointcom.safariview2.server.RequestM
anagerEJB.initialize(Unknown Source)
16:36:10,779 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
16:36:10,779 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
16:36:10,779 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
16:36:10,794 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$Conta
inerInterceptor.invoke(StatelessSessionContainer.java:683)
16:36:10,794 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedCo
nnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanc
eInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:84)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:267)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:128)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
oke(SecurityInterceptor.java:118)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
ogInterceptor.java:191)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.inter
nalInvoke(StatelessSessionContainer.java:331)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java
:700)
16:36:10,794 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
16:36:10,794 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
16:36:10,794 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
16:36:10,794 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
16:36:10,794 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatc
her.invoke(ReflectedMBeanDispatcher.java:284)
16:36:10,810 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
eanServerImpl.java:546)
16:36:12,278 ERROR [STDERR] at org.jboss.invocation.local.LocalInvoker.invok
e(LocalInvoker.java:101)
16:36:12,294 ERROR [STDERR] at org.jboss.invocation.InvokerInterceptor.invok
e(InvokerInterceptor.java:90)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.TransactionInterceptor.invoke
(TransactionInterceptor.java:46)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.SecurityInterceptor.invoke(Se
curityInterceptor.java:45)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.ejb.StatelessSessionIntercept
or.invoke(StatelessSessionInterceptor.java:100)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.ClientContainer.invoke(Client
Container.java:85)
16:36:12,294 ERROR [STDERR] at $Proxy44.initialize(Unknown Source)
16:36:12,294 ERROR [STDERR] at com.cedarpointcom.safariview2.common.SafariVi
ewStartupService$InitializeSafariViewThread.run(Unknown Source)
16:36:12,294 ERROR [STDERR] Caused by: java.lang.OutOfMemoryError
16:36:12,294 ERROR [STDERR] java.lang.OutOfMemoryError


Name and version of the database you are using:

MYSql - version 4.0.20d

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 10:49 am 
Newbie

Joined: Tue Aug 24, 2004 4:54 pm
Posts: 4
An update. I continue to debug this problem and have changed my code a bit.

I removed the static SessionFacotry. I am currently doing a JNDI lookup everytime now. There were no more OutOfMemoryError exceptions, but I was getting a RollBack excepiton such as:

09:58:14,,536 ERROR
[net.sf.hibernate.transaction.JTATransaction] Could not register Synchronization
javax.transaction.RollbackException: Already marked for rollback


I removed transactions from my saveAlarmAndEvent call because of an apparent problem with transactions, as discussed in this thread:

http://forum.hibernate.org/viewtopic.ph ... d+rollback

After I removed the transaction code I ran it again. Now I am getting the OutOfMemoryError again. There are times I see JTATransaction errors as described in other threads, but I believe these too are related to the memory, as they happen only after the memory is starved and the process becomes sluggish due to memory requirements.

I am very sure that the memory leak is not in my test code. When I simply comment out the saveEventAndAlarm() method, I can run through hundreds of thousands of iterations with no gain in memory usuage.

Roger


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 1:20 pm 
Newbie

Joined: Tue Aug 24, 2004 4:54 pm
Posts: 4
Ok, I've figured out how to keep this thing running and thought I'd post what I've found here just in case someone else may find this useful.

First off, I kept the static Factory reference. That was a red herring, and the static reference to the factory is (as would be expected) causing no problems at all.

To fix the problem I was having, not only did I remove the call to begin transaction and end transaction, I had to remove the TransactionStrategy,
TransactionManagerLookupStrategy, and UserTransactionName attributes from the jboss_service.xml file. After I did this, i could perform my test with no problems, I have processed 200,000+ inserts and updates without any increase in memory.

Unfortunatly this means I have no ability to do transactions at the moment, but I don't think I need them at this time. I'm hoping when I do need them, this bug will be fixed.

I have a couple questions. Is this a JBoss bug or a hibernate bug? Is someone looking into this problem?

Roger


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 7:01 pm 
Newbie

Joined: Sat Aug 14, 2004 6:44 am
Posts: 17
Location: Auckland, NZ
Perhaps you should retest this running multiple clients under load. That static reference doesn't look good.

While many people don't bother, there is a close() on the initialContext.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 10:01 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
If you are using the JBoss MBean to start Hibernate and put the session factory in JNDI, you are using JTA transactions. It is a bad thing to also use Hibernate transactions in this case.

See http://www.hibernate.org/hib_docs/reference/en/html/manipulatingdata.html#manipulatingdata-endingsession-exceptions

The last example in this section is what you want to use.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 11:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Correction:

Using beginTransaction() etc. under a CMT (Container Managed Transaction) via JTA is 100% ok - Hibernate will just join the ongoing transaction.

That is a Good Thing as it allow you to use the exact same code inside as well as outside an container.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 29, 2004 10:12 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
max wrote:
Correction:

Using beginTransaction() etc. under a CMT (Container Managed Transaction) via JTA is 100% ok - Hibernate will just join the ongoing transaction.

That is a Good Thing as it allow you to use the exact same code inside as well as outside an container.


It is a great thing! But the documentation I referred to implies something very different. Was this always the case, or did it change at a particular version? Regardless, the documentaiton should reflect the JTA/beginTransaction() capability.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 3:33 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, the documentation says "The following idiom is recommended" and uses the Transaction API.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:57 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
Hi all,


I´m using Hibernate 2.14 with Jboss 3.2.3 and Oracle9i.

I found the example:

Code:
SessionContext ctx = ... ;
Session sess = factory.openSession();
try {
    // do some work
    ...
    sess.flush();
}
catch (Exception e) {
    // ctx.setRollbackOnly();
    throw new EJBException(e);
}
finally {
    sess.close();
}


I´m working with JTATransaction, but I´m using like this:

Code:
Session sess = factory.openSession();
Transaction tx = null;
try {
    tx = sess.beginTransaction();
    // do some work
    ...
    tx.commit();
}
catch (Exception e) {
    if (tx!=null) tx.rollback();
    throw e;
}
finally {
    sess.close();
}


To the exception "Already Marked for Rollback" doesn´t appear more, can I do this?

Code:
Session sess = factory.openSession();
Transaction tx = null;
try {
    tx = sess.beginTransaction();
    // do some work
    ...
    tx.commit();
}
catch (Exception e)
{
    if (tx!=null)
    {
         if (!tx.wasRolledBack()) // to avoid Already Marked for Rollback
         {
             tx.rollback();
         }
    }
    throw e;
}
finally
{
    sess.close();
}


thanks!

Tads

_________________
Tads


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.