This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Perfomance Issue: Persisting a large collection.

 
esteban gomez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Im using Hibernate3.2.3.ga + spring 2.0.

I have an Object Grid, which contains a collection of Points. Point has just latitude(float) and longitude(float) attrbs.
The problem is that the grid object actually contains a lot of Points, say more than 13000 points. When I tried performing a normal save using the Springs HibernateTemplate.save(Object o) it tooked more than 15 minutes to perform the save operation.

Which optimization technique should I use in order to perform this saving in less time?


Thanks.

Esteban.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The big thing is that all those objects being stored into the Session and not being Batched.

There are a few options.

1) In a for loop set the batch size to say 50. When you reach 50 do a session.flush and session.evictAll() to remove objects in the Session. This will help a little bit. Test out batch sizes to see where you get the best performance.

2) How are those points created, you could do more batch SQL code instead of creating objects and using session.saveOrUpdate()

3) If this is truly a batch update of tons of records, maybe Hibernate isn't the best choice for this. You can always go low level and getConnection() from the session and do it via JDBC.

Mark
 
esteban gomez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for the reply.

Actually I used option 1) and performance improved a lot. The code I used was the following:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice.

One question, I thought the benefit of using the HibernateTemplate in Spring was so that you didn't have to do beginTransaction(), commit() and rollback() yourself.

Ah, and you are one of those "final" type guys. ;)

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic