-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate slows down algorithms in entity classes?
PostPosted: Fri Sep 30, 2011 9:18 pm 
Newbie

Joined: Tue Oct 26, 2010 10:21 am
Posts: 4
Hello,

I have a project with just 3 Entity classes. The performance of my project is very important, because there are methods in some entity-classes which are called permanently with a rate of 300000 times per second.
The performance of the persistence mechanism(Hibernate with h2-database) is not important.

My problem:
When I just create a SessionFactory, the performance of my programm decrease about 200%. (The CPU load increases about 200%)

Can you explain me, why this happens?
Is it possible, that hibernate watches on any entity-classes for changes, and because there are 300000 changes persecond, hibernate gets notified on every change?

Here is the code, with that I create the SessionFactory:
Code:

Configuration cfg = new Configuration()
.addAnnotatedClass(logic.Oscillator.class)
.addAnnotatedClass(logic.Envelope.class)
.addAnnotatedClass(logic.Preset.class)
.setProperty("hibernate.connection.driver_class", "org.h2.Driver")
.setProperty("hibernate.connection.url", "jdbc:h2:file:" + dbPath)
.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.setProperty("hibernate.connection.username", "sa")
.setProperty("hibernate.connection.password", "")
.setProperty("hibernate.connection.pool_size", "2")
.setProperty("hibernate.hbm2ddl.auto", "update");
         

SessionFactory sessionFactory = cfg.buildSessionFactory();
   




Last edited by aleister on Sun Oct 02, 2011 9:19 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate slows down algorithms in entity classes?
PostPosted: Sun Oct 02, 2011 4:29 pm 
Newbie

Joined: Sun Sep 25, 2011 4:05 pm
Posts: 12
Quote:
The performance of my project is very important, because there are methods in some entity-classes which are called permanently with a rate of 300000 times per second.


The methods that are called frequently, do they require a database update/query too? If not, you will boost performance by using a detached instance of an entity. Meaning one retrieved from the database, but is not currently in a session (the session that got it was closed/cleared).

Quote:
My problem:
When I just create a SessionFactory, the performance of my programm decrease about 200%. (The CPU load increases about 200%)


Are you saying that your function which creates the configuration and the session factory is being called repeatedly?

Forgive me if I'm mistaken, the next paragraph of my post assumes that is what you're doing.

Your application should only create the configuration and the session factory once when the application starts. The process of initializing the configuration and session factory is very resource intensive. Keep a static reference to the result in a singleton style class. See an example here:
http://docs.jboss.org/hibernate/core/3. ... pp-helpers

Quote:
Is it possible, that hibernate watches on any entity-classes for changes


It watches changes to entities that are contained in a session, aka persistent entities. Does not watch changes to transient or detached entities. For those that are persistent in a session though, it does not make database updates/queries unless it is necessary, or until the session's flush is reached. That is generally speaking though, I think there are ways to re-configure it (i.e. session.setFlushMode(...)). So long story short, simply modifying an entity through a setter method will not cause a database update/query.

Chapter 13 will answer some of your questions:
http://docs.jboss.org/hibernate/core/3. ... tions.html

This is another article that I think might answer your questions, and can help you with performance:
http://community.jboss.org/wiki/SessionsAndTransactions


Top
 Profile  
 
 Post subject: Re: Hibernate slows down algorithms in entity classes?
PostPosted: Sun Oct 02, 2011 9:18 pm 
Newbie

Joined: Tue Oct 26, 2010 10:21 am
Posts: 4
Thanks for your reply

Quote:
The methods that are called frequently, do they require a database update/query too? If not, you will boost performance by using a detached instance of an entity. Meaning one retrieved from the database, but is not currently in a session (the session that got it was closed/cleared).

- The methods do not require database updates/queries.
- I don't opened a session, i just do the configuration and create a SessionFactory. The performance leak occures after I created the SessionFactory. When I remove the relevant entity classes from the hibernate configuration, then the performance leak don't occur.

Quote:
Are you saying that your function which creates the configuration and the session factory is being called repeatedly?

No, this function is called just one times. It is in a singleton.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.