Weblogic – Tuning Java Virtual Machines (JVMs)


Tuning Java Virtual Machines (JVMs)

The Java virtual machine (JVM) is a virtual “execution engine” instance that executes the bytecodes in Java class files on a microprocessor. How you tune your JVM affects the performance of WebLogic Server and your applications.

Using Verbose Garbage Collection to Determine Heap Size

The HotSpot VM’s verbose garbage collection option (verbosegc) enables you to measure exactly how much time and resources are put into garbage collection. To determine the most effective heap size, turn on verbose garbage collection and redirect the output to a log file for diagnostic purposes.

The following steps outline this procedure:

  1. Monitor the performance of WebLogic Server under maximum load while running your application.
  1. 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.

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.

For example, on Windows and Solaris, enter the following:

% java -ms32m -mx200m -verbosegc -classpath $CLASSPATH
-Dweblogic.Name=%SERVER_NAME% -Dbea.home="C:\bea"
-Dweblogic.management.username=%WLS_USER%
-Dweblogic.management.password=%WLS_PW%
-Dweblogic.management.server=%ADMIN_URL%
-Dweblogic.ProductionModeEnabled=%STARTMODE%
-Djava.security.policy="%WL_HOME%\server\lib\weblogic.policy" weblogic.Server
>> logfile.txt 2>&1

where the logfile.txt 2>&1 command redirects both the standard error and standard output to a log file.

3. 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.

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.

  1. If you are using 1.4 Java HotSpot JVM, set the New generation heap sizes.

See Specifying Heap Size Values and Table 3-2.

Note: For information about setting the appropriate heap sizes for the BEA WebLogic JRockit JVM, see Tuning WebLogic JRockit JVM.

  1. Make sure that the heap size is not larger than the available free RAM on your system.

Use as large a heap size as possible without causing your system to “swap” pages to disk. The amount of free RAM on your system depends on your hardware configuration and the memory requirements of running processes on your machine. See your system administrator for help in determining the amount of free RAM on your system.

  1. If you find that your system is spending too much time collecting garbage (your allocated “virtual” memory is more than your RAM can handle), lower your heap size.

Typically, you should use 80 percent of the available RAM (not taken by the operating system or other processes) for your JVM.

  1. If you find that you have a large amount of available free RAM remaining, run more instances of WebLogic Server on your machine.

Remember, the goal of tuning your heap size is to minimize the time that your JVM spends doing garbage collection while maximizing the number of clients that WebLogic Server can handle at a given time.

Specifying Heap Size Values

You must specify Java heap size values each time you start an instance of WebLogic Server. This can be done either from the java command line or by modifying the default values in the sample startup scripts that are provided with the WebLogic distribution for starting WebLogic Server, as explained in Using WebLogic Startup Scripts to Set Heap Size.

For example, when you start a WebLogic Server instance from a java command line, you could specify the HotSpot VM heap size values as follows:

$ 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. The example above allocates 128 megabytes of memory to the New generation and maximum New generation heap sizes, and 512 megabytes of memory to the minimum and maximum heap sizes for the WebLogic Server instance running in the JVM. For more information on the heap size options, see Java Heap Size Options.

Using WebLogic Startup Scripts to Set Heap Size

Sample startup scripts are provided with the WebLogic Server distribution for starting the server and for setting the environment to build and run the server:

  • startWLS.cmd and setEnv.cmd (Windows).
  • startWLS.sh and setEnv.sh (UNIX and Windows. On Windows, these scripts support the MKS and Cygnus BASH UNIX shell emulators.)

If you used the Configuration Wizard to create your domain, the WebLogic startup scripts are located in the domain-name directory where you specified your domain. By default, this directory is BEA_HOME\user_projects\domain\domain-name, where BEA_HOME is the directory that contains the product installation, and domain-name is the name of the domain directory defined by the selected configuration template. For more information about creating domains using the Configuration Wizard, see “Creating Domains Using the Configuration Wizard“.

