-->
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.  [ 8 posts ] 
Author Message
 Post subject: Share listener between pre-insert and pre-update
PostPosted: Mon Sep 03, 2007 9:14 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
ValidatePreInsertEventListener and ValidatePreUpdateEventListener are empty classes. They both inherits from ValidateEventListener.

In my case with 400 classes in my domain, each listener take around 15 Mo of memory.

Instead of creating two listeners, one for update and one for insert, I can create only one and share it betwwen post-insert and post-update.

Can somebody tell me if this is correct or not. Is there something I miss that prevent me from sharing my listener ?

I am using spring to configure my session factory so here is my configuration :
Code:
  <bean id="validateListener" class="org.hibernate.validator.event.ValidateEventListener" />

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="eventListeners">
      <map>
        <entry key="pre-update" value-ref="validateListener"/>
        <entry key="pre-insert" value-ref="validateListener"/>
      </map>
    </property>
    <!-- fichiers de mapping d'hibernate -->
    <property name="mappingResources">
      <list>
        <value>...</value>
      </list>
    </property>

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 8:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you will be fine. I think I do that for when the validator is bootstrapped from annotations

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 6:12 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Another point about validators.
In my case on a domain model of about 400 entities, the listener take between 15 and 30 Mo of memory.
This seems a little bit to much for me. I don't dig into the code to see if all the cached data is really necessary but by inspecting a memory dump it seems that it caches all my domain model methods, even methods that do not have annotations.

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 8:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
scesbron wrote:
it caches all my domain model methods, even methods that do not have annotations.


Are you sure about that? AFAIR, we only keep the annotated methods.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 2:56 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
No, I am not sure of that. It seems to be the case when I watch my memory dump but it does not seems to be the case when I step into the code.
I may do more memory analysis to see if I can reduce the memory footprint

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 3:34 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
In fact I have juste my annotated methods in my ValidatableElement.

But, each classvalidator holds a JavaXFactory instance which holds a map of methods.

In my case all my validators represents 20 Mo of memory and the JavaXFactory instances represents 16 Mo of this 20 Mo.

There is a reset method on the JavaXFactory class. If you put this method on the ReflectionManager, you could call it at the end of the initialization process

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 4:24 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
It works

By adding a reset method at the end of the ClassValidator initValidator method, my Listener now takes only 4,6 Mo of memory.

Is there any side effect ? Do you think this can be added in the next release version ? Do you want me to create a JIRA on this ?

Another weird thing, for my 481 domain classes there is 481 instances of DefaultMessageInterpolatorAggerator (typo ?) that holds 2231 instances of DefaultMessageInterpolator. All this takes 34% of the listener footprint. May the default interpolator can be shared by all instances.

HTH

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 12:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Open a JIRA issue for the JavaXFactory, I need to think about it. AFAIR there was a reason for me to keep it around, but reset might be a decent solution.

For the second problem, I precompute things, that's the reason why you have so many instances, it's a trade-off between memory and speed. it worths exploring alternate solutions too.

_________________
Emmanuel


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