3 Tuning Java Virtual Machines (JVMs)

The Java virtual machine (JVM) in Oracle WebLogic Server 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. Configure the JVM tuning options for WebLogic Server.

JVM Tuning Considerations

Examine some general JVM tuning considerations for WebLogic Server.

The following table presents general JVM tuning considerations for WebLogic Server.

Table 3-1 General JVM Tuning Considerations

Tuning Factor Information Reference

JVM vendor and version

Use only production JVMs on which WebLogic Server has been certified.

See Supported Configurations in What's New in Oracle WebLogic Server for links to the latest certification information on various platforms.

Tuning heap size and garbage collection

For WebLogic Server heap size tuning details, see Garbage Collection.

Choosing a GC (garbage collection) scheme

Depending on your application, there are a number of GC schemes available for managing your system memory, as described in Choosing a Garbage Collection Scheme.

Mixed client/server JVMs

Deployments using different JVM versions for the client and server are supported in WebLogic Server.

UNIX threading models

Choices you make about Solaris threading models can have a large impact on the performance of your JVM on Solaris. You can choose from multiple threading models and different methods of synchronization within the model, but this varies from JVM to JVM.

See Performance Documentation For the Java Hotspot Virtual Machine: Threading at http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html.

Changing To a Different JVM

When you create a domain, you choose the JVM that you want to run your domain and the Configuration Wizard configures the Oracle start scripts based on your choice. Modify the values for the JAVA_HOME and JAVA_VENDOR variables in the Configuration Wizard to change the JVM.

After you create a domain, if you want to use a different JVM, see Changing the JVM That Runs Servers in Administering Server Startup and Shutdown for Oracle WebLogic Server.

Garbage Collection

Garbage collection is the VM's process of freeing up unused Java objects in the Java heap.

The following sections provide information on tuning your VM's garbage collection:

VM Heap Size and Garbage Collection

The Java heap is where the objects of a Java program live. It is a repository for live objects, dead objects, and free memory. When an object can no longer be reached from any pointer in the running program, it is considered "garbage" and ready for collection. A best practice is to tune the time spent doing garbage collection to within 5% of execution time.

The JVM heap size determines how often and how long the VM spends collecting garbage. An acceptable rate for garbage collection is application-specific and should be adjusted after analyzing the actual time and frequency of garbage collections. If you set a large heap size, full garbage collection is slower, but it occurs less frequently. If you set your heap size in accordance with your memory needs, full garbage collection is faster, but occurs more frequently.

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. To ensure maximum performance during benchmarking, you might set high heap size values to ensure that garbage collection does not occur during the entire run of the benchmark.

You might see the following Java error if you are running out of heap space:

java.lang.OutOfMemoryError <<no stack trace available>>
java.lang.OutOfMemoryError <<no stack trace available>>
Exception in thread "main"

To modify heap space values, see Specifying Heap Size Values.

To configure WebLogic Server to detect automatically when you are running out of heap space in the server, see Specifying Heap Size Values.

Choosing a Garbage Collection Scheme

Depending on which JVM you are using, you can choose from several garbage collection schemes to manage your system memory. For example, some garbage collection schemes are more appropriate for a given type of application. Once you have an understanding of the workload of the application and the different garbage collection algorithms utilized by the JVM, you can optimize the configuration of the garbage collection.

Refer to the following links for in-depth discussions of garbage collection options for your JVM:

Using Verbose Garbage Collection to Determine Heap Size

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

  2. 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:\Oracle\Middleware"
    -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:

    1. How often is garbage collection taking place? In the weblogic.log file, compare the time stamps around the garbage collection.

    2. How long is garbage collection taking? Full garbage collection should not take longer than 3 to 5 seconds.

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

  4. Review the New generation heap sizes, see Java HotSpot VM Heap Size Options.

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

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

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

System performance is greatly influenced by the size of the Java heap available to the JVM. This section describes the command line options you use to define the heap sizes 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.

Tuning Tips for Heap Sizes