The WebLogic startup scripts set environment variables, such as the default memory arguments passed to Java (that is, heap size) and the location of the JDK, and then start the JVM with WebLogic Server arguments. Be aware that the WebLogic Server startup scripts specify default heap size parameters; therefore, you need to modify them to fit your environment and applications. For instructions on how to modifying the startup scripts to set the Java heap size options, see “Specifying Java Options for a WebLogic Server Instance“.

Java Heap Size Options

You achieve best performance by individually tuning each application. However, configuring the Java HotSpot VM heap size options listed in Table 3-2 when starting WebLogic Server increases performance for most applications.

These options may differ depending on your architecture and operating system. See your vendor’s documentation for platform-specific JVM tuning options.

Table 3-2 Java Heap Size Options 

Task

Option Recommended Value

Setting the New generation heap size

-XX:NewSize

Set this value to a multiple of 1024 that is greater than 1MB. As a general rule, set -XX:NewSize to be one-fourth the size of the maximum heap size. Increase the value of this option for larger numbers of short-lived objects.

Be sure to increase the New generation as you increase the number of processors. Memory allocation can be parallel, but garbage collection is not parallel.

Setting the maximum New generation heap size

-XX:MaxNewSize

Set this value to a multiple of 1024 that is greater than 1MB.

Setting New heap size ratios

-XX:SurvivorRatio

The New generation area is divided into three sub-areas:

Eden, and two survivor spaces that are equal in size.

Configure the ratio of the Eden/survivor space size. Try setting this value to 8, and then monitor your garbage collection.

Setting minimum heap size

-Xms

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) to minimize garbage collections.

Setting maximum heap size

-Xmx

Set the maximum size of the memory allocation pool. Set this value to a multiple of 1024 that is greater than 1MB.


Automatically Logging Low Memory Conditions

WebLogic Server enables you to automatically log low memory conditions observed by the server. WebLogic Server detects low memory by sampling the available free memory a set number of times during a time interval. At the end of each interval, an average of the free memory is recorded and compared to the average obtained at the next interval. If the average drops by a user-configured amount after any sample interval, the server logs a low memory warning message in the log file and sets the server health state to “warning.”

If the average free memory ever drops below 5 percent of the initial free memory recorded immediately after you start the server, WebLogic Server logs a message to the log file.

You configure each aspect of the low memory detection process using the Administration Console:

  1. Start the Administration Server if it is not already running.
  1. Access the Administration Console for the domain.
  1. Expand the Servers node in the navigation tree to display the servers configured in your domain.
  1. Click the name of the server instance that you want to configure. Note that you configure low memory detection on a per-server basis.
  1. Select the Configuration —> Tuning tab in the right pane.
  1. On the Advanced Options bar, click Show to display additional attributes.
  1. Modify the following Memory Option attributes as necessary to tune low memory detection for the selected server instance:
    • Low Memory GCThreshold: Enter a percentage value (0-99 percent) to represent the threshold after which WebLogic Server logs a low memory warning and changes the health state to “warning.” By default, Memory GCThreshold is set to 5 percent. This means that by default the server logs a low memory warning after the average free memory reaches 5 percent of the initial free memory measured at the server’s boot time.
    • Low Memory Granularity Level: Enter a percentage value (1-99 percent) to use for logging low memory conditions and changing the server health state to “warning.” By default this value is set to 5 percent. This means that if the average free memory drops by 5 percent or more over two measured intervals, the server logs a low memory warning in the log file and changes the server health state to “warning.”
    • Low Memory Sample Size: Enter the number of times the server samples free memory during a fixed time period. By default, the server samples free memory 10 times each interval to acquire the average free memory. Using a higher sample size can increase the accuracy of the reading.
    • Low Memory Time Interval: Enter the time, in seconds, that define the interval over which the server determines average free memory values. By default WebLogic Server obtains an average free memory value every 3600 seconds.
  1. Click Apply to apply your changes.
  1. Reboot the server to use the new low memory detection attributes.

 


