Solved

Java JVM tuning paramters

Posted on 2010-09-24
7
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 33754923
-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
ID: 33754958
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
ID: 33755842
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 500 total points
ID: 33760147
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
ID: 33760388
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
ID: 33760486
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
ID: 33778649
It seems to be running fine!  Thank you!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

690 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