Apr 12, 2010

Case Study on High CPU utilization by Java GUI Based Application

Case Study: Increase in CPU usage for a Multi-Thread Java Application.

Problem Description:

A multi-threaded GUI based Java application running on a Solaris machine caused a significant rise in the CPU usage leading to slowness of the application and occasional hang-ups.

The prstat output is as follows:

PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP

4313 vinay 159M 83M run 0 0 0:15:07 40% vinayview/53

4312 root 22M 19M sleep 59 0 0:02:15 5.1% mmdp/31

4484 vinay 3280K 2840K cpu0 49 0 0:00:00 0.2% prstat/1

Analysis:

  • Usually for a multi-thread GUI java application, the common problem found is the unusual increase in CPU usage and slowness. The default heap size defined for the JVM is usually not enough to run big applications since lots of objects are created and processed. If the allocated heap size is not enough, then Garbage Collector runs continuously to clear the unused objects consuming majority of CPU resource. Hence, tuning the JVM heap size becomes necessary.
  • The rule of thumb is to set same values for both minimum and maximum heap memory but it can be changed as per the requirement of the application.

Solution:

The above problem was solved by increasing the minimum and maximum heap size to 256 MB each as against the default values of 1MB and 64MB respectively. The minimum and maximum values for the heap size are passed as arguments to the VM while creating the executable for the application.

The code snippet is as follows:

// *********************************************************

// ***** IMPORTANT *****

// specify vm_args version # if you use JDK1.1.2 and beyond

// *********************************************************

vm_args.version = JNI_VERSION_1_2 ;

options[0].optionString = cpathoption;

options[1].optionString = vhomeoption;

options[2].optionString = doption;

options[3].optionString = "-Xms256m";

options[4].optionString = "-Xmx256m";

vm_args.options = options;

vm_args.ignoreUnrecognized = JNI_TRUE;

The prstat output after tuning the JVM heap size is as follows:

PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP

4328 vinay 368M 89M sleep 59 0 0:00:14 1.3% vinayview/21

1278 root 16M 13M sleep 59 0 0:43:45 0.3% mmdp/26

1410 root 170M 79M sleep 59 -20 1:10:59 0.1% java/37

4333 vinay 4896K 4552K cpu1 59 0 0:00:00 0.1% prstat/1

Even for running a java applet, the runtime parameters require to be set. Since JVM runs before the execution of the applet so the runtime parameters can be set using the Java Control Panel.

The users who have deployed the latest Jdk will get an option, Java Plug-in node which enables the option to add runtime parameters through applet tag.

References:

0 comments:

Text Widget

Copyright © Vinay's Blog | Powered by Blogger

Design by | Blogger Theme by