Solved

Java JVM tuning paramters

Posted on 2010-09-24
7
413 Views
Last Modified: 2012-05-10
I have a Java application that utilizes a lot of memory and consequently runs very slowly.  I found that there is a .ini file that I can use to configure the memory usage of the JVM but I don't know what these parameters mean or how to set them.  Can someone explain their meaning and what they do?  The application has both a 32-bit and a 64-bit version.

Here is the default config - which runs very slowly
-vmargs
-Xms40m
-Xmx500m
-XX:MaxPermSize=128m

I changed it to this and noticed an improvement, but I don't know if I did the right thing or not:
-vmargs
-Xms1024m
-Xmx1500m
-XX:MaxPermSize=512m

Can someone provide advice on how this should be configured?  I'm running WIndows 7 with 4GB of RAM.
0
Comment
Question by:jbaird123
  • 4
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
Comment Utility
-Xmx is the maximum heap assigned to the VM
-Xms is the minimum heap assigned to the VM
-XX:MaxPermSize: sets the amount of memory allowed to load class definitions and static variables

Simply increasing the memory is not allways a good thing. And when having a look at your configuration on a 32 Bit system you will get problems with your increased memory settings.
You set Xms to 1024m ... as soon as this is full and the maximum of 1500 is not reached, the VM tries to allocate a block of memory that is greater than 1024 (lets say 1100m) in order to copy everything from the old block to the new block. Unfortunately the VM would have more than 2GB allocated which is not possible on classic 32Bit Systems. So for this ... my tip ... setting Xmx and Xms to the same size is a good thing.

Now another tip to the larger amount of memory:
More memory means more cleaning up. If your application needs 250MB of ram but creates a lot of objects that are disposed relatively soon then the VM has to clean up all the rest which might make the System hang during Garbage collection runs.
0
 
LVL 20

Expert Comment

by:ChristoferDutz
Comment Utility
Perhaps you should have a look at this ...
http://en.wikipedia.org/wiki/Java_performance#Virtual_machine_optimization_techniques

Also, are you sure the performance is related to memory only? In one of my projects I had the problem, that I did a lot of log4j logging. Under heavy load the access to the FileSystem was blocking my entire system. If you are using Windows Vista or Greater (Don't know which version of Windows Server has it) try the resource Monitor to have a look at your File IO. If this is high, you should have a look at what's causing the High IO and eventually solve the problem.
0
 

Author Comment

by:jbaird123
Comment Utility
Hi.  I checked my File IO, and it does not seem to be unusually high.  CPU Usage always spikes to 100% when I'm having my issues.

I'm on a 64-bit machine, so I can go higher than 1024 if needed.  

It sounds from what you're saying above, I should normally try to set my Xms and Xmx parameters as low as possible in order to minimize the garbage collection load.  Is that correct?

Additionally, I have noticed that the biggest performance gain I have achieved was the result of changing this:  XX:MaxPermSize from 128 to 512.  What does that tell me?

Thanks!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 500 total points
Comment Utility
No ... you shouldn't let the VM live with the minimum. That too is not very efficient, because then the Garbage collection will not have to do very much every time it starts it's work, but it will have to do it very often, which tool will slow down everything. In my Projects I usually have a look at how much memory the application needs (Have a look at the used memory after the garbage collection is finished and then add 1/3 of that Memory as space for young-generation objects (Objects that are created and displosed relatively quick).

To your observation about the MaxPermSize ... if you have an application with JSPs for example, then this space is filled up with the class-definition of the compiled JSP pages. Unfortunately the VM doesn't do Garbage collections in the PermSpace ... if it runs out though, it does start a garbage collection.

You could give the following parameters a try:

-XX:+CMSPermGenSweepingEnabled
-XX:+CMSClassUnloadingEnabled

The first turnes on the garbage collection in the perm gen space and it turns on the ability to unload classes that are no longer needed (As it happens with JSPs quite a lot)
0
 

Author Comment

by:jbaird123
Comment Utility
Thanks again.  Are you saying that I should add those parameters in addition to what I already have like this?

-vmargs
-Xms1024m
-Xmx1500m
-XX:MaxPermSize=512m
-XX:+CMSPermGenSweepingEnabled
-XX:+CMSClassUnloadingEnabled

Or should it replace what I have like this:

-vmargs
-Xms1024m
-Xmx1500m
-XX:+CMSPermGenSweepingEnabled

And then try it this way:

-vmargs
-Xms1024m
-Xmx1500m
-XX:+CMSClassUnloadingEnabled

Thanks!
0
 
LVL 20

Expert Comment

by:ChristoferDutz
Comment Utility
Nono ... add them to your configuration as they simply control additional aspects of the VM. I'd try the first option containing all 6 params even if the perm size looks pretty high ... I'd set that to 256m
0
 

Author Closing Comment

by:jbaird123
Comment Utility
It seems to be running fine!  Thank you!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now