JVM memory allocation parameters

The Java virtual machine uses its heap storage for dynamic allocation memory. In addition, each thread requires reserved memory for the stack used to pass method parameters. These parameters must be configured in the Java virtual machine startup options.

Table 2-1 describes the JVM memory allocation options. Configure these parameters for the server by setting the indicated environment variables in the bin\local-setenv.bat file (for Windows platforms) or bin/local-setenv.sh script (for UNIX platforms).

Table 2-1: JVM memory allocation parameters

Parameter

Description

-XmxMaxHeap

Specifies the maximum heap size. MaxHeap is the heap size value specified using the syntax in Table 2-2. The JVM reserves this much memory at start-up. The memory used for object allocation cannot exceed this amount. If the heap size is exceeded, you see request failures accompanied by java.lang.OutOfMemoryError errors in the error log.

To set this property, set the DJC_JVM_MAXHEAP environment variable to the heap size value specified using the syntax in Table 2-2.

-XmsMinHeap

Specifies the minimum, or initial heap size. MinHeap is the heap size value specified using the syntax in Table 2-2. While the maximum size is reserved at start-up, only the minimum size is monitored and allocated from by the JVM.

On production servers, set this value to the same size as the maximum heap size. The maximum heap size is reserved at server start-up regardless of the minimum size, and using equal sizes avoids the CPU overhead of dynamically growing the heap.

To set this property, set the DJC_JVM_MINHEAP environment variable to the heap size value specified using the syntax in Table 2-2.

-XssStackSize

Configures the stack size for Java threads. StackSize is the amount of virtual memory reserved for the stack of each Java thread. To set this property, add it to the Java Startup Options server property in the Management Console (or the javaStartupOptions property if using Ant configuration); this property specifies other JVM startup options as they are passed on the Java command line.

The optimum heap size depends on your application and machine configuration. To tune the value, first verify that you have removed any memory leaks from your own code. Then test under expected peak load conditions to determine the minimum size that allows the application to run without errors. If the heap size is too large, it uses memory that could otherwise be used for the call stack required to run each thread. Large heap sizes can also incur a larger delay when the Java garbage collector runs. Never set the heap size larger than the machine’s physical memory; if you do, the system will swap memory to disk. Set the minimum and maximum sizes to equal values, specified in bytes, kilobytes, or megabytes, as described in Table 2-2.

Table 2-2: Syntax for Java heap size values

Heap size value syntax

To indicate

nM

or

nm

n megabytes, for example:

512M
nK

or

nk

n kilobytes, for example:

1024K
n

n bytes, for example:

536870912

Set the Java thread stack size to the smallest value that still allows the application to run. Usual values are 256K or 512K for the applications used for internal stress testing at Sybase. Most applications should never require more than 1Mb. The stack must be large enough to accommodate parameters passed in component dispatcher and intercomponent calls. However, if the value is too high, it limits the maximum number of threads that can be spawned. To run N threads, there must at least N x StackSize of free memory available.