java 7 garbage collectors

hi experts

In our project we are currently using something like this in our shell script to invoke our java

java -cp $CLASSPATH -DjobParam=customerAnalyzer -XX:+UseParallelOldGC -server -Xms512m -Xmx2048m com.cust.gatr.CustomerAnalyzer

we often encounter out of memory error. It is not because we have memory leaks but because we have to store one million objects
in the JVM.

How can we avoid the out of memory error?What options do i have ?

2.Also what is the difference between -XX:+UseParallelOldGC and -XX:+UseConcMarkSweepGC
which is a better option

java -cp $CLASSPATH -DjobParam=customerAnalyzer -XX:+UseParallelOldGC -server -Xms512m -Xmx2048m com.cust.gatr.CustomerAnalyzer
java  -cp $CLASSPATH -DjobParam=customerAnalyzer -XX:+UseConcMarkSweepGC -server -Xms512m -Xmx2048m com.cust.gatr.CustomerAnalyzer

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1) Increase this value: -Xmx2048m to give Java more heap memory, so you can create more objects.

2) The choice of garbage collector is mostly about improving response time.
UseParallelOldGC is the standard collector.
UseConcMarkSweepGC is a new one that attempts to reduce the pauses when collecting garbage on a machine that is using a lot of RAM.

Whichever you choose shouldn't have much impact on out of memory errors.  It's more about looking at response times (UseParallelOldGC may achieve better overall throughput - you get a lot of work done but occasionally stall, while UseConcMarkSweepGC may reduce latency - you get a bit less work done, but there are fewer stalls).

Generally the advice is to run with both and measure the performance of your app to see which you prefer.

royjaydAuthor Commented:
>> Increase this value: -Xmx2048m
yeah that's what we wanted to do, the problem is there are 6 process running each using 2gb ram already. The total ram on the Linux box is 12gb, so basically we have exhausted the memory.
We are trying to see if we can request for more memory.
Do you see any other options ?

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Do you see any other options ?
No really apart from changing you application structure so that you DON'T have to store all 1 million objects in memory at the same time! (To help much more than that, you would need to give us some info on what those objects are and why you think you need to store them all, maybe we can suggest an alternative)
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

>> yeah that's what we wanted to do, the problem is there are 6 process running each using 2gb ram already. The total ram on the Linux box is 12gb, so basically we have exhausted the memory.

You can still increase the Java heap to over 2GB per process, since that's allocated as virtual address space, not physical address space.

Then you won't get the out of memory exceptions and your program will at least run.

If more than 2GB is actively in use on all 6 processes at the exact same time, then you will end up swapping, so things will run more slowly - but again at least they'll run.  And you may find that not all 2GB is actually being touched at once.  Perhaps you are just actively processing a fraction of the data, even though it's all "in memory".  In which case 12GB would be fine.

Slow is better than broken :)

If that's still no good, then you need to either reduce the memory usage, increase the RAM on the server or spread the processes to other boxes.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royjaydAuthor Commented:
Did you guys ever try these GC tuning settings and observe any performance benefits ?

4.2.7   Tuning Example 7: Try AggressiveOpts for low pause times and high throughput

This tuning example is builds on Example 6, and adds the AggressiveOpts option.

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=31 -XX:+AggressiveOpts 

Turns on point performance optimizations that are expected to be on by default in upcoming releases. The changes grouped by this flag are minor changes to JVM runtime compiled code and not distinct performance features (such as BiasedLocking and ParallelOldGC). This is a good flag to try the JVM engineering team's latest performance tweaks for upcoming releases. Note: this option is experimental! The specific optimizations enabled by this option can change from release to release and even build to build. You should reevaluate the effects of this option with prior to deploying a new release of Java.

Open in new window

taken from

I've not personally tried that - but I know that "JVM tuning" is a huge thing and some ops folks spend weeks adjusting all of the params and doing perf testing to see what happened.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.