• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

Java JVM tuning paramters

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
jbaird123
Asked:
jbaird123
  • 4
  • 3
2 Solutions
 
ChristoferDutzCommented:
-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
 
ChristoferDutzCommented:
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
 
jbaird123Author Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ChristoferDutzCommented:
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
 
jbaird123Author Commented:
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
 
ChristoferDutzCommented:
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
 
jbaird123Author Commented:
It seems to be running fine!  Thank you!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now