• No se han encontrado resultados

MAPK FAMILY MEMBERS

3. MACROPHAGE ACTIVATION

3.2. Lipopolysaccharide, LPS

3.2.2. LPS Transduction pathway

3.2.2.3. JNK MAPK

This chapter provides tutorial notes on JVM statistics monitoring tools. Topics include listing JVM processes with 'jps', the JVM remote monitoring server - 'jstatd', Java security policy file, connecting 'jps' and 'jstat' to a remote machine, RMI protocol and URL, getting garbage collection statistics with 'jstat -gcutil'.

'jps' - JVM Process Status Tool

Listing JVM Processes on the Local Machine with "jps"

'jstatd' - JVM Remote Monitoring Server Starting 'jstatd' with a Security Policy File Connecting to 'jps' to Remote 'jstatd' 'jstat' Command Options and Parameters Garbage Collection Testing Program 'jstat -gcutil' - Garbage Collection Statistics Accessing Remote JVM Processes with 'jstat' Conclusions:

JDK 1.6 offers 3 nice JVM monitoring tools: jps, jstatd, and jstat.

jps is simple tool that allows you to list all running JVM processes on the local machine or a remote machine.

jstatd is an RMI server that allows you to access local JVM processes by jps and jstat from remote machines.

jstat is a monitoring tool that allows you to obtain sample data periodically from a local or remote JVM process.

'jps' - JVM Process Status Tool

"jps": A new Java tool that lists all JVM processes on the local machine or a remote machine. "jps" tool is distributed as part of the Sun JDK package and represented by the

\Progra~1\java\jdk1.6.0_02\bin\jps.exe program file. "jps" can be executed with the following syntax:

jps [options] [hostid]

where "options" is a list of options and "hostid" is the host identifier of a remote machine.

"jps" options are listed below:

-l Output the full package name for the application's main class or the full path name to the application's JAR file.

-m Output the arguments passed to the main method. The output may be null for embedded JVMs.

-q Suppress the output of the class name, JAR file name, and arguments passed to the main

method, producing only a list of local VM identifiers.

-v Output the arguments passed to the JVM.

-Joption Pass option to the java launcher called by jps. For example, -J-Xms48m sets the startup memory to 48 megabytes. It is a common convention for -J to pass options to the underlying VM executing applications written in Java.

You don't need to use the "hostid" command argument, if you want to list JVM processes on the local machine. But to list JVM processes on a remote, you need to use "hostid" to specify how to connect to the remove machine. The "hostid" is a string with the following syntax:

