Solved

Java JVM tuning paramters

Posted on 2010-09-24
7
420 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 53
Java exception bubble up 2 18
JavaFX TableView not displaying correctly 3 17
jsp login check 12 31
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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 …

770 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