如何对远程 Java Web 应用程序进行内存分析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/194328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:22:06  来源:igfitidea点击:

How to do memory profiling on remote java web application

javamemoryprofiling

提问by Nick Long

I know we can use tools like JProfiler etc. Is there any tutorial on how to configure it to display the memory usage just by remote monitoring?

我知道我们可以使用 JProfiler 等工具。有没有关于如何配置它以仅通过远程监控显示内存使用情况的教程?

Any idea?

任何的想法?

回答by MatthieuGD

you have VisualGC, it's not very advanced but you can see the memory usage of your application (garbage,old, perm etc...)

你有 VisualGC,它不是很先进,但你可以看到你的应用程序的内存使用情况(垃圾、旧、烫等......)

http://java.sun.com/performance/jvmstat/visualgc.html

http://java.sun.com/performance/jvmstat/visualgc.html

to resume : you launch a daemon monitoring on the remote machine (http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstatd.html, see the security parapraph)

恢复:您在远程机器上启动守护进程监控(http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstatd.html,请参阅安全说明)

JAVA_HOME/bin/jstatd -J-Djava.security.policy=jstatd.all.policy

with a file here called jstatd.all.policycontaining :

这里有一个名为jstatd.all.policy的文件,其中包含:

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

on the remote machine you got the pid of your application to debug with the jps tool :

在远程机器上,您可以使用 jps 工具获得应用程序的 pid 进行调试:

http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html#jps

http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html#jps

finally on your local machine you launch the visualgc :

最后在本地机器上启动 visualgc :

visualgc the_pid@remote_machine_address

回答by joejag

I usually use YourKit which is an excellent application (license needed).

我通常使用 YourKit,这是一个很好的应用程序(需要许可证)。

In your webservers startup/shutdown script (catalina.sh for tomcat) put in:

在您的网络服务器启动/关闭脚本(tomcat 的 catalina.sh)中输入:

JAVA_OPTS="-Djava.awt.headless=true -agentlib:yjpagent -Xrunyjpagent:sessionname=Tomcat"

You'll need YourKit already downloaded and added to your library path (I do this in catalina.sh as well):

您需要已经下载并添加到您的库路径中的 YourKit(我也在 catalina.sh 中这样做):

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/yourkit/yjp-6.0.16/bin/linux-x86-32

You can then launch the YourKit client on your local desktop and remotely connect.

然后,您可以在本地桌面上启动 YourKit 客户端并远程连接。

回答by Peter

You can change to VM params of your Java application to allow remote profiling something like -agentlib:jprofilerti=port=25000

您可以更改 Java 应用程序的 VM 参数以允许远程分析,例如 -agentlib:jprofilerti=port=25000

General explanation of JProfiler.

JProfiler 的一般说明

Examples:

例子:

回答by Madhu Cheepati

Profile your application using Jprofiler. Below are the steps to configure your Tomcat with Jprofiler.

使用 Jprofiler 分析您的应用程序。以下是使用 Jprofiler 配置 Tomcat 的步骤。

  1. In Linux machine open .bash_profilefile from /rootdirectory.
    Enter jprofiller location (using below command export) in

    .bash_profile file
    export LD_LIBRARY_PATH=/dsvol/jprofiler6/bin/linux-x86
    
  2. Go Tomcat installation directory. Open catalena.shfile from binfolder.
    Enter the below details in catelana.shfile (only red color information and black color you can find by default in catalena.sh file).

    export JPROFILER_HOME
    JAVA_OPTS="-Xms768m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF8 -agentpath:/opt/Performance/jprofiler7/bin/linux-x86/libjprofilerti.so=port=8849 $CATALINA_OPTS"
    
  3. Start the server from bin folder by executing the starup.shcommand

  1. 在 Linux 机器中,.bash_profile/root目录中打开文件。
    在中输入 jprofiller 位置(使用下面的命令导出)

    .bash_profile file
    export LD_LIBRARY_PATH=/dsvol/jprofiler6/bin/linux-x86
    
  2. 进入Tomcat安装目录。catalena.shbin文件夹中打开文件。
    catelana.sh文件中输入以下详细信息(默认情况下,您只能在 catalena.sh 文件中找到红色信息和黑色信息)。

    export JPROFILER_HOME
    JAVA_OPTS="-Xms768m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF8 -agentpath:/opt/Performance/jprofiler7/bin/linux-x86/libjprofilerti.so=port=8849 $CATALINA_OPTS"
    
  3. 通过执行starup.sh命令从 bin 文件夹启动服务器

回答by Moemars

I've heard good things of VisualVM and here is an article on how to it up remotely:

我听说过 VisualVM 的好消息,这里有一篇关于如何远程启动的文章:

Java VisualVM to profile a remote server

用于配置远程服务器的 Java VisualVM

EDIT: I wrote a blog post on how to setup remote profiling through an SSH tunnel here:

编辑:我写了一篇关于如何通过 SSH 隧道设置远程分析的博客文章:

http://kamilmroczek.com/2012/11/16/168787859/

http://kamilmroczek.com/2012/11/16/168787859/