The following section provides general guidelines for tuning VM heap sizes:

  • The heap sizes should be set to values such that the maximum amount of memory used by the VM does not exceed the amount of available physical RAM. If this value is exceeded, the OS starts paging and performance degrades significantly. The VM always uses more memory than the heap size. The memory required for internal VM functionality, native libraries outside of the VM, and permanent generation memory (for the Sun VM only: memory required to store classes and methods) is allocated in addition to the heap size settings.

  • When using a generational garbage collection scheme, the nursery size should not exceed more than half the total Java heap size. Typically, 25% to 40% of the heap size is adequate.

  • In production environments, set the minimum heap size and the maximum heap size to the same value to prevent wasting VM resources used to constantly grow and shrink the heap. This also applies to the New generation heap sizes.

Java HotSpot VM Heap Size Options

You achieve best performance by individually tuning each application. However, configuring the Java HotSpot VM heap size options listed in the following table 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 Comments

Setting the New generation heap size


As a general rule, set -XX:NewSize to be one-fourth the size of the 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


Set the maximum size of the New Generation heap size.

Setting New heap size ratios


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 initial heap size


As a general rule, set initial heap size (-Xms) equal to the maximum heap size (-Xmx) to minimize garbage collections.

Setting maximum heap size


Set the maximum size of the heap.

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.

Other Java HotSpot VM Options

Oracle provides other standard and non-standard command-line options to improve the performance of your VM. How you use these options depends on how your application is coded.

Test both your client and server JVMs to see which options perform better for your particular application. See http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html for more information on the command-line options and environment variables that can affect the performance characteristics of the Java HotSpot Virtual Machine.

For additional examples of the HotSpot VM options, see:

The Java Virtual Machine document provides a detailed discussion of the Client and Server implementations of the Java virtual machine for Java SE at http://docs.oracle.com/javase/6/docs/technotes/guides/vm/.

Manually Requesting Garbage Collection

You may find it necessary to manually request full garbage collection from the WebLogic Server Administration Console. When you do, remember that garbage collection is costly as the JVM often examines every living object in the heap. See Manually request garbage collection in Oracle WebLogic Server Administration Console Online Help.

Requesting Thread Stacks

You may find it necessary to display thread stacks while tuning your applications. See Display thread stacks in Oracle WebLogic Server Administration Console Online Help.

Increasing Java Heap Size for Managed Servers

For better performance, increase the heap size for each Managed Server in your environment.

The following sections provide information about how to modify the Java heap size for Managed Servers:

See Configuring Remote Startup Arguments in Administering Node Manager for Oracle WebLogic Server.

Using the Administration Console to Set Java Heap Size

If you use Node Manager to start the Managed Servers, you can specify a heap size as a Java argument on the Server Start tab for each Managed Server. See Increasing the Java Heap size for a managed server in the Oracle WebLogic Server Administration Console Online Help. Your heap size values are then persisted in the startup.properties file for the server.

Modify the startManagedWebLogic Script to Set Java Heap Size

You can update the startManagedWebLogic script with the required heap size in JAVA_OPTIONS. For example:


See Starting Managed Servers with a Startup Script in Administering Server Startup and Shutdown for Oracle WebLogic Server.

Using the Command Line to Set Java Heap Size

You can pass JVM parameters when starting a managed server by invoking weblogic.Server class in a Java command. See weblogic.Server Command-Line Reference in the Command Reference for Oracle WebLogic Server.

Determining the Memory Values Used by a Managed Server

Start scripts and the Administration Console (the startup.properties file) are common ways to configure memory arguments in managed servers. Often, they are set in multiple places and with different values. How do you determine which values are actually used by a running managed server?

A running managed server always uses the last set of memory arguments passed to the server during startup. You can verify this by looking through the log files. If you see the memory arguments listed multiple times, the last set in the output contains the values used by the server. If you used the Administration Console to set the values, see Using the Administration Console to Set Java Heap Size, the startup.properties file is always processed last, after all scripts. This provides a convenient method to tune memory size for an individual managed server when using common scripts. If you prefer not to include memory arguments that are not actually used in the environment, you will need to remove any extraneous memory arguments such as MEM_ARGS and JAVA_OPTONS from the scripts used to start a managed server.