[protocol:][[//]hostname][:port][/servername]

protocol

The communications protocol. The default protocol is "rmi".

hostname

A hostname or IP address indicating the remote host.

port

The default port for communicating with the remote server.

The default port is the RMI registry port (1099).

servername

The treatment of this parameter depends on the implementation.

For the "rmi" protocol, this parameter is a string representing the name of the RMI remote object on the remote host.

See sections below for tutorial examples on how to use "jps" to list JVM processes on the local or a remote machine.

Listing JVM Processes on the Local Machine with "jps"

It is very easy to listing JVM processes on the local machine using the "jps" tool. Here is what I did:

1. Run the PrimeNumberSeeker.java program I wrote in another tutorial in a command window:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\javac PrimeNumberSeeker.java C:\herong>\Progra~1\java\jdk1.6.0_02\bin\java PrimeNumberSeeker 10 200 Period, Current int, # primes

1, 2, 0 2, 12, 5 3, 21, 8 ...

2. While PrimeNumberSeeker.java is running to search for prime numbers, run the "jps" tool in another command window:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jps -l -m -v 2836 PrimeNumberSeeker 10 200

3812 sun.tools.jps.Jps -l -m -v

-Dapplication.home=C:\Program Files\java\jdk1.6.0_02 -Xms8m

Several interesting notes on the "jps" output:

Each JVM process is represented by starting class running in side the JVM.

The number displayed before the class name is the process ID.

When you run "jps", it starts a JVM process, which is also listed in the "jps" output.

The package name, "sun.tools.jps", is displayed because of the "-l" option.

The arguments passed to the main method, "10 200", are displayed because of the "-m" option.

The parameters passed to the JVM, "-D... -X...", are displayed because of the "-v" option.

'jstatd' - JVM Remote Monitoring Server

"jstatd": A server that allows JVM monitoring tools like "jps" and "jstat" to access JVM processes from a remote machine. "jstatd" tool is distributed as part of the Sun JDK package and represented by the

\Progra~1\java\jdk1.6.0_02\bin\jstatd.exe program file. "jstatd" can be executed with the following syntax:

jstatd [options]

"jstatd" options are listed below:

"-p port" Port number where the RMI registry is expected to be found. If not found, an internal RMI registry will be created with this port number.

"-n rminame" Name to which the remote RMI object is bound in the RMI registry. The default name is JStatRemoteHost.

After "jstatd" is started, JVM monitoring tools, "jps" and "jstat", can connect to it from a remote machine and access local JVM processes as shown in the picture below:

See next section on how to start "jstatd".

Starting 'jstatd' with a Security Policy File

In this tutorial, we are going to try to start the JVM remote monitoring server, "jstatd".

1. Run the "jstatd" command in a command window:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jstatd Could not create remote object

access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)

java.security.AccessControlException: access denied (java.util.PropertyPermission

java.rmi.server.ignoreSubClasses write)

at java.security.AccessControlContext.checkPermission (AccessControlContext.java:323)

at java.security.AccessController.checkPermission (AccessController.java:546)

at java.lang.SecurityManager.checkPermission (SecurityManager.java:532)

at java.lang.System.setProperty(System.java:727) at sun.tools.jstatd.Jstatd.main(Jstatd.java:122)

The "access denied" error is expected, because "jstatd" requires a security policy file specified with the

"java.security.policy" system property, if there is no security manager running on my machine.

2. Create the security policy file, tools.policy, that grants permissions to run "jstatd" and other tools in the tools.jar:

grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission;

};

3. Run "jstatd" with the security policy file, tools.policy specified to the "java.security.policy" system property:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jstatd -p 1234 -J-Djava.security.policy=tools.policy

"jstatd" is running correctly now. It created an internal RMI registry and waiting at port 1234 for RMI protocol connections from remote machines by JVM monitoring tools. See the next section on how to run "jps" and "jstat" tools from remote machines.

Connecting to 'jps' to Remote 'jstatd'

With the "jstatd" server running on my local machine as described in the previous section, now I am ready to test how to connect to this "jstatd" server with the "jps" command from a remote machine to list JVM processes.

1. Run my test Java program PrimeNumberSeeker.java in another command window on my local machine:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\java PrimeNumberSeeker 10 200 Period, Current int, # primes

1, 2, 0 2, 10, 4 ...

2. Run the "jps" command to connect to the "jstatd" server with the "rmi://localhost" URL as the host identifier:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jps -l -m -v rmi://localhost RMI Registry not available at localhost:1099

Connection refused to host: localhost; nested exception is:

java.net.ConnectException: Connection refused: connect

3. The cause of the error is obvious, the "jstatd" server started the internal RMI registry at the port 1234, not the default port 1099. So Run the "jps" command again with the "rmi://localhost:1234":

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jps -l -m -v rmi://localhost:1234

3056 sun.tools.jstatd.Jstatd -p 1234 -Dapplication.home=C:\jdk -Xms8m -Djava.security.policy=tools.policy

4080 sun.tools.jps.Jps -l -m -v rmi://localhost:1234

-Dapplication.home=C:\Program Files\java\jdk1.6.0_02 -Xms8m 2024 PrimeNumberSeeker 10 200

Cool. The "jps" successfully connected to the RMI registry through the "jstatd" server. The output shows correctly all running JVM processes.

'jstat' Command Options and Parameters

"jstat": A JVM statistics monitoring tool that displays performance statistics of a given JVM process with a specified sampling interval. "jstat" tool is distributed as part of the Sun JDK package and represented by the \Progra~1\java\jdk1.6.0_02\bin\jstat.exe program file. "jstat" can be executed with the following syntax:

