Friday, June 12, 2009

Debugging Your Production JVM

I've been trying to debug an issue in our QA environment for the last few weeks and also to do a presentation next Wednesday to my JUG.

I found a free tool from dev.java.net called Visual VM https://visualvm.dev.java.net/

I found VisualVm to be very useful and has many features that go way beyond jconsole and has most of the features available in a commercial product. I especially like the threads view. I wish I could do remote profiling with VisualVm but I believe that feature is probably not too far in the future. The platform is extensible via a plug-in interface.

This other slide set has some good tuning info as well http://www.slideshare.net/Byungwook/jvm-performance-tunning-1154189

I just found this SlideShare from a JavaOne conference.
This should be a good reference for my 6/17 RJUG Presentation, although there's more to a presentation than just slides, some of them don't go into much detail.

Tuesday, June 9, 2009

Setting up a New Subversion Repository Server

Abstract
This will walk through the steps of creating and sharing a subversion repository. We're working on a virtual Windows XP instance because its almost always available and gets backed up regularly. I chose VisualSvn Server because it is almost zero configuration and it works nicely on XP, no mess no fuss. I also make use of TortoiseSVN for the task of initializing the repository, checking in and out so install TortoiseSVN right after installing VisualSvn Server. All Language Developers: No fear, VisualSvn Server is still a subversion server, no need to get Visual Studio, works with Java, *** its just a great Windows distribution that is easy to setup.

Background
We have a new development sub-project (finally) for which we can use Subversion to share/store the code base. My main project is called MASS and the new project will load natural gas production measurements (readings) from our new hand-held units via a web service.

1. Log into the Remote XP Server VM

2. Download and Install VisualSvn Server from http://www.visualsvn.com/server/. I found this article http://www.west-wind.com/presentations/subversion/ useful in making the decisions getting started. I chose SSL and Windows Authentication.

3. Configure the Repository
Use the SvnServer Admin tool available under "myComputer" > "Manage" > "Services" and "Applications".

4. Enable Repository Access
Right-click on "Repositories", select "Properties". This brings up a window with one tab labeled Security. Select the "Add" button to add user access. Select the "Locations..." button and select your active directory server as the authentication source, type the userId of a user and select "Check Names..." This should resolve the userId to a windows Domain user. By default this will give all the users entered here read/write access to any of the repositories created on this server. That works for me since our project owns the XP VM.

5. Create a Repository
Right-click on "Repositories" in the hierarchy and select "Create New Repository..." Name it what you like and select the checkbox "Create default structure (trunk, branches and tags)". After you select "OK", the status on the main admin screen should read "Total 1 repositories".

6. Right click on the new repository folder named "trunk" and select "New" and "Folder...". Name it "src" or something you are comfortable with.

7. Switch to your desktop and Create the Project root Folders
cd c:\
mkdir GAS
cd GAS
mkdir MASS
cd MASS

7. Check out the new folder from the repository
Open the file system explorer and navigate to the new project folder (MASS in my example). Right-click on the folder and select "TortoiseSVN", "Repo-browser", paste the URL of your new VisualSVN Server instance admin client, and select the newly created folder from the repository and select "Check out". This will be the basis for you to populate the rest of the repository with your existing code.

Friday, June 5, 2009

JVM Profiling and Optimization

Caveat: I'm really new at JVM profiling and memory leak troubleshooting so I'm making certain assumptions and taking certain steps to feel my way through the process.


TOOLS
I'm using a combination of tools and OS logging to get feedback from the JVM.

