Nailgun is Cool (February 13, 2005)

I've been checking out Marty Lamb's Nailgun project, which is a Java server running classes, executed by a small command-line client in C, using a custom communication protocol. The C client, of course, starts up immediately, and the cost of starting the JVM is taken up when the Nailgun server is first launched. This means that classes you execute (called "Nails") through Nailgun run much faster than if launched directly as they would from the java command-line.

I got to use this just in the last week, when I needed to convert BMP files to JPEG. The document I'm writing has to use JPEGs for images, but the original document had over 100 BMPs. So I had to convert them. The second problem was that I captured new images as screenshots, and, in my version of MS Paint, I can't save images as JPEGs, so I needed to save them and convert them, too. I need to focus on the document itself, so didn't want to look for some image-manipulation tool. A quick search found a blog by Chet Haase on image conversion. The utility he wrote, JpegConverter, converts all BMP files in a directory to JPEGs, using Java's imaging libraries.

Putting two and two together, I installed JpegConverter as a Nail, then wrote a batch script to run the Nailgun client on the utility. So typing


There's some other blog I will write with my (unrequested) opinions on Sun's stewardship of Java, but one point I can make here is it's too bad this wasn't available, like, 10 years ago. There is one very small C program to write, which I imagine is pretty portable, and suddenly you can use Java for all sorts of little utilities that wouldn't be worth it if you had to absorb the cost of the JVM launch. And what is good about this is that you get the memory protection, garbage collection and etc. of Java with the full reach of the Java API.

I'm hoping that Nailgun takes off. I sent Marty some ideas that would be, for me anyway, useful extensions. One is if there were an easy way to add NG-extensions to the Windows (or equivalent *nix) Explorer context menus, then you could run Nails throughout the your desktop GUI. WinZip, for example, has a little context menu that appears on files it controls, so, for example, you can extract a ZIP file to it's current directory without launching the WinZip console. Why not use Java for similar tasks? There are endless command-line utilities people have already written for Java, it's just not terribly convenient, or fast, to use them.

My guess is there will always be a range of utilities that are just easier to write in C or a scripting language, but pulling the Java API into the day-to-day world benefits everyone. Because apart from memory management, bounded arrays and all that good stuff, we have the other cool things about the language: dynamic reloading of classes through custom classloaders, multi-threading, security managers, remote invocation, and APIs for everything under the (S)un. And those features in turn mean that one can develop utility software more quickly, and with greater expression, than with at least some alternatives. And the nature of packaging and API interweaving means we can build more powerful utilities on top of simpler utilities, gradually working our way up the food chain.

Another idea is that if the server could be written using the Servlet API, using it's own protocol (or HTTP as an alternative), then we'd have the full range of web-containers, including their caching, reload, and management functions, to manage Nails. One idea I'll send to Marty.

And last--why not write adaptors to bring in the full set of JVM-based "scripting" languages? See how close we can get JRuby, Jython, Beanshell and etc. to match their *nix counterparts in common everyday use.

So, check out Nailgun. If you have written Java utilities in the past, try them out as Nails, and send Marty feedback. Maybe we can get a JAR of the most useful ones as a sort of Java performance pack. And maybe Sun will have some interest in backing it as a semi-standard approach to rapid execution of simple utility software in Java. One can only hope.

You can comment on this on the jRoller Website site, the the host for the blog entry above.