Let's continue, where we stopped in my last post: How can I monitor the increase in PermGen area ?
For monitoring PermGen, we'll learn to use a very simple tool, which is part of Java 5, called JSTAT. For those who use Linux or any other Unix-like OS, jstat is very similar to the TOP tool. JSTAT will connect to some VM, local or remote, and monitor some critical resources. Let's see how it works. Just type JSTAT and you'll see its command-line options:
JPS (Java Process Status)
Let's understand the options. The 1st thing you need to know is the VMID (Virtual Machine ID). What is the VMID ? Right now, there are 2 Java applications running on my computer, each in its own virtual machine. Each virtual machine has its own VMID. To discover the VMID that the application you need to monitor is using, you'll have to learn another tool: JPS (Java Process Status). There is a very similar tool in the Unix world called PS. JPS will list all running VMs with their VMIDs. Just type JPS on the command-line and you'll see this:
Let's understand JPS's output. In its basic form, jps outputs the VMID and the simple name of the executable class that is running in the virtual machine. In this case, I can infer the application I want to monitor, Jboss, is the first one listed, not because I know that "Main" is the name executable class, but because I can exclude the 2nd line, which is obviously EasyEclipse and the 3rd line, which is JPS. JPS itself runs inside a virtual machine and therefore, is always reported by jps. If, by the simple name of main class you cannot discover the VMID of your application, I suggest you type "jps -l" which will show the complete name of the main class for each VM. In most cases, that will do.
Now that we know that the VMID of Jboss is 1136, let's use JSTAT to monitor Jboss usage of PermGen memory. To use JSTAT, you need specify a single parameter that will identify the class of monitors you want to use. In our case, we will use "-gcpermcapacity" which will show statistics of the sizes of the Permanent Generation.
The important metrics
There are 3 important numbers to monitor regarding permanent generation size: the maximum permanent size, the current permanent size, and the current permanent utilization. Now, look at jstat's ouput. The 1st column shows the minumum size for the permsize. That's a parameter you can set in the initialization of the virtual machine. The 2nd column shows the maximum size for permsize. This is also a paramter you can set in the initialization of the virtual machine. Now, compare the 2nd column to the 3rd column. The permanent size fluctuate between the minimum and the maximum number. Now, it's just the minimum number. But that doesn't mean it's all used. To know how much of the current permanent size is being used, we'll have to look at another number, the Permanent Capacity Utilization, which you can see using the "-gcutil" parameter. If [minimum] = [maximum] permanent size, then [current] = [maximum] = [minimum] permanent size. Therefore, this number will not be very useful. But, if [minimum] < [maximum], knowing if [current] is getting closer to [maximum] is of vital importance. If [current] is only a few megabytes bellow maximum, maybe this is the right time to change Jboss Installation, so that its virtual machine is initialized with a greater MAXIMUM permanent size.
Well, we'll learn how to do that in part3.