views:

62

answers:

2

Hi guys,

I'm working on a program that parses data from a file and stores it into a HSQLDB database. As the parser encounters data it creates entities which are mapped to the database using JPA/Hibernate. My problem is that while the parsing is being performed the application uses more and more memory. I have successfully used cached tables so that once the parsing is complete the memory is all released, but during the parsing it uses way more than what I am comfortable with.

I have tried to fix this by calling flush and clear methods on my EntityManager, but this had no effect. I've also tried to make sure that Entity with references to all other entities is kept in memory.

The largest objects in memory seems to be hsqldb.Sessions. Could it be that HSQlDb caches loads of data for each transaction? It does seem excessive to need 1GB of RAM to only end up with a DB that is 120MB on disk does it not?

Please advise on what I could try next.

:)

+2  A: 

Do a heap dump and use Eclipse MAT to analyse where the memory is used. With JPA the results are often surprising and without looking at the actual memory usage you're often stabbing in the dark.

leonm
good sueggestion as I have no idea why this is happening. I just thought clearing the EntityManager would release all the memory.
willcodejavaforfood
This revealed that it is HSQLDB that is holding on to the memory for some reason. Does it mean it is a database configuration problem, or a application design problem, or a transactional design problem? :)
willcodejavaforfood
Which classes use the most memory?
Thomas Mueller
+1  A: 

After two days of faffing around with HSQLDB I followed the advice of two friends and changed database to H2. The memory footprint during a transaction is roughly a third now and it is also 20% faster.

Really surprised me

willcodejavaforfood
Looks like you've been using HSQLDB 1.8.x. The transaction memory use of HSQLDB 2.0.x with CACHED tables is much lower.
fredt
@fredt - Thanks for that. It's too late now to go back to HSQLDB, but for my next project I'll give it another go :)
willcodejavaforfood