简体   繁体   English

我们如何调试生产的Struts / Hibernate应用程序?

[英]How can we debug our production Struts/Hibernate apps?

So, we use Netbeans 6.9.1 , push our code to a SVN server (dev) and run local webservers (Tomcat) that connect to MySQL on a DEV machine. 因此,我们使用Netbeans 6.9.1 ,将我们的代码推送到SVN服务器(dev),然后运行连接到DEV计算机上MySQL的本地Web服务器(Tomcat)。 We can run in debug mode and step through our code. 我们可以在调试模式下运行并逐步执行代码。

However, we then take our WAR file, push to a production machine (on a production database). 但是,我们然后获取WAR文件,将其推送到生产机器(在生产数据库中)。 This machine is completely separate from dev. 该机器与开发人员完全分开。

But we run into constant problems. 但是我们遇到了持续的问题。 Things like null id in Hibernate when we have triple-checked all columns, etc. 当我们对所有列进行三重检查时,诸如Hibernate中的null id之类的事情,等等。

What we need is a way to attach a debugger to a PRODUCTION user and step through the code. 我们需要的是一种将调试器附加到PRODUCTION用户并逐步执行代码的方法。

What are our options? 我们有什么选择?

Thanks for any advice. 感谢您的任何建议。

EDIT 编辑

I wanted to post a little more information. 我想发布更多信息。 Thanks for those that have offered suggestions. 感谢那些提供建议的人。

First, our production server hosts 3 apps (along with the prod db). 首先,我们的生产服务器托管3个应用程序(以及prod数据库)。 The app we are having the most problems with just has one user and the data is almost identical to what we have in dev. 我们遇到最多问题的应用只有一个用户,数据几乎与开发人员的数据相同。 We are having transaction problems with JDBC and can't find out where they are coming from. 我们在JDBC中遇到事务问题,无法找到问题的根源。

If you really want to attach debugger to a running production server, Java is fully capable of doing this. 如果您确实想将调试器附加到正在运行的生产服务器上,则Java完全可以做到这一点。 First, run you server/JVM with the following commands: 首先,使用以下命令运行服务器/ JVM:

-Xrunjdwp:transport=dt_socket,address=8778,server=y,suspend=n

Now you can attach your IDE using prd_server:8788 address in Eclipse or IntelliJ IDEA . 现在,您可以使用EclipseIntelliJ IDEA中的 prd_server:8788地址连接IDE。

However there are few gotchas: 但是,有一些陷阱:

  • You need to have TCP/IP access to production server on a specified port. 您需要在指定端口上具有对生产服务器的TCP / IP访问。 Probably some firewall/SSH tunnelling will be involved. 可能会涉及一些防火墙/ SSH隧道。

  • By default your debugger might suspend all threads when it hits the breakpoint. 默认情况下,调试器在遇到断点时可能会挂起所有线程。 Make sure you only suspend the current one, otherwise you will freeze the whole server. 确保仅暂停当前服务器,否则将冻结整个服务器。

  • ...yes, remote debugging is dangerous , especially on production. ...是的,远程调试很危险 ,尤其是在生产环境中。

  • JVM in debug mode/listening for debug connections might be slightly slower (haven't seen it though). 处于调试模式/侦听调试连接的JVM可能会稍微慢一些(虽然没有看到)。

If you are willing to debug the production environment remotely than beware it will slow down your applicaton. 如果您愿意远程调试生产环境而不是提防它会减慢您的应用程序。 But in case if you are not able to replicate the issue on development server than please follow the steps to remotely debug the applicaton : - 但是,如果您不能在开发服务器上复制问题,请按照以下步骤远程调试应用程序:-

  1. Make sure your production server is having debug port open to connect debug remotely. 确保生产服务器的调试端口打开以远程连接调试。
  2. Debug setting differ for different-different application server 调试设置因不同的应用程序服务器而异
  3. If you are using Eclispe than right click on the project and go to debug configuration enter the production server name/IP and the port number and than hit the debug button. 如果您使用的是Eclispe,则右键单击该项目并转到调试配置,输入生产服务器名称/ IP和端口号,然后单击调试按钮。 Mkae sure your server is having debug port open 确保您的服务器打开了调试端口

Let us know which production server you are using. 让我们知道您正在使用哪个生产服务器。

You can configure Tomcat to allow remote debugger connections , but I would not advise doing so as you will significantly slow down execution of the JVM while a debugger is attached, and I believe whenever a breakpoint is hit the execution of all threads will be paused. 可以 将Tomcat配置为允许远程调试器连接 ,但是我不建议这样做,因为在连接调试器时 ,这会大大减慢JVM的执行速度,而且我相信,只要遇到断点,所有线程的执行都会暂停。

Much better to recreate the problem using the production data on a dev server, add more logging, etc etc. 使用开发服务器上的生产数据,添加更多日志记录等来重新创建问题要好得多。

Before you attempt to debug Prod, migrate your Prod data down to a Dev env and debug there. 在尝试调试Prod之前,请将您的Prod数据向下迁移到Dev env并在那里进行调试。 If you have a security policy against Prod data in a non-Prod env, sanitize the data as needed. 如果您有针对非Prod环境中Prod数据的安全策略,请根据需要清理数据。

If the issue is data related, you should hit it fairly quickly. 如果问题与数据有关,则应尽快解决。

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

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