Tip #-3 How to Debug Clustered AppServer Instances

There used to be a big problem in trying to attach a debugger to a clustered server instance in Glassfish.  As of today (build 45), it is a snap to do it!

The problem was that a cluster config could only specify one debugging port.  This would work if you started one and only one server instance.  As soon as you tried to start a second instance it would try to use the same jdwp port and it would fail to launch.  It was (almost) impossible to debug 2 instances on the same machine at the same time.

The solution is to defer the actual port number selection.  I.e. the instance needs to choose its own port.  Each instance specifies a different port and, voila, problem solved.

Here is how to do it:

1. Enable debugging support for the cluster
We are using a cluster named c1.  First make sure that debugging is enabled for the cluster:

asadmin set c1-config.java-config.debug-enabled=true

2. Set a variable debugging port

The syntax is ugly.  Don't bother memorizing just do a get to see it, edit it and then do a set on the result like so: 

asadmin get c1-config.java-config.debug-options
c1-config.java-config.debug-options = -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009
asadmin set c1-config.java-config.debug-options="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT}"
Don't forget the double quotes, and no spaces around the equals sign!

 Another Tip:  asadmin get "\*" > afile is handy.  You can then grep for 'debug' in the file.  I use this technique all the time.  What human being wants to memorize this sort of crushing detail?

3. Set the instances' debugging ports

 In this case we have 2 instances, i1 and i2.  We will make the debugging ports 11111 and 22222 respectively:

GlassFish v2.x:

asadmin set i1.system-property.DEBUG_PORT=11111
i1.system-property.DEBUG_PORT = 11111
asadmin set i2.system-property.DEBUG_PORT=22222
i2.system-property.DEBUG_PORT = 22222

The above does NOT work in GlassFish 3.X.  Instead use the following commands:

asadmin create-system-properties --target i1 DEBUG_PORT=11111
asadmin create-system-properties --target i2 DEBUG_PORT=22222



That's it.  You're ready to debug multiple instances.



Comments:

Great Job, Byron.

This post brings about the powerful feature of "tokens" in GlassFish management!

Posted by Kedar on April 25, 2007 at 01:34 AM PDT #

This was helpful. Here is feedback on what I encountered following the steps.
  • For Step 2, I got Undefined variable DEBUG_PORT. Was using Solaris 10 and tcsh. Workaround was to turn off variable expansion of ${DEBUG_PORT} by using single quotes rather than double quotes to quote '-Xdebug ... ${DEBUG_PORT}' of step 2.
  • Server instances needed to be restarted after these changes are made.

Posted by Joe Fialli on June 25, 2007 at 06:31 AM PDT #

I agree with Joe. The shell always intercepts the CLI commands first :(

Posted by Kedar on June 25, 2007 at 06:37 AM PDT #

Really useful blog!. Thanks!

Posted by Venu on March 17, 2008 at 04:57 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

ByronNevins

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today