简体   繁体   English

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

[英]How to do memory profiling on remote java web application

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? 任何想法?

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.policy containing : 这里有一个名为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

I usually use YourKit which is an excellent application (license needed). 我通常使用YourKit这是一个很好的应用程序(需要许可证)。

In your webservers startup/shutdown script (catalina.sh for tomcat) put in: 在你的webservers启动/关闭脚本(catalina.sh for tomcat)中输入:

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客户端并进行远程连接。

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: 例子:

Profile your application using Jprofiler. 使用Jprofiler配置您的应用程序。 Below are the steps to configure your Tomcat with Jprofiler. 以下是使用Jprofiler配置Tomcat的步骤。

  1. In Linux machine open .bash_profile file from /root directory. 在Linux机器中,从/root目录打开.bash_profile文件。
    Enter jprofiller location (using below command export) in 在中输入jprofiller位置(使用下面的命令导出)

     .bash_profile file export LD_LIBRARY_PATH=/dsvol/jprofiler6/bin/linux-x86 
  2. Go Tomcat installation directory. 去Tomcat安装目录。 Open catalena.sh file from bin folder. bin文件夹中打开catalena.sh文件。
    Enter the below details in catelana.sh file (only red color information and black color you can find by default in catalena.sh file). 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. Start the server from bin folder by executing the starup.sh command 通过执行starup.sh命令从bin文件夹启动服务器

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/

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

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