1. YourKit for Java (http://www.yourkit.com/)
YourKit is very easy to install against a WebLogic JVM and monitor via a remote PC desktop. It is free for developers contributing to non-commercial Open Source projects, with an established and active community and has a reasonable academic license fee. YourKit has a script that will generate the modifications needed to be made to the host JVM. This makes installation much easier.

2. Sun's VisualVM I am evaluating this as I write. I see much of the features available in YourKit here, however YourKit has really easy setup and nicer charting features. VisualVm seems to beat JConsole pretty handily. To use VisualVM to retrieve data from a remote application, the jstatd utility needs to be running on the remote JVM. All the tools need some kind of modification to either the remote server or remote JVM startup parameters.

Some of the blogs about VisualVm have yielded a few really handy commands, such as jps (find the PID of the Java Processes) and jstat (get status of JVM at PID). I also see mention of something from Sun called visualgc which is also available from Sun's dev.java.net. Some of these appear possibly to be orphan projects.

3. Java's JConsole (http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html)
Jconsole provides basic information about a profiled JVM (not as much and not presented as nicely as YourKit, but it is free) and requires more setup (see my post "Connecting to a Remote JConsole Session" for setup.

4. A series of custom logging scripts that essentially scrape Unix top or other unix admin commands for pulling out information about the running processes and logging that information to a format that can be easily put into Excel for charting and analysis.


Links:
http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp
http://www.slideshare.net/kensipe/debugging-your-production-jvm
https://visualvm.dev.java.net/

Enabling JMX on a JVM

This is necessary for many of the profiling options, such as allowing a remote JConsole session to connect to a JVM.

I've been profiling my QA WebLogic application because it's been really misbehaving the last two weeks. Sun's free swing app, jconsole, gives a bunch of insight into performance metrics such as memory, garbage collection and object counts.


  1. Enable your JVM to use JConsole

    The jconsole app is enabled via command line parameters that activate at startup. On weblogic you modify the file setDomainEnv.sh in the bin directory of your WL 'domain'. Add the following (Solaris/Unix):

    # Allow JConsole to view this JVM
    JC_JMX_ENAB="-Dcom.sun.management.jmxremote=true"

    # Allow remote access to JConsole at this port
    JC_JMX_PORT="-Dcom.sun.management.jmxremote.port=5097"

    # Don't require login
    JC_JMX_AUTH="-Dcom.sun.management.jmxremote.authenticate=false"

    # Don't require SSL
    JC_JMX_SSL="-Dcom.sun.management.jmxremote.ssl=false "

    JAVA_OPTIONS="${JAVA_OPTIONS} ${JC_JMX_ENAB} ${JC_JMX_PORT} ${JC_JMX_AUTH} ${JC_JMX_SSL}"

    export JAVA_OPTIONS


  2. Restart the WL Server instance or JVM

  3. Start a command line JConsole session on your desktop
    Do this by executing jconsole.exe from the bin directory of your JSDK installation.

  4. Connect to your remote server at the specified JMX port
    Select the 'Remote Process' radio button and enter the host server name and using the port (5097 in this example) in the form [hostname]:[port].


REFERENCES

  1. http://www.javapassion.com/handsonlabs/jconsole/index.html#Configure_a_simple_app
  2. http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html
  3. http://java.sun.com/javase/6/docs/technotes/tools/share/jconsole.html


SEE ALSO

  1. JStat http://java.sun.com/javase/6/docs/technotes/tools/share/jstat.html

XP Connecting to a Solaris Server via X11 XWindows

I'm working out the details of how to view the JConsole profiling information from my Windows XP desktop.

I began with the misconception, that unless one is running jconsole locally (e.g. on the same server) as the one the JVM is running, then the amount of jconsole information you can see is limited. From the Java documentation at Sun, you are led to believe that remote sessions are unable to access certain tabs.

Having busted that, I'm now left with some valuable info that I know will be useful later, so here it is.

HOW TO GET AN XWindows connection to a Solaris Server.

One requirement is to have an XWindows session running on XP.
The other is to enable X11 over SSH on the Solaris server.

I used Cygwin/X on the desktop. It's great and there's plenty of easy documentation on cygwin's web site to get you going here <http://www.javapassion.com/handsonlabs/jconsole/index.html#Configure_a_simple_app>.

On Solaris modify the file /etc/ssh/sshd_config. Enable X11 tunneling by finding the section labeled "X11 tunneling" and make it match the following:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

Finding the PID (Process Id) of a Windows XP Process

Open up the Windows Task Manager (Either press Ctrl+Alt+Del and select "Task Manger", or issue the command "taskmgr" from the command line).

Click on the “Processes” tab.

Select the “View" menu item and choose "Select Columns...”.

Check the "PID (Process Identifier)" checkbox and click the "OK" button

The process list will now show the PID of each running process.

There are a number of other properties you might like to show on the process list.

This is a hidden gem.

Followers