□Java Jvmstatの使い方(チューニング)
Jvmstatは、Javaアプリケーションのヒープ領域について、外部から確認できるツールです。
□入手方法
Sunの下記のURLから最新版が取得できます。(現在(20006/9/8)v3.0)
最新版のv3.0は、Java1.5以上となっており、Java1.4.2の場合は、SunのFAQページから
v2.0をダウンロードすることで、使用可能です。
□設定方法(Linuxの場合)
設定方法は、アーカイブファイルをダウンロードして、任意のディレクトリに展開して、
下記の設定のにて使用可能になります。
1.環境変数 PATHに、~/jvmstat/bin/のパスを追加
2.Javaの実行に必要な環境変数を追加
□使用方法
1.JavaのプロセスIDを取得します。jvmspsにて取得が可能です。
jvmps
(実行例)
[root@db2node207 iplocks]# jvmps
25296 jvmps.jar
11128 visualgc.jar
8645 jvmstat.jar
24093 org.apache.catalina.startup.Bootstrap
※左側の数値が、javaのプロセスIDになります。
実行例のうち、"org.apache.catalina.startup.Bootstrap"が、tomcatのプロセスになります。
2.1で得たプロセスIDを基に、jvmstat を実行します。
jmvstat -gcutil -h <ヘッダ表示行間隔> <プロセスID> <間隔[ミリ秒]>
(実行例)
[iplocks@db2node207 iplocks]$ jvmstat -gcutil 24093 -h 10 10000
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.00 45.40 2.27 67.98 89.77 10743 44.957 19 7.009 51.965
47.06 0.00 49.39 67.98 89.77 10744 44.962 19 7.009 51.970
0.00 47.04 98.26 67.99 89.77 10745 44.965 19 7.009 51.973
S0 |
Survivor 0 領域の使用率 |
S1 |
Survivor 1 領域の使用率 |
E |
Eden 領域の資料率 |
O |
Old Generatio 領域の使用率 |
P |
Perm Generation 領域の使用率 |
YGC |
Young Generation(New領域)でのGC実行回数 |
YGCT |
YGC所要時間 |
FGC |
Full GC実行回数 |
FGCT |
Full GC所要時間 |
GCT |
総GC所要時間 |
※使用率の分母となるものは、その時点でOSから確保しているメモリ量がもととなっており、
-Xmxなどで設定したヒープ最大メモリが基となっていません。使用率が100%を超えても
さらにOSからメモリーを確保して通常に実行が可能な場合もあります。
visualgc(要:Xウィンドウ)を確認することで、その相関関係を容易に理解することが
出来ます。
GC仕様 : ご参考まで
JVMで新たにメモリをアロケートする際は、まずEden領域へ割り当てられます。この領域が一杯に
なったら、GCが発生し、この際まだ使用中のメモリはS0/S1へコピーされます。そしてEden領域は空になり
ます。また、S0/S1はスイッチして使用され、GCの際SO/S1間で、使用中のものだけが転送されて
クリアされます。S0/S1間を繰り返し往復しているものについては、長期間必要なメモリ割り当てと
して、Old領域にコピーされます。
Eden ⇒ S0 ⇔ S1 ⇒ Old
もし、New領域(Eden+S0+S1)が不足していた場合、度々Old領域にS0/S1に収まりきれず、
Old領域にあふれ出し、度々Full GCが発生することになります。
この様な状況が、jvmstat、visualgc等のツールで確認することができます。
(補足)
Windowsで使う場合の注意点があります。
4. I'm running on Windows and I've installed J2SE 1.4.2 and jvmstat 2.0, but when I run jvmps it does not display any java processes. I can run 'visualgc 0' and it will work, but I cannot get visualgc or any other jvmstat tool to monitor other Java processes.
The problem is most likely that your default Windows temporary directory is on a FAT type file system. For security reasons, the shared memory exported by the HotSpot JVM is disabled whenever the JVM encounters a FAT type file system (more precisely, any file system that does not support persistent access control lists) as such file systems provide insufficient access controls.
There are two potential work-arounds for this issue:
Set the TMP environment variable to refer to a directory on an NTFS file system, or any file system that supports persistent access control lists. Note that this file system should be local to the machine. Setting this option for target applications is application specific. To set this variable in a command prompt or in a batch script, simply enter the following:
set TMP=path
The environment variable can be set globally by adding it to the list of environment variables in the System Properties (Control Panel->System, select the "Advanced" tab and click on the "Environment Variables" button). Through this interface, you can choose to set the variable for all processes run by the current user or globally as a system variable for all processes run by the system.
The TMP variable must refer to the same location for both the monitored applications and the jvmstat tools.
Changing the TMP environment variable to refer to an NTFS type file system is not always a viable option. For these cases, the HotSpot JVM provides a mechanism to bypass the the file system type check. However, using this mechanism instructs the HotSpot JVM to create the jvmstat shared memory without any access controls, allowing access to the instrumentation exported by the JVM to any user on the system.
To bypass the file system type check, set the -XX:+PerfBypassFileSystemCheck on the java command line for both the applications you want to monitor and for the jvmstat tools. Setting this option for target applications is application specific. For the jvmstat tools, the following environment variable can be set before running any of the commands:
set VMARGS=-XX:+PerfBypassFileSystemCheck
For the jvmstat tools bundled with JDK 5.0, include the following option on the command line (jps command used for illustrative purposes):
jps -J-XX:+PerfBypassFileSystemCheck
最終更新:2007年02月07日 19:39