May 18

Eclipse Memory Manager Plugin

Posted by James Netherton | Sunday 18 May 2008 12:09 PM | In Java

I thought I'd mention this as it ties in quite nicely with my previous post.

Currently in incubation phase, Eclipse has a memory manager plugin which can analyse and provide some nice graphs and statistics from Java heap dumps.

The plugin can be downloaded here. There is an additional dependency on the BIRT charting and reporting plugin. Instructions for installing this are here.

Once everything is installed you can begin heap analysis. Use the jmap utility to create a heap dump file from a running JVM instance. You'll need the JVM process ID in order to do this.

Open up a command prompt or terminal session and execute the command below. Be warned that the size of the file produced can be quite large (over 100Mb).

jmap -dump:format=b,file=heapdump.hprof <process id>

From eclipse you can use the memory manager to open up and analyse the dump file.

Java 1.6 includes a simpler heap analysis tool named jhat. To analyse the heap dump we obtained from jmap, execute the following command:

jhat heapdump.hprof

Now point your web browser at http://localhost:7000 to see view the heap analysis results.

All of this may be useful if you're experiencing the Java OutofMemory exception. You can set the JVM parameter -XX:+HeapDumpOnOutOfMemoryError to dump the heap on out of memory exceptions.

 

May 16

JVM Monitoring Tools For ColdFusion

Posted by James Netherton | Friday 16 May 2008 11:29 AM | In ColdFusion,Java

I've been experimenting with JVM monitoring tools out of curiosity for what impact some applications have on memory and CPU usage. Here is a brief rundown on some of the tools that I used. All of these tools should be included within the bin directory of whatever JDK distribution you are using, providing the Java version is 1.5 or greater.

You may read this post and wonder why I bothered to research any of this, seeing as ColdFusion now has built in monitoring and profiling tools, together with many third party alternatives. Those tools are all good at providing a relatively high level of detail, showing what's going on inside of the application server but the tools outlined below can offer a more granular level of detail.

jps

Some of the tools require an argument to specify the id of the JVM that you want to interrogate, jps can be used to retrieve this id:

jps localhost

358 Jps
268

Other tools require that you pass an argument for the JVM process ID. This information can be easily obtained by using Task Manager, Activity Monitor, top, ps or whatever your tool of choice is for your environment.

JConsole

JConsole is a graphical tool that displays the current state of the JVM in terms of memory usage, thread usage and classes loaded. There are a couple of other items such as MBean management, but that's outside the scope of this post.

To start JConsole you need to the process ID of the JVM. I'm going to use the PID of JRun (2219) which of course is my ColdFusion JVM instance:

jconsole 2219

You'll then see graphs representing the current JVM memory usage. Execute some CF pages or fire up an application and you should see the memory graphs rise and fall as memory is allocated and garbage is collected. You can even force garbage collection by clicking the 'Perform GC' button.

jstack

jstack produces a stack trace dump of all threads within the JVM.

jstack 2219

Note that the output is very verbose so it's probably better to pipe the output to a file.

jmap

jmap can be quite useful to gather details about JVM memory details. For example, you can view heap statistics relating to number of objects loaded and the amount of memory allocated. Again, it's best to pipe the output to a text file:

jmap -histo 2219 > heap_stats.txt

jstat

jstat displays performance statistics for a JVM instance. The tool requires the id of the target JVM to be passed as a command line argument. You can also set the data refresh rate by specifying a value in milliseconds. The example below outputs a summary of garbage collection statistics every 5 seconds:

jstat -gcutil 1700 5000

There a many different switches that can be used to obtain different monitoring statistics. The Sun jstat web page has an overview of these options.

Some other tools that I looked at:

visualgc - similar in some ways to JConsole but focuses on memory and garbage collection statistics.

profiler4j - I couldn't get this working with JRun.

Eclipse Profiler - I got the Eclipse plugin installed ok but JRun choked whenever I tried to start ColdFusion after adding the specified profiler arguments into the jvm.config file. I only tried this with CF 8 so it may work with CF 7 and Java 1.4.2.

JRockit Mission Control - A product from BEA. It has been used to good effect in the past to find memory leaks in ColdFusion:

Mike Schierberl - ColdFusion Memory Leaks

Jason Sheedy - Cold Fusion Memory Leak

I got bored of trying to hunt down a free version of JRockit on the BEA website, but this tool can potentially offer some nice insights into what's happening under the hood of an application.

 

May 24

Quercus: PHP on Java!

Posted by James Netherton | Thursday 24 May 2007 9:13 PM | In PHP,Java

That's right, thanks to Caucho, you can run PHP scripts on the Java platform! It uses the Resin application server to compile PHP scripts down into Java bytecode.

Read all about it here. Some of the highlights are:

- Applications can take advantage of features like connection pooling, distributed sessions, load balancing, and proxy caching

- PHP applications can choose to use Java libraries and technologies like JMS, EJB, SOA frameworks, Hibernate, and Spring

- Quercus claims to outperform mod_php by about 4x some applications

- Make use of Java profilers to get in-depth information about the PHP application performance

- Write PHP extensions in Java

It works very nicely indeed. I had Drupal 4.7 up and running with almost zero fuss. I had to remove a particular PEAR library dependency for a module that I wrote. I'm pretty sure I could replace this with a custom Java PHP extension though.

As Resin is a Java application server, you can also run ColdFusion! I deployed CF in WAR form and so far, it all seems to be 100% working. I've got blogcfc and a couple of other applications working.

Hopefully I'll post some more after I've had a chance to experiment further.

 

May 03

XML based frameworks harmful?

Posted by James Netherton | Thursday 03 May 2007 9:26 PM | In Programming,Java

There has been some debate recently on the merits of using XML as a means of framework configuration.

I think XML has both positive and negative aspects to it. I came across this interesting blog post:

XML-based J2EE frameworks considered harmful

There are some interesting points in there, some only relevant to Java / J2EE but others cross over into ColdFusion.