Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postInstantiate buildSessionFactory slow/memory huge database

Having an ERP database with more than 520 tables, the postInstanciate of EntityPersister is very slow and its consuming more than 512M which is to much for only one session Factory, the application become very slow.

like image 813
Nassim MOUALEK Avatar asked May 26 '14 09:05

Nassim MOUALEK


1 Answers

I can't post all changes, but here the ideas :

1_ Hibernate creates many Entiy Loaders for all entities and collections (many type of loader for each entity and each collection), this operation should be done on demande, entity or collection loader should be created when its needed, not during the build of session factory, even if you have 500 entities it doesn't mean that the user will load data from each entity.

    private Map LoaderMap = new LoaderMap();//instead Hashmap  
    class LoaderMap extends HashMap{
        @Override
        public Object get(Object key) {         
            Object obj = super.get(key);
        ….
        }
    }
    

2_ DirectPropertyAccessor is calling getDeclaredField twice once for the buildGetter Method and the second for buildSetter, using a cache is a good optimization

Response to Ulrich Scholz: I add a jar containing all fixed Classes to the project, in my case its Webapp application deployed on Tomcat, all you need is to fix the loading order of the Jars using :

<Context>
<Resources>
      <PreResources className="org.apache.catalina.webresources.FileResourceSet"
                base="${catalina.base}/webapps/AGIWERP/WEB-INF/lib/AAACLZ-1.0.jar"
                webAppMount="/WEB-INF/lib/AAACLZ-1.0.jar" />
</Resources>

</Context>

This mean your classes should be loaded before the original ones

like image 153
Nassim MOUALEK Avatar answered Oct 13 '22 23:10

Nassim MOUALEK