Manually Requesting Garbage Collection

Make sure that full garbage collection is necessary before manually selecting it on a server. When you perform garbage collection, the JVM often examines every living object in the heap.

To use the Administration Console to request garbage collection on a specific server instance:

  1. On the Administration Console, expand the server instance node for the server whose memory usage you want to view. A dialog box in the right pane shows the tabs associated with this instance.
  1. Select the Monitoring —> Performance tab.
  1. Check the Memory Usage graph for high usage. Note that the Memory Usage graph displays information only for a server that is currently running.
  1. Click the Force garbage collection button to request garbage collection. The Force garbage collection button calls the JVM’s System.gc() method to perform garbage collection. Note, however, that the JVM implementation itself decides whether or not the request actually triggers garbage collection.

 


Setting Java HotSpot VM Options

You can use standard java command-line options to improve the performance of your JVM. How you use these options depends on how your application is coded. Although command-line options are consistent across platforms, some platforms may have different defaults.

Test both your client and server JVMs to see which options perform better for your particular application. The Sun Microsystems Java HotSpot VM Options document provides information on the command-line options and environment variables that can affect the performance characteristics of the Java HotSpot Virtual Machine.

For a brief discussion of additional “non-standard” VM options that can also affect performance, see Non-Standard HotSpot VM Options for Windows, Solaris, and Linux.

Note: For information about using the WebLogic JRockit JVM command-line options to improve performance, see Tuning WebLogic JRockit JVM.

Standard HotSpot VM Options for Windows, Solaris, and Linux

You can use standard java options to improve performance on Windows, Solaris, and Linux platforms. These options are supported on the current Java the run-time environment and will also be supported in future releases of HotSpot. When specifying one of the standard options listed Table 3-3 through the java command, WebLogic Server invokes a particular version of the JVM.

Table 3-3 Standard Java HotSpot VM Options

Option

Platform Description

-client

Windows

Solaris

Selects the Java HotSpot Client VM. This is the default for Windows and Solaris.

-server

Windows

Solaris

Linux

Selects the Java HotSpot Server VM.

-hotspot

Linux

Selects the Java HotSpot Client VM. This is the default for Linux.

For additional examples of the standard HotSpot VM options, see:

Sun Microsystems’ Java Virtual Machine document provides a detailed discussion of the Client and Server implementations of the Java virtual machine for J2SE 1.4.

Tuning WebLogic Server

The following sections describe how to tune WebLogic Server to match your application needs.

Setting Java Parameters for Starting WebLogic Server

Java parameters must be specified whenever you start WebLogic Server. For simple invocations, this can be done from the command line with the weblogic.Server command. However, because the arguments needed to start WebLogic Server from the command line can be lengthy and prone to error, BEA recommends that you incorporate the command into a script. To simply this process, you can modify the default values in the sample scripts that are provided with the WebLogic distribution to start WebLogic Server, as described in “Specifying Java Options for a WebLogic Server Instance“.

If you used the Configuration Wizard to create your domain, the WebLogic startup scripts are located in the domain-name directory where you specified your domain. By default, this directory is BEA_HOME\user_projects\domain\domain-name, where BEA_HOME is the directory that contains the product installation, and domain-name is the name of the domain directory defined by the selected configuration template. For more information about creating domains using the Configuration Wizard, see “Creating Domains Using the Configuration Wizard“.

You need to modify some default Java values in these scripts to fit your environment and applications. The important performance tuning parameters in these files are the JAVA_HOME parameter and the Java heap size parameters:

  • Change the value of the variable JAVA_HOME to the location of your JDK. For example:

set JAVA_HOME=C:\bea\jdk141_03

  • For higher performance throughput, set the minimum java heap size equal to the maximum heap size. For example:

"%JAVA_HOME%\bin\java" -hotspot -Xms512m -Xmx512m -classpath %CLASSPATH% -

See Specifying Heap Size Values for details about setting heap size options.


Leave a Reply

Your email address will not be published. Required fields are marked *