![]() |
![]() |
|
|
| |
Tuning Java Virtual Machines (JVMs)
The Java virtual machine (JVM) is an "execution engine" that executes the byte codes in Java class files on a microprocessor. How you tune your JVM affects the performance of WebLogic Server and your applications.
This document discusses the following JVM tuning topics:
For links to related reading, see Java Virtual Machine (JVM) Information.
Table 2-1 presents general JVM tuning considerations.
Issue |
Description |
---|---|
JVM vendor and version |
Use only production JVMs on which WebLogic Server has been certified. WebLogic Server 6.x supports only those JVMs that are Java 1.3-compliant. The Platform Support page is frequently updated and contains the latest certification information on various platforms. |
Tuning heap size and garbage collection |
For tuning details, see About JVM Heap Size. For a good overview of garbage collection, see Tuning Garbage Collection with the 1.3.1 Java Virtual Machine |
Generational garbage collection |
|
Mixed client/server JVMs |
Deployments using different JVM versions for the client and server are supported in WebLogic Server. For information about support for mixed client/server JVMs. |
UNIX threading models |
There are two UNIX threading models: green threads and native threads. To get the best performance and scalability with WebLogic Server, choose a JVM that uses native threads. For Solaris, see "Threading Models and Solaris Versions Supported" on the JavaSoft web site. |
Just-in-Time (JIT) JVMs |
Use a JIT compiler when you run WebLogic Server. Most JVMs use a JIT compiler, including those from Sun Microsystems and Symantec. See your JVM supplier documentation for more information. Note: Sun's JVM 1.3.x, JIT options are no longer valid. See Java Virtual Machine (JVM) Information. |
Garbage collection is the VM process of de-allocating unused Java objects in the Java heap.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, the object is garbage.
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 you spend doing garbage collection while maximizing the number of clients that you 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.
About Generational Garbage Collection
The 1.3 Java HotSpot JVM uses generational garbage collection. While naive garbage collection examines every living object in the heap, generational garbage collection considers the lifetime of an object to avoid extra work.
The heap is divided into two general areas: New and Old. The New generation area is sub-divided further into Eden and two survivor spaces. Eden is the area where new objects are allocated. When garbage collection occurs, live objects in Eden are copied into the next survivor space. Objects are copied between survivor spaces in this way until they exceed a maximum threshold, and then they are moved out of the New area and into the Old. For information about specifying the size and ratios of the New and Old generation areas, see Specifying Heap Size Values.
Many objects become garbage shortly after being allocated. These objects are said to have "infant mortality." The longer an object survives, the more garbage collection it goes through, and the slower garbage collection becomes. The rate at which your application creates and releases objects determines how often garbage collection occurs. Attempt to cache objects for re-use, whenever possible, rather than creating new objects.
Knowing that a majority of objects die young allows you to tune for efficient garbage collection. When you manage memory in generations, you create memory pools to hold objects of different ages. Garbage collection can occur in each generation when it fills up. If you can arrange for most of your objects to survive less than one collection, garbage collection is very efficient. Poorly sized generations cause frequent garbage collection, impacting your performance.
For a good overview of generational garbage collection, see Tuning Garbage Collection with the 1.3.1 Java Virtual Machine
This section describes basic steps for determining the most effective heap size:
See Turning On Verbose Garbage Collection and Redirecting Output.
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.
Typically, you should use 80% of the available RAM (not taken by the operating system or other processes) for your JVM.
See also Specifying Heap Size Values
Turning On Verbose Garbage Collection and Redirecting Output
This section describes how to turn on verbose garbage collection and redirect output to a log file for diagnostic purposes:
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:
% java -ms64m -mx64m -verbosegc -classpath $CLASSPATH
-Dweblogic.domain=mydomain -Dweblogic.Name=clusterServer1
-Djava.security.policy==/bea/weblogic6x/lib/weblogic.policy
-Dweblogic.management.server=192.168.0.101:7001 -Dweblogic.management.username=system
-Dweblogic.management.password=systemPassword weblogic.Server >> logfile.txt
On HPUX, use the following option to redirect stderr stdout to a single file:
-Xverbosegc:file=/tmp/gc$$.out
where $$ maps to the PID of the java process. Because the output includes timestamps for when garbage collection ran, you can infer how often garbage collection occurs.
On Solaris, use the following command:
weblogic.Server > server.out 2>&1
You can specify Java heap size values when starting the WebLogic Administration Server from the Java command line. For 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.
Be aware that WebLogic Server startup and environment scripts affect these parameters. Sample scripts are provided with the WebLogic distribution for starting the default server and for setting the environment to build and run the server:
You will need to modify these scripts to fit your environment and applications. See Starting and Stopping WebLogic Servers.
You achieve best performance by individually tuning each of your applications. Configuring the JVM heap size options listed in Table 2-2 increases performance for most applications.
The options listed in Table 2-2 may differ depending on your architecture and operating system. See your vendor's documentation for platform-specific JVM tuning options.
Make sure that full garbage collection is necessary before forcing it on a server. When you force garbage collection, the JVM often examines every living object in the heap.
To use the Administration Console to force garbage collection on a specific server:
Note that the Memory Usage graph displays only for servers that are currently running.
A message displays indicating that the collection operation was successful.
Setting Java HotSpot VM Options
You can use standard java options to improve performance. Be aware that 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.
You need to test both your client and server JVMs and see what performs better for your particular application.
See Setting Non-Standard Java Command Line Options for more VM options that affect performance.
For NT, WebLogic Server invokes the JVM via the java command. Use the options listed in listed in Table 2-3.
Option |
Description |
---|---|
-hotspot |
Selects the Client HotSpot VM. |
-server |
Selects the server VM. |
-classic |
Selects the classic VM. |
For UNIX, the WebLogic Server invokes the JVM via the java command. Use the options listed in listed in Table 2-4.
Option |
Description |
---|---|
-client or -hotspot |
Selects the Client HotSpot VM. |
-server |
Selects the server VM. |
Setting Non-Standard Java Command Line Options
You can use non-standard java options to improve performance. Be aware that 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.
Some examples of non-standard options for improving performance on the Hotspot VM on NT are listed in Table 2-5.
Option |
Description |
---|---|
-Xnoclassgc |
This option disables garbage collection for the class, It prevents re-loading of the class when the class is referenced after all references to it have been lost. This option requires a greater heap size. |
-oss |
This option controls the Java thread stack size. Setting it too high (>2MB) severely degrades performance. |
-ss |
This option controls the native thread stack size. Setting it too high (>2MB) severely degrades performance. |
-Xverbosegc:file=/tmp/gc$$.out |
This option redirects -verbosegc messages to a file, allowing you to separate your garbage collection messages from the rest of the messages on stderr. It also provides a performance advantage because writes to files are buffered better than writes to a character stream like stderr. See also Turning On Verbose Garbage Collection and Redirecting Output. |
Non-Standard Options for Solaris
See non-standard options for Solaris VMs.
![]() |
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|