Reputation: 164
I have project with large database. To parse it I use java with G1 garbage collector. When program runs for a long period of time java begins to consume a lot of memory. But when I check java heap the size is much smaller. For example:
Question: what is taking the rest of my RAM? Is this overhead of G1?
Edit: Here is stats
java procces: allocated ~50gb, consumed ~20gb
jmap info: heap size ~4gb
Upvotes: 3
Views: 2935
Reputation: 164
I understood the problem. As @Holger mentioned the ram is allocated to java process but not fully filled with heap. But the reason why G1 allocates so many ram:
G1 suffers if it needs to allocate a lot of humongous regions. They will be created each time an object size > 50% of the region size. They will waste space as nothing else will be created in the region. Thus if its size is 51%, you will waste 49% of the region. Worse, if a region is 2MB and your object is 2.1MB, it will waste 1.9MB in the second region. If you allocate large objects, adjust your XX:G1HeapRegionSize.
Upvotes: 4
Reputation: 155
The RAM consumption will be because of the huge database size and the size of the result set.
Try the below: Optimizing Garbage Collection:
be wary of String Concatenation operator (+) use concat() instead
if using spring, try setFetchSize(number of rows to be fetched at a time) using setFetchSize will, however, increase your time for execution, but it is memory efficient
remove all unnecessary statement
Use Asynchronous Execution
Upvotes: 0