• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance Issue in Hibernate?

 
akash yadav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am facing very strange behavior in hibernate which is described below

I have written a function which fetch one city of a particular state the hbm mapping of files are given below:

city.hbm

State.hbm

From my action class I am calling the method

IMPL class Method:



The whole application invokes when I upload some users into database, before uploading users I also checked the city related to that user for that I invoke above method. The method works fine with few records but it takes lot of time when we upload say 5000 users.
I also put debug statements and found that to execute the
city = (City) criteria.uniqueResult();
it takes 4ms for first record then it keeps on increasing and reached to 190 ms for 3500 users.

I had also tried to put second level caching, as a result the SQL query is not executing every time but it still takes same time .

But if I comment the line city = (City) criteria.uniqueResult(); then a unique behavior can be seen like it differs from 5ms to 15 ms .
If you carefully noticed the code I have not done any complex join or something and it also works fine for few records but why the time keeps on increasing continuously for only this method is very strange for me.

Please provide some solution. Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can consider the Heap space. So for every object you load, it takes up heap space. If you load more and more, garbage collection comes into play as well as the sizing of the heap space.

You can try to increase it with -Xmx and -Xms to see if that helps.

Also do you need to load all those users, or can you do some batch, and pagination logic to not load 5000 objects at once into the Session.

Let us know how that goes.

Mark
 
akash yadav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:Well, you can consider the Heap space. So for every object you load, it takes up heap space. If you load more and more, garbage collection comes into play as well as the sizing of the heap space.

You can try to increase it with -Xmx and -Xms to see if that helps.

Also do you need to load all those users, or can you do some batch, and pagination logic to not load 5000 objects at once into the Session.

Let us know how that goes.

Mark


Thanks for your response Mark. I got your point but I want to know there are are several methods in application which are showing consistent behavior only this method more precisely only that particular line of code is creating problem whereas I have now save the multiple database hits also by implementing second level cache. Also I didn't understood about paginataion logic I am using aop:config in my application where the transaction commits after the execution of all methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic