-->
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: Hibernate with Spring - CGLIB classes memory retention issue
PostPosted: Fri Nov 17, 2006 4:41 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
I am using Hibernate with Spring. There has been some memory related issues. I tracked it down with a profiler that showed that even after garbage collection, the OR library classes (CGLIB) loaded by Hibernate are still held in memory. As the usage increases, the number of instances that can't be reclaimed is also increasing drastically. In just 20-40 clicks, the system runs out of memory. Btw, the actual persistable/detached objects are cleaned up fine during GC.

I am not sure where to start to debug this. Please help me narrow down the choices I have to get to the bottom of the issue. Thanks a lot!

I am showing one OR class ProductCategory.hbm.xml here.

======================
Hibernate Version: 3.1
======================


<hibernate-mapping>
<class name="com.ti.eps.dealer.product.orm.ProductCategory" table="PRODUCT_CATEGORY" schema="DEALER">
<id name="productCategoryId" type="big_decimal">
<column name="PRODUCT_CATEGORY_ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="pageSetup" class="com.ti.eps.dealer.pagesetup.orm.PageSetup" fetch="select" lazy="false">
<column name="PAGE_SETUP_ID" precision="22" scale="0" />
</many-to-one>
<property name="productCategoryName" type="string">
<column name="PRODUCT_CATEGORY_NAME" length="512" not-null="true" />
</property>
<property name="instructSortOrder" type="big_decimal">
<column name="INSTRUCT_SORT_ORDER" precision="22" scale="0" />
</property>
<property name="retailerSortOrder" type="big_decimal">
<column name="RETAILER_SORT_ORDER" precision="22" scale="0" />
</property>
<property name="thumbnailImagePath" type="string">
<column name="THUMBNAIL_IMAGE_PATH" length="512" not-null="true" />
</property>
<property name="productComparisonPath" type="string">
<column name="PRODUCT_COMPARISON_PATH" length="512" />
</property>
<property name="courseGuidePath" type="string">
<column name="COURSE_GUIDE_PATH" length="512" />
</property>
<set name="products" inverse="true" lazy="true">
<key>
<column name="PRODUCT_CATEGORY_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.ti.eps.dealer.product.orm.Product"/>
</set>
</class>
<query name="ProductCategory.getAllCategories">
<![CDATA[from ProductCategory where pageSetup.langId = ? and pageSetup.pageSetupCountries.countryId = ? ]]>
</query>

</hibernate-mapping>

======================
I am using Springs DAOSupport methods to access the OR layer.

Object[] queryValues = {'EN', 'US'};

List list = getHibernateTemplate().findByNamedQuery("ProductCategory.getAllCategories"
queryValues);

======================

Here is what the profiler complained about:

com.ti.eps.dealer.product.orm ProductCategory$$EnhancerByCGLIB$$63a97b50$$FastClassByCGLIB$$fca2633a
com.ti.eps.dealer.product.orm ProductCategory$$FastClassByCGLIB$$b9a9f207

======================

Spring version: 2.0 RC3
======================


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 3:24 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Are your sessions long-lived ? Maybe you don't flush/clear often enough ?
Do you respect the short-lived session best practice ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 8:18 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
I am not controlling the sesssions. The following method that I am using to access OR layer is facilitated by Spring. From what I read about
Springs DAO support, it closes sessions after every transaction.

===============
List list = getHibernateTemplate().findByNamedQuery("ProductCategory.getAllCategories"
queryValues);
===============

It lookslike that the Object retained in the memory has been loaded by CGLIB.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 3:11 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
trmm333 wrote:
I am not controlling the sesssions. The following method that I am using to access OR layer is facilitated by Spring. From what I read about
Springs DAO support, it closes sessions after every transaction.


You should check your configuration about this. Verify that Spring gives you a new session each time (displaying its address, e.g.) and verify it begins a transaction and commit it each time. I had had some problems with this, mainly due to my poor spring knowlegde.

From your user point of view, what is a transaction ? Is this a dao method call, or do you have an upper layer which can call more than one dao method so to coordinate everything ?

I suppose you're using such class as TransactionProxyFactoryBean to demarcate your tx automatically ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 11:53 am 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
For me, a transaction is a DAO method call. I am using automatic TX demarcation.

Sure, I will do some more debug of the session/tx demarcation information from Spring. Thank you for the insight!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 4:07 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Looks like you create session factory per request, session factory must be a singleton.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 10:15 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
Thank you all for your insights!

Upon one day of profiling this is what I found

1. Hibernate is leaving lot of proxy and CGLIB enhancer instances for each persistable objects open. GC is not able to reclaim them. I guess that is okay for our application as the hibernate OR mapping is complex and there are just too many associations. I think I have less control over here.

2. Also, there are many persistable objects that are instantiated just too many times. I am working on enabling second level caching as most of the data are read-only.

3. I now realize that spring+hibernate has significant overhead in terms of memory consumption.

Finally, a question. I don't understand this TransactionProxyFactoryBean. Why do I need it anyway? I currently don't specify it and the app seems to be working just fine. Our app only reads from the db, never writes.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 10:16 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
Yes, I have singleton session factory.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 1:11 pm 
Beginner
Beginner

Joined: Thu Oct 12, 2006 6:19 pm
Posts: 34
Location: Guatemala
Hi to all, baliukas, if you read it... We all have singleton pattern applied to SessionFactory, but I'd like to have more than one Session object and persistent objects per each Session is it possible?

Thanks in advance

_________________
God is Love


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.