persistence@glassfish.java.net

Memory question

From: Dru Devore <ddevore_at_duckhouse.us>
Date: Wed, 14 Jan 2009 09:47:32 -0700

I have been fighting with an application that is taking a lot of memory
and I need to know what I can do about it.

Setup:
- Glassfish v2ur2 (heap size of 256m for testing)
- Toplink (have also tried Hibernate but the same problem exists)
- I am using pure JPA persisting the POJOs

Database Structure (short version):

Table1 ---- Table2 ---- Table3 ---- Table4
       1 n 1 n 1 n

I have narrowed down the memory consumption to the persisting of the
objects. I can reproduce it in a test where I create a structure
approximately like this:

Table1 1 record
Table2 1 record
Table3 12 records
Table4 10000 records (approximately 1000 records per Table3 record)

If I simply create the structure the memory is solid (as reported
through jconsole) hovering around 50% tenure/old gen space. I can run
the test over and over and it without restarting without the memory
hardly moving.

When I persist the the structure with persist(table1) the tenure/old gen
space hits around 90% utilization and does not shrink. I can run the
test about 3-4 times before it basically brings the server to its knees.
I can request a GC through the jconsole and it will recover a little but
always shows more tenure/old gen space consumed after this test. This
becomes a major problem because after the tenure/old gen space is
consumed the eden and survivor space becomes totally consumed also and
brings the server to its knees. In long running tests where the size of
the table 4 records are much less, the memory is all consumed after
about 5 days on a server with a 512M heap which forces us to restart the
server.

I am thinking that changing the way I persist the objects will help with
the problem. Something like doing a direct update on the table instead
of using the POJOs. I also thought that if I would persist the Table1,
2, and 3 before creating the Table4 records and persisting Table4
separately may help.

My questions are:

How can I resolve this problem?

Would my thought of doing direct updates work?

Is there any configuration setting that would help?

Has anyone else seen this kind of problem?