jstat [options] vmid interval [count]

"options" - List of "jstat" command options.

"vmid" - Virtual machine identifier string to identify a local or a remote JVM process.

"interval" - Sampling interval in seconds (s) or mimilliseconds (ms).

"count" - Number of samples to collect. Default value is infinity; that is, jstat displays statistics until the target JVM terminates or the jstat command is terminated.

Some "jstat" options are listed below:

"-t" - Display a timestamp column as the first column of output. The timestamp is the the time since the start time of the target JVM.

"-class" - Display multiple columns of statistics on the behavior of the class loader.

"-compiler" - Display multiple columns of statistics of the behavior of the HotSpot Just-in-Time compiler.

"-gc" - Display multiple columns of statistics of the behavior of the garbage collected heap.

"-gcutil" - Display multiple columns of summary of garbage collection statistics.

"-gccapacity" - Display multiple columns of statistics of the capacities of the generations and their corresponding spaces.

See the next section on how to use "jstat" to collect statistic samples of a given JVM process.

Garbage Collection Testing Program

Since most of "jstat" options are about garbage collection statistics, I wrote this garbage collection testing program to test the "jstat" tool:

/**

* GarbageCollection.java

* Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/

*/

class GarbageCollection {

public static void main(String[] a) { int max = 10000;

int min = 16;

Object[] arr = new Object[min];

Runtime rt = Runtime.getRuntime();

System.out.println("Free/total memory:");

for (int m=0; m<max; m++) {

for (int n=0; n<min-1; n++) arr[min-n-1] = arr[min-n-2];

arr[0] = getOneMega();

System.out.println(rt.freeMemory()+" "+rt.totalMemory());

try {

private static Object getOneMega() { // return new long[1024*128]; // 1MB

When I run this program, I get this output:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\javac GarbageCollection.java C:\herong>\Progra~1\java\jdk1.6.0_02\bin\java

-Xms24m -Xmx24m GarbageCollection Free/total memory:

23725256 25034752 22710400 25034752 21618728 25034752 20523584 25034752

19429328 25034752 9552096 25034752 8452192 25034752 7357216 25034752 6258720 25034752 5159112 25034752 4060976 25034752 2965296 25034752 1865656 25034752 767256 25034752

7356032 25034752 // Garbage Collection 6257576 25034752

5159368 25034752 4060712 25034752 2964336 25034752 1867032 25034752 767176 25034752

7356512 25034752 // Garbage Collection 6258136 25034752

5159360 25034752 4060464 25034752 2964064 25034752 1866728 25034752 766568 25034752

7356272 25034752 // Garbage Collection ...

The output shows that the garbage collector is working correctly to remove those objects shifted out of the arr[].

'jstat -gcutil' - Garbage Collection Statistics

With the garbage collection testing program running, I am ready to test the "jstat" tool. The first test is run "jstat" with the "-gcutil -t" option to get statistic samples on a local JVM process.

1. Run the "jps" to get the process ID of the GarbageCollection.java JVM:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jps -l -m -v 3824 sun.tools.jps.Jps -l -m -v

-Dapplication.home=C:\Program Files\java\jdk1.6.0_02 -Xms8m 3868 GarbageCollection -Xms24m -Xmx24m

2924 PrimeNumberSeeker 10 200

2544 sun.tools.jstatd.Jstatd -p 1234 -Dapplication.home=C:\jdk -Xms8m -Djava.security.policy=tools.policy

2. Run the "jstat" to get the summary of garbage collection statistics of the GarbageCollection JVM

identified by the process ID 3868:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jstat -gcutil -t 3868 1s 30 Time S0 S1 E O P YGC YGCT FGC FGCT GCT 313.7 0.00 99.99 4.20 84.56 0.15 2093 3.653 416 13.998 17.651 314.6 0.00 99.99 0.00 97.66 0.15 2100 3.665 417 14.023 17.688 315.6 0.00 0.00 0.00 71.25 0.15 2106 3.674 419 14.090 17.764 316.7 0.00 99.99 4.20 84.56 0.15 2113 3.687 420 14.124 17.811 317.7 0.00 99.99 0.00 97.66 0.15 2120 3.699 421 14.158 17.858 318.6 0.00 0.00 0.00 71.25 0.15 2126 3.708 423 14.225 17.933 319.7 0.00 99.99 4.20 84.56 0.15 2133 3.721 424 14.259 17.980 320.7 0.00 99.99 0.00 97.66 0.15 2140 3.734 425 14.293 18.027 321.6 0.00 0.00 0.00 71.25 0.15 2146 3.743 427 14.360 18.103 322.7 0.00 99.99 4.20 84.56 0.15 2153 3.756 428 14.394 18.149 323.7 0.00 99.99 0.00 97.66 0.15 2160 3.769 429 14.428 18.196 324.7 0.00 0.00 67.14 71.25 0.15 2166 3.777 431 14.495 18.272 325.7 0.00 99.99 4.20 84.56 0.15 2173 3.790 432 14.528 18.319 326.7 0.00 99.99 0.00 97.66 0.15 2180 3.803 433 14.563 18.366 327.7 0.00 99.99 86.29 97.66 0.15 2185 3.810 434 14.588 18.397 328.7 99.99 0.00 0.00 77.66 0.15 2192 3.821 436 14.656 18.476 329.7 0.00 99.99 71.29 84.56 0.15 2198 3.832 437 14.690 18.522 330.7 0.00 99.99 19.15 97.66 0.15 2205 3.845 438 14.723 18.568 331.7 99.99 0.00 0.00 77.66 0.15 2212 3.855 440 14.791 18.646 332.7 0.00 99.99 71.29 84.56 0.15 2218 3.867 441 14.825 18.692 ...

The last two parameters "1s 30" tells "jstat" to collect 30 samples with an interval of 1 second.

To understand the statistic output, you need to read the full documentation of the "jstat" tool.

Accessing Remote JVM Processes with 'jstat'

In the previous section, I used the "jstat" tool to get garbage collection statistic against a JVM process on the local machine.

Now I want to use the "jstat" tool to get garbage collection statistic against a JVM process on a remote machine. Like the "jps" tool, the "jstat" tool also requires that the remote machine running the "jstatd"

server with a RMI registry.

1. Make sure that the "jstatd" server is running on the remote machine:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jstatd -p 1234 -J-Djava.security.policy=tools.policy

2. Make sure that the garbage collection program is running on the remote machine:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\java -Xms24m -Xmx24m GarbageCollection

Free/total memory:

23725256 25034752 22710400 25034752 ...

3. Run the "jps" tool to get a list of JVM process IDs on the remote machine:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jps -l -m -v rmi://localhost:1234

2924 PrimeNumberSeeker 10 200

2544 sun.tools.jstatd.Jstatd -p 1234 -Dapplication.home=C:\jdk -Xms8m -Djava.security.policy=tools.policy

3028 sun.tools.jps.Jps -l -m -v rmi://localhost:1234

-Dapplication.home=C:\Program Files\java\jdk1.6.0_02 -Xms8m 3536 GarbageCollection -Xms24m -Xmx24m

4. I am ready to run the "jstat" tool to get some statistics data on the garbage collection program:

C:\herong>\Progra~1\java\jdk1.6.0_02\bin\jstat -gcutil -t rmi://3536@localhost:1234 1s 30

Time S0 S1 E O P YGC YGCT FGC FGCT GCT 303.6 0.00 99.99 86.29 97.66 0.15 2025 3.589 402 13.500 17.089 304.6 99.99 0.00 35.16 77.66 0.15 2032 3.597 404 13.559 17.155 305.6 100.00 0.00 51.20 90.69 0.15 2039 3.610 405 13.592 17.202 ...

Cool. The "jstat" tool works nicely to get statistics data from a JVM process on a remote machine.

Chapter - 9