-->
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.  [ 2 posts ] 
Author Message
 Post subject: OutOfMemoryError in simple stress test
PostPosted: Tue Dec 14, 2004 9:59 am 
Newbie

Joined: Mon Nov 08, 2004 6:03 pm
Posts: 8
Hibernate version: 2.1.2

Name and version of the database you are using:MySQL 4.1.5

The generated SQL (show_sql=true):true

Hi I have a simple JUnit test that loops forever calling the specified method:

Code:
    public void testIt() throws Throwable {
        try {
            long count = 0;
            while (true) {
                runHibernateQuery();
                Thread.sleep(1L);
                System.out.println("*** LOOP: " + (++count));
            }
        } catch (Throwable t) {
            t.printStackTrace();
            throw t;
        }
    }

    protected void runHibernateQuery() throws Exception {
        if (sessionFactory == null) {
           sessionFactory = createSessionFactory();
        }
        Session session = sessionFactory.openSession();
        net.sf.hibernate.Transaction tx = null;
        try {
            tx = session.beginTransaction();
            net.sf.hibernate.Query query = session.createQuery("FROM MyTable");
            Iterator iterator = query.iterate();
            while (iterator.hasNext()) {
                Object object = iterator.next();
                System.out.println(">>> Got Object: " + object);
                session.evict(object);
            }
            if (iterator instanceof HibernateIterator) {
                // I know, probably don't need to do this but trying anything here.
                ((HibernateIterator) iterator).close();
            }
            tx.commit();
        } catch (Exception e) {
            if (tx != null) {
                tx.rollback();
            }
            throw e;
        } finally {
            session.close();
        }
    }


I create the SessionFactory once using default hibernate properties. The test runs for ONLY 1500 iterations then I get an OutOfMemoryError. I'm running with the Java memory profiler on and the memory usage steadily increases. I'm also using the default initial and maximum memory sizes (64 megs I assume). Under real conditions we have these settings larger but in this simple test why should running the same query over and over with closing the session each time increase the memory?

I'm not sure where the problem lies. I am aware that (from searching this forum) that its highly unlikely its a hibernate problem but I really can't make the test more simple than this. The only possible alternative could be a MySQL leak I guess maybe with not closing connections but if I'm closing the hibernate session each time shouldn't that close the underlying DB connection?

Thanks for any help!
Mike


Top
 Profile  
 
 Post subject: Might have figured it out...
PostPosted: Tue Dec 14, 2004 12:56 pm 
Newbie

Joined: Mon Nov 08, 2004 6:03 pm
Posts: 8
Ok, feel alittle stupid but I think the problem was the JUnit task within my ANT target. It looks like that task buffers all output in memory then at the end of the unit test run writes it to an xml file. As soon as I took ANT out of the picture memory was flat and didn't come close to the 64 meg limit.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.