Tuning Java Virtual machines Weblogic Server
Garbage collection is the first and foremost thing while tuning JVM. Garbage collection is the VM process of de-allocating unused java objects in the java heap.
For tuning Garbage collection we will focus on:
–> JVM heap size
–> Generational garbage collection
JVM Heap Size
- The Java heap is a repository for live objects, dead objects and free memory.
- The JVM heap size determines how often and how long the VM spends collecting garbage i.e. dead objects.
- Larger the heap size full garbage collection is slower and frequency is less. Smaller the heap size full garbage collection is faster and frequency is more.
Goal for tuning heap size:
- To minimize the time spent doing garbage collection while maximizing number of clients to be handled at a time.
- To ensure maximum performance during benchmarking the heap size values should be set in such a way that garbage collection does not occur during the entire run of the benchmark.
Determine Optimal Heap Size:
- Use the
-verbosegc
option to turn on verbose garbage collection output for your JVM and redirect both the standard error and standard output to a log file. - Make sure that the heap size is not larger than the available free RAM on the system.
Analyze the following data points:
- How often is garbage collection taking place?
- In the weblogic.log file, compare the time stamps around the garbage collection.
- How long is garbage collection taking?
Full garbage collection should not take longer than 3 to 5 seconds. Lower heap if major GC time is greater.
- What is your average memory footprint?
In other words, what does the heap settle back down to after each full garbage collection? If the heap always settles to 85 percent free, you might set the heap size smaller.
You might see the following Java error if you are running out of heap space
java.lang.OutOfMemoryError <>
java.lang.OutOfMemoryError <>
Exception in thread "main"
Turning on Verbose Garbage Collection:
- Turn on verbose garbage collection output for Java VM when WebLogic Server is started, as shown in the example.
- Redirect both the standard error and standard output to a log file.
- This places thread dump information in the proper context with WebLogic Server informational and error messages, and provides a more useful log for diagnostic purposes.
- Example
- java -ms64m -mx64m -verbosegc -classpath $CLASSPATH
-Dweblogic.domain =mydomain -Dweblogic.Name=clusterServer1
-Djava.security.policy==/bea/weblogic91/server/lib/weblogic.policy
-Dweblogic.management.server =192.168.0.101:7001
-Dweblogic.management.username =system
-Dweblogic.management.password =systemPassword weblogic.Server
>> logfile.txt
Specifying Heap Size Values:
- Java heap size values are specified when starting the WebLogic Administration Server from the Java command line.
- Example:
- java … -XX:NewSize =128m -XX:MaxNewSize=128m -XX:SurvivorRatio=8
-Xms512m -Xmx512m
- The default size for these values is measured in bytes. Append the letter ‘k’ or ‘K’ to the value to indicate kilobytes, ‘m’ or ‘M’ to indicate megabytes, and ‘g’ or ‘G’ to indicate gigabytes.
Java Heap Size Options
- -XX:NewSize:
- This option is used to set the New generation Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.
- As a general rule, set this option to be one-fourth the size of the maximum heap size. Increase the value of this option for larger numbers of short-lived objects.
- Make sure that the New generation is increased as the number of processors are increased. Memory allocation can be parallel, but garbage collection is not parallel.
- -XX:MaxNewSize
- This option is used to set the maximum New generation Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.
- -XX:SurvivorRatio
- This option is used to configure the ratio of the Eden/survivor space size. Try setting this value to 8 and then monitor your garbage collection.
- -Xms
- This option is used to set the minimum size of the memory allocation pool. Set this value to a multiple of 1024 that is greater than 1MB. As a general rule, set minimum heap size (-Xms) equal to the maximum heap size (-Xmx).
- -Xmx
- This option is used to set the maximum Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.
Control Permanent Generation area size explicitly:
- Set initial heap size = max heap size
- Permanent Generation area defaults:
- 4MB min, 32MB max
- To increase, use:
- -XX:PermSize=32m .XX:MaxPermSize=64m
- Use less than ~80% available RAM on the machine
- 32-bit limit is 2GB; 64-bit is 16GB