IntelliJ IDEA: debug a Java application deployed in a cluster environment

已回答

Each time when I need to debug a Java application deployed in a cluster environment I am in big trouble.

Company's environments (Test, Acceptance, etc.) usually is cluster environments with multiply servers and in front of the cluster, there is a proxy server that forwards the requests (HTTP) to one of the servers in the cluster. If you have no access to the individual servers and you are not allowed to lunch the app from one particular server then you must use the endpoint that comes from the proxy.

As I know one IntelliJ can open only one remote debug connection. That means if the request goes to another server in the cluster (where my debugger is not attached) then I can not see anything in my debug window. Maybe next time.

If you are lucky you can stop all servers in the cluster except one, what you are debugging. But to stop servers is also not easy, especially in Acceptance environments.

According to my colleagues, I can debug multiply servers with one Eclipse instance, but I really do not wanna use Eclipse.

Okay, I guess that I can copy the whole source code to a different folder, open the code with a new IntelliJ instance, and from there I can connect to the 2nd server in the cluster. But this is a painful hack.

Is there any normal way how to debug the cluster environment with multiply servers with IntelliJ?

0

As commended in your another post - IDE can open any number of remote Java debug connections as launched at the remote end: the debugger connects to specific ip address and tcp port. 

>As I know one IntelliJ can open only one remote debug connection. That means if the request goes to another server in the cluster (where my debugger is not attached) then I can not see anything in my debug window. Maybe next time.

I do not actually understand what do you mean by "where my debugger is not attached" . Is the JVM that runs there is different than the JVM on another server? If it differs - then you obviosely can start it with different debugger port (and host) and use another Remote JVM Debug configuration in IDE to connect to that remote JVM.

If the JVM is the same and the port and host for debugger connection is the same - then you must have all the sources from all your remote servers combined under the project where you launch this debug configuration and do not specify the module in Run/Debug Configurations | Use module classpath: option - then IDE will not limit classpath search to a certain module classes but will look for all the classes in project.

0

A cluster environment contains multiply application servers running on different host machines. When an application is deployed to a cluster then the EAR is deployed automatically to all servers in the cluster. That means, the same EAR is deployed and runs on different JVMs. But because it is a cluster it is a distributed (redundant) environment. When an (HTTP or whatever) request arrived at the proxy then it is forwarded to one of the working servers in the cluster. So it is unknown in advance that which server (JVM) in the cluster will serve the request.

When I start the IntelliJ debug, it connects to ONE JVM and I can debug the app if the request is forwarded to the server, where intellij connects. But if the request goes to a different server (JVM) in the cluster then I can not debug this request with the same IntelliJ instance. I need to start a new IntelliJ, open the same source code twice and connect to JVM 1 from the 1st Intellij, and connect to the 2nd JVM from the 2nd Intellij.

If the cluster has 4 application servers this debug nightmare continues. 

An Eclipse instance can conect to multiply hosts (JVMs) parallelly via the multiply debug hosts and ports and stop at the breakpoint. It really does not matter whether the request was forwarded to host 1 (JVM 1) or host 2 (JVM 2) in the cluster.

0

>I need to start a new IntelliJ, open the same source code twice and connect to JVM 1 from the 1st Intellij, and connect to the 2nd JVM from the 2nd Intellij.

What run configuration do you use? And how do you launch the remote JVMs on remote servers? Are they launched in debug mode?

>An Eclipse instance can conect to multiply hosts (JVMs) parallelly via the multiply debug hosts and ports and stop at the breakpoint. It really does not matter whether the request was forwarded to host 1 (JVM 1) or host 2 (JVM 2) in the cluster.

As noted, you can do the same in IntelliJ IDEA. See the Host and Port options:

For example to connect with the above host and port, the remove JVM must be started with 

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

if you use JDK version 8 or less, and the 

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

if you use JDK version 9 or newer.

0

Thx for the response. Maybe it is not clear, how I described the situation.

You are correct. I can debug a server the way you described. That works like the charm.

But my use case is not like this. I wanna debug an application deployed to a cluster:

 

                   |- server 1 (host: 10.10.10.10, debug port: 5001) <- IntelliJ A instance
request -> proxy --+
                   |- server 2 (host: 20.20.20.20, debug port: 5001) <- IntelliJ B instance

 

I am trying to describe the situation in a different way:

  • Sometimes the request goes to server 1, sometimes to server 2.
  • Server 1 and server 2 run on separate host machines.
  • Because a cluster is distributed system, the same Java application runs on each server, same source code.
  • One IntelliJ instance can ONLY connect to ONE host to remote debug the app (as you described in the previous post).
  • So If I have 2 servers in the cluster and wanna catch all requests then I need to lunch a 2nd IntelliJ to debug the 2nd server

If I have 4 machines in the cluster, then I need to run 4 IntelliJ.

 

 

0

>So If I have 2 servers in the cluster and wanna catch all requests then I need to lunch a 2nd IntelliJ to debug the 2nd server

No, I do not understand still sorry. In one project you can create several Remote Debug configurations in which you specify different host to connect to. Then you launch all these run configurations in a single project. Have you tried this? What is not working with this approach?

1

No, I have not tried.

It seems that this is the solution ;)

0

Your last comment solved the issue.

I do not know why, but I completely ignored that I can create multiply remote debug configurations in the project.

thx

 

0

Glad to hear! Thank you for the information.

0

请先登录再写评论。