Tuning JVM server heap and garbage collection

Garbage collection in a JVM server is handled by the JVM automatically. You can tune the garbage collection process and heap size to ensure that application response times and processor usage are optimal.

About this task

The garbage collection process affects application response times and processor usage. Garbage collection temporarily stops all work in the JVM and can therefore affect application response times. If you set a small heap size, you can save on memory, but it can lead to more frequent garbage collections and more processor time spent in garbage collection. If you set a heap size that is too large, the JVM makes inefficient use of MVS™ storage and this can potentially lead to data cache misses and even paging. CICS® provides statistics that you can use to analyze the JVM server. You can also use IBM® Health Center, which provides the advantage of analyzing the data for you and recommending tuning options.

Procedure

  1. Collect JVM server and dispatcher statistics over an appropriate interval. The JVM server statistics can tell you how many major and minor garbage collections take place and the amount of time that elapsed performing garbage collection. The dispatcher statistics can tell you about processor usage for T8 TCBs across the CICS region.
  2. Use the dispatcher TCB mode statistics for T8 TCBs to find out how much processor time is spent on JVM server threads.
    The Accum CPU Time / TCB field shows the accumulated processor time taken for all the TCBs that are, or have been, attached in this TCB mode. The TCB attaches field shows the number of T8 TCBs that have been used in the statistics interval. Use these numbers to work out approximately how much processor time each T8 TCB has used.
  3. Use the JVM server statistics to find the percentage of time that is spent in garbage collection.
    Divide the time of the statistics interval by how much elapsed time is spent in garbage collection. Aim for less than 2% of processor usage in garbage collection. If the percentage is higher, you can increase the size of the heap so that garbage collection occurs less frequently.
  4. Divide the heap freed value by the number of transactions that have run in the interval to find out how much garbage per transaction is being collected.
    You can find out how many transactions have run by looking at the dispatcher statistics for T8 TCBs. Each thread in a JVM server uses a T8 TCB.
  5. Optional: Write the verbosegc log data to a file, which can be done with the parameter -Xverbosegclog:path_to_file. This data can be analyzed by another ISA tool - Garbage Collection and Memory Visualizer.
    The JVM writes garbage collection messages in XML to the file that is specified in the STDERR option in the JVM profile. For examples and explanations of the messages, see IBM SDK for z/OS, Java Technology Edition, Version 7, Troubleshooting and support section.
    Tip: You can use the file in the Memory Analyzer tool to perform more detailed analysis.

Results

The outcome of your tuning can vary depending on your Java™ workload, the maintenance level of CICS and of the IBM SDK for z/OS®, and other factors. For more detailed information about the storage and garbage collection settings and the tuning possibilities for JVMs, see IBM SDK for z/OS, Java Technology Edition, Version 7, Troubleshooting and support section.

IBM Health Center and Memory Analyzer are two IBM monitoring and diagnostic tools for Java that are supplied by the IBM Support Assistant workbench. You can download these tools free of charge from the IBM Software Support site.