简体   繁体   English

如何在没有 jhat 或 jstat 的情况下为我的 JBoss 进程生成堆转储?

[英]How do I generate a heap dump for my JBoss process without jhat or jstat?

I'm using JBoss 7.1.3 with the following Java, Linux versions …我将 JBoss 7.1.3 与以下 Java、Linux 版本一起使用……

[dave@mymachine ~]$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
[dave@mymachine ~]$ uname -a
Linux mymachine.mydomain.org 4.1.99-99.88.amzn1.x86_64 #1 SMP Fri Feb 5 23:44:22 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I want to figure out how much heap is being used (not the maximum amount, but what is currently being used).我想弄清楚正在使用多少堆(不是最大数量,而是当前正在使用的数量)。 Sadly, on our machine I don't have access to jmap or jstat.遗憾的是,在我们的机器上,我无法访问 jmap 或 jstat。 So I wanted to do a heap dump using “kill -3”.所以我想使用“kill -3”做一个堆转储。 So I first got the pid of my boss process所以我首先得到了我老板进程的pid

[dave@mymachine ~]$ ps -elf | grep jboss
1 S root      1251     1  0  80   0 - 28870 -      07:03 ?        00:00:00 /bin/sh /etc/rc3.d/S84jboss start
4 S root      1254  1251  0  80   0 - 34424 -      07:03 ?        00:00:00 runuser -s /bin/bash jboss -c ulimit -S -c 0 >/dev/null 2>&1 ; LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=/var/run/jboss-as/jbos-as-standalone.pid /usr/java/jboss/bin/standalone.sh -c standalone.xml
4 S jboss     1255  1254  0  80   0 - 28271 -      07:03 ?        00:00:00 bash -c ulimit -S -c 0 >/dev/null 2>&1 ; LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-standalone.pid /usr/java/jboss/bin/standalone.sh -c standalone.xml
0 S jboss     1256  1255  0  80   0 - 28272 -      07:03 ?        00:00:00 /bin/sh /usr/java/jboss/bin/standalone.sh -c standalone.xml
0 S jboss     1289  1256  3  80   0 - 603908 -     07:03 ?        00:18:26 /usr/java/default/bin/java -D[Standalone] -server -XX:+UseCompressedOops -Xms256m -Xmx1024m -XX:MaxPermSize=512m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.server.default.config=standalone.xml -Dorg.jboss.as.logging.per-deployment=false -Dorg.jboss.boot.log.file=/usr/java/jboss/standalone/log/boot.log -Dlogging.configuration=file:/usr/java/jboss/standalone/configuration/logging.properties -jar /usr/java/jboss/jboss-modules.jar -mp /usr/java/jboss/modules -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -Djboss.home.dir=/usr/java/jboss -Djbos.server.base.dir=/usr/java/jboss/standalone -c standalone.xml
0 S 602      21746 20632  0  80   0 - 27615 pipe_w 16:46 pts/1    00:00:00 grep --color=auto jboss

and then I ran “kill -3” …然后我跑了“kill -3”……

[dave@mymachine ~]$ sudo kill -3 1289 1256

but nothing prints out and no file is generated in the current directory.但没有打印出来,也没有在当前目录中生成文件。 How do I generate a heap dump with my current constraints?如何使用当前约束生成堆转储?

I suspect that the main reason that you do not have access to the excellent serviceability tools like jmap , jstack etc. is that they are not part of the openjdk-6-jre , or openjdk-7-jre Linux packages (I am assuming debian distro here).我怀疑您无法访问jmapjstack等出色的可维护性工具的主要原因是它们不是openjdk-6-jreopenjdk-7-jre Linux 软件包的一部分(我假设是 debian发行版在这里)。 I do not understand why that should be the case.我不明白为什么会这样。 In my opinion, these tools should be a part of the JRE and not the JDK .在我看来,这些工具应该是JRE而不是JDK Here's the proof:这是证据:

$> apt-file list openjdk-6-jdk | grep jmap
openjdk-6-jdk: /usr/lib/jvm/java-6-openjdk-amd64/bin/jmap
openjdk-6-jdk: /usr/lib/jvm/java-6-openjdk-amd64/man/ja_JP.eucJP/man1/jmap.1.gz
openjdk-6-jdk: /usr/lib/jvm/java-6-openjdk-amd64/man/man1/jmap.1.gz
$> apt-file list openjdk-6-jre | grep jmap
<nothing>

Anyway, to get these tools, you should consider using the JDK and install them using sudo apt-get install openjdk-6-jdk .无论如何,要获得这些工具,您应该考虑使用 JDK 并使用sudo apt-get install openjdk-6-jdk安装它们。 This should get you not only the latest JDK 6 build (which, btw, very very old).这不仅应该为您提供最新的 JDK 6 版本(顺便说一句,非常非常旧)。 Then, you should get the access to the tools that give us the heap dump for later analysis.然后,您应该可以访问为我们提供堆转储以供以后分析的工具。

Heap dump is very different from the thread dump which shows you what the JVM threads are doing.堆转储与线程转储非常不同,后者向您展示了 JVM 线程在做什么。 One way to get the thread dump is by sending the QUIT signal to JVM process (using, like you said: kill -3 ).获取线程转储的一种方法是将QUIT信号发送到 JVM 进程(使用,就像你说的: kill -3 )。 This will show the thread dump wherever the JVM's stdout is redirected.这将在 JVM 的标准输出重定向的任何地方显示线程转储。 An (almost) equivalent tool is jstack , which is, again, a part of the JDK package, and not the JRE package.一个(几乎)等效的工具是jstack ,它也是JDK包的一部分,而不是JRE包的一部分。

But thread dump is not what you need.但是线程转储不是您所需要的。 You need heap dump.你需要堆转储。 So, you need jmap .所以,你需要jmap

Short of this, you can estimate the actual memory being used by the JVM using the indispensable Linux top command. top ,您可以使用必不可少的 Linux top命令估计 JVM 使用的实际内存。 Make sure that you analyze the output correctly to get an estimate of how much heap is being used by the JVM.确保正确分析输出以估计 JVM 使用了多少堆。

If you are experiencing an OutOfMemoryError in your JVM, then you should consider starting it with -XX:+HeapDumpOnOutOfMemoryError so that when OOME is thrown, at least you can get a heap dump.如果您在 JVM 中遇到OutOfMemoryError ,那么您应该考虑使用-XX:+HeapDumpOnOutOfMemoryError启动它,以便在抛出OOME时,至少可以获得堆转储。 But this way, you can get the heap dump only after you run out of heap space!但是这样,您只能在堆空间用完后才能获得堆转储!

set -XX:HeapDumpPath=mpath/heapdump to a writable directory or file on java's command line for starting up JBOSS.将 -XX:HeapDumpPath=mpath/heapdump 设置为 java 命令行上的可写目录或文件,用于启动 JBOSS。 This path/file needs to be writable for the user JBOSS is running under and then try the kill -3 option again.对于运行 JBOSS 的用户,此路径/文件需要是可写的,然后再次尝试 kill -3 选项。

http://five.agency/java-heap-dump/ http://five.agency/java-heap-dump/

You could also problematically do a heap dump using the HotSpotDiagnosticMXBean from your application also.您也可以使用应用程序中的 HotSpotDiagnosticMXBean 进行堆转储。

see class to dump heap查看转储堆的类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM