简体   繁体   English

无法对在Windows7上作为服务运行的Tomcat7使用JVisualVM分析

[英]Unable to use JVisualVM profiling for Tomcat7 running as a service on Windows7

I'm trying to profile a Servlet running in Apache Tomcat (7.0.34) as a service on Windows 7 (64 bit) using JVisualVM (JDK 1.7.0 - 06, 64 bit) running locally. 我正在尝试使用在本地运行的JVisualVM(JDK 1.7.0 - 06,64位)将在Apache Tomcat(7.0.34)中运行的Servlet作为Windows 7(64位)上的服务进行分析。

Initially I had the problem of Tomcat not showing in the list of local applications due to the differing "java.io.tmp" property bug/feature, but worked around it as advised in several posts in this forum. 最初我遇到了Tomcat没有显示在本地应用程序列表中的问题,因为不同的“java.io.tmp”属性错误/功能,但在本论坛的几个帖子中建议解决它。

However although the Tomcat process now shows in the list of local applications as "Local Application", when I open the process there are no tabs for Monitor, Threads, Sampler or Profile - only the Overview tab for which the JVM arguments and Sytem Properties sub-tabs show the dreaded "not supported for this jvm" message. 但是,虽然Tomcat进程现在在本地应用程序列表中显示为“本地应用程序”,但是当我打开进程时,没有用于Monitor,Threads,Sampler或Profile的选项卡 - 只有JVM参数和Sytem属性子菜单的Overview选项卡-tabs显示可怕的“不支持此jvm”消息。

I have double checked the following items: 我仔细检查过以下几项:

  • that both Tomcat and JVisualVM are running the same version of Java by looking at the JVM properties in JVisualVM (using a JMX connection for Tomcat) 通过查看JVisualVM中的JVM属性(使用Tomcat的JMX连接),Tomcat和JVisualVM都运行相同版本的Java
  • that both Tomcat and JVisualVM have the same "java.io.tmp" path by looking at the System Properties in JVisualVM (again using a JMX connection for Tomcat) AND looking at the actual TMP/TEMP directory and confirming that the PID files for both exist 通过查看JVisualVM中的系统属性(再次使用Tomcat的JMX连接)并查看实际的TMP / TEMP目录并确认两者的PID文件,Tomcat和JVisualVM都具有相同的“java.io.tmp”路径存在
  • that the file system is NTFS 文件系统是NTFS
  • that the Windows user does not have an underscore in the name (Note: the user does have a period in the name as we are using network logins of the form "firstname.lastname", however I have no problems viewing other Java applications in JVisualVM so don't think this is an issue) Windows用户名称中没有下划线(注意:由于我们使用“firstname.lastname”形式的网络登录,用户确实在名称中有句点,但是在JVisualVM中查看其他Java应用程序时没有问题所以不要认为这是一个问题)
  • that both Tomcat and JVisualVM are being executed as the same Windows user by looking at the processes in Task Manager 通过查看任务管理器中的进程,Tomcat和JVisualVM都作为同一个Windows用户执行

A couple of final points: 最后几点:

  • I need to Profile the Servlet so using JMX is not sufficient 我需要配置 Servlet,因此使用JMX是不够的
  • I was able to profile on a Windows XP machine (Java 7, Tomcat 7 as a service), so would appear to be a Windows 7 / 64 bit thing? 我能够在Windows XP机器(Java 7,Tomcat 7作为服务)上进行配置,因此看起来似乎是Windows 7/64位的东西?

If anyone has had and solved this issue obviously the solution would be much appreciated. 如果有人已经解决了这个问题,那么解决方案将会非常受欢迎。 However would be useful to just know if other people are running the same configuration - Windows 7 64 bit, Java 7 64 bit, Tomcat 7 running as a service - successfully . 但是,只知道其他人是否正在运行相同的配置 - Windows 7 64位,Java 7 64位,Tomcat 7作为服务运行 - 成功

Update: Instead of running as a service, I ran Tomcat using the batch file and all worked perfectly: what is it about running as a service? 更新:我没有作为服务运行,而是使用批处理文件运行Tomcat,并且完美运行:作为服务运行的是什么?

As already hinted in my previous comment. 正如我之前的评论中已经暗示的那样。 I guess the simple answer is it's not possible . 我想简单的答案是不可能的 In order to realize the communication between jconsole/jvisualvm and the to be monitored process Java uses memory mapped files. 为了实现jconsole / jvisualvm与被监视进程之间的通信,Java使用内存映射文件。 In the end it boils down to a certain Windows API call that fails due to the "Windows Service Hardening" [1] feature added in Windows Vista and which, of course, also exists in Windows 7 and later versions. 最后归结为某个Windows API调用因Windows Vista中添加的“Windows服务强化”[1]功能而失败,当然,Windows 7及更高版本中也存在此功能。

The call which fails is to the function OpenFileMapping as can be seen in perfMemory_windows.cpp line 1402 [2]. 失败的调用是函数OpenFileMapping,可以在perfMemory_windows.cpp第1402行[2]中看到。 During my experiments the method is called with an argument of the form "hsperfdata_[username]_[process id]". 在我的实验过程中,使用“hsperfdata_ [username] _ [process id]”形式的参数调用该方法。 As further detailed in Microsofts explanation of the differences introduced by the service hardening (see [3]) communication won't work if no name prefix is used: "If a user application [...] synchronizes with the service by creating or opening objects with the Local\\ prefix (or no prefix, which defaults to Local), the application no longer works as expected." 正如在微软中进一步详细说明的那样,如果没有使用名称前缀,通信将不起作用:“如果用户应用程序通过创建或打开与服务同步,则无法解释服务强化(参见[3])引入的差异具有Local \\前缀(或没有前缀,默认为Local)的对象,应用程序不再按预期工作。“

If someone wants to take a look himself. 如果有人想看看自己。 You can use the Logger tool [4] included with the Windows debugging tools to trace API calls. 您可以使用Windows调试工具附带的Logger工具[4]来跟踪API调用。

Also the Sysinternals Process Explorer is very handy as it shows the full names used for memory mapped files via its "Find Handle or DLL..." function. 此外,Sysinternals Process Explorer非常方便,因为它通过“Find Handle or DLL ...”函数显示用于内存映射文件的全名。 Just search for handles containing "hsperf". 只需搜索包含“hsperf”的句柄。

As a side note: The workaround to delete or otherwise mess with the temporary directory which contains the hsperf data boils down to the fact that the case of the username used by the to be monitored process and the monitoring process need to be consistent. 作为旁注:删除或以其他方式弄乱包含hsperf数据的临时目录的解决方法归结为以下事实:要监视的进程和监视进程使用的用户名的情况需要保持一致。 But instead of changing the temporary directory you can also easily change the USERNAME environment variable used by the monitoring process. 但是,您也可以轻松更改监视进程使用的USERNAME环境变量,而不是更改临时目录。 You can also see how it is being used in in perfMemory_windows.cpp line 272 [2]. 你还可以在perfMemory_windows.cpp第272行[2]中看到它是如何使用的。

[1] http://technet.microsoft.com/en-us/library/cc507844.aspx#EHF [1] http://technet.microsoft.com/en-us/library/cc507844.aspx#EHF

[2] http://hg.openjdk.java.net/jdk7/hotspot-rt/hotspot/file/5dce25362b8a/src/os/windows/vm/perfMemory_windows.cpp [2] http://hg.openjdk.java.net/jdk7/hotspot-rt/hotspot/file/5dce25362b8a/src/os/windows/vm/perfMemory_windows.cpp

[3] http://msdn.microsoft.com/en-us/windows/hardware/gg463353.aspx [3] http://msdn.microsoft.com/en-us/windows/hardware/gg463353.aspx

[4] http://msdn.microsoft.com/en-us/library/windows/hardware/ff560123(v=vs.85).aspx [4] http://msdn.microsoft.com/en-us/library/windows/hardware/ff560123(v=vs.85).aspx

You nearly made it " Instead of running as a service, I ran Tomcat using the batch file and all worked perfectly: what is it about running as a service " Now the only step left was to run JVisualVM as service :) 你几乎成了“它不是作为服务运行,而是使用批处理文件运行Tomcat,并且完美运行:作为服务运行的是什么 ”现在剩下的唯一步骤就是将JVisualVM作为服务运行:)

Refer this 请参阅此

https://blogs.oracle.com/nbprofiler/entry/monitoring_java_processes_running_as https://blogs.oracle.com/nbprofiler/entry/monitoring_java_processes_running_as

Since only Java processes running under the same user as VisualVM can be profiled, the only way to profile Windows service (which is by default running under the System account) is to start the VisualVM itself as a Windows service. 由于只能分析在与VisualVM相同的用户下运行的Java进程,因此分析Windows服务(默认情况下在系统帐户下运行)的唯一方法是将VisualVM本身作为Windows服务启动。 Note that this approach doesn't work on Windows Vista due to security restrictions which by default prevent the services to display any UI. 请注意,由于安全限制,此方法在Windows Vista上不起作用,默认情况下会阻止服务显示任何UI。

Another option is to run to Run CMD.EXE as Local System , Refer below. 另一种选择是运行到本地系统运行CMD.EXE,请参阅下文。

http://vicevoice.blogspot.in/2009/09/vaas-visualvm-as-service.html http://vicevoice.blogspot.in/2009/09/vaas-visualvm-as-service.html

Can't you just connect over the network, ie start the JVM with 你不能只通过网络连接,即启动JVM

 java 
  -Dcom.sun.management.jmxremote
  -Dcom.sun.management.jmxremote.port=1234 
  -Dcom.sun.management.jmxremote.local.only=false 
  -Dcom.sun.management.jmxremote.authenticate=false 
  -Dcom.sun.management.jmxremote.ssl=false 
  -jar my.jar`

and create a network connection in the tool to localhost:1234 并在工具中创建一个网络连接到localhost:1234

I'd also be curious if anyone has a solution on Windows 7. As was noted the trick of running VisualVM as a service doesn't work on Vista and I'm assuming the same security features are preventing it from working on Win 7. 如果有人在Windows 7上有解决方案,我也很好奇。正如所指出的,运行VisualVM作为服务的技巧在Vista上不起作用,我假设相同的安全功能阻止它在Win 7上运行。

The only solution I have is to set up your app server (Tomcat) as a service so that if the server is rebooted it will come up and be available. 我唯一的解决方案是将您的应用服务器(Tomcat)设置为服务,这样如果服务器重新启动,它将会出现并可用。 Then manually stop the service and start your app server (Tomcat) from a command line and connect with VisualVM. 然后手动停止服务并从命令行启动应用程序服务器(Tomcat)并与VisualVM连接。 Then you've got nice monitoring as long as the server isn't rebooted. 然后,只要服务器没有重新启动,您就可以获得良好的监控。

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

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