Jim Lawless' Blog


Speeding up JRuby with NailGun

Originally published on: Tue, 09 Mar 2010 00:27:59 +0000

NailGun is a Java-oriented protocol that is used to speed up Java command-line applications. A NailGun server process must first be initiated that will listen for traffic on port 2113 by default.

The NailGun client program (ng) is then used to specify Java classnames to the NailGun server which executes those classes in its already-running JVM. The standard input/output channels are redirected to those of the ng client instead of the ones tied to the running JVM.

The benefit is that each command-line task can avoid the load-time of a JVM for each invocation; a single JVM is shared among multiple requests.

For more information on using NailGun with Java programs, please see this link:

http://martiansoftware.com/nailgun/quickstart.html

The NailGun server and client were merged into the JRuby distribution as of version 1.3. No changes need to be made to JRuby code to allow them to execute with the packaged NailGun server.

To start the JRuby ng server enter the following at a command-prompt:


jruby --ng-server

You should see output similar to the following:


NGServer started on all interfaces, port 2113.

You can then invoke a JRuby script by entering the following at a command-prompt in a different console window:


jruby --ng scriptname.rb

...where scriptname.rb is the name of the JRuby script that you'd like to execute.

I tried the above procedures with the JPoppy.rb script shown here: http://www.mailsend-online.com/blog?p=73.

I encountered some sort of odd error when I tried this the first time on Windows XP from the JRuby/ng client. It crashed due to an invalid instruction or something along those lines. This also crashed the running ng server process, showing a Java stack trace on the ng process's console window.

I was not able to recreate the error situation after several attempts. I even tried to break out of the ng client side prematurely to see if the ng server would again throw an unhandled exception, but I could not cause an exception to occur.

I was going to start using NailGun by simply writing some Java code to use it. I changed my mind once I saw how simple it was to use NailGun with JRuby.

The NailGun homepage states that the product should be considered to be an alpha release. As such, it should not be used for production purposes.

I would like to understand more about how concurrent ng clients using the same scripts ( or classes ) are handled by a single instance of the NailGun server. I hope to get around to those experiments in the near future.

Unless otherwise noted, all code and text entries are Copyright ©2010 by James K. Lawless

del_icio_us Save to del.icio.us
stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks



Previous post: JRuby as a Java Obfuscation Utility
Next post:BBS Fun in the Eighties


Search this Blog (and site)

Search this Site with PicoSearch


Subscribe to this Blog

 Subscribe!


Contact Me

Email: jimbo@radiks.net


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

Mad Schemes : Learning Lisp via SICP

Auto Save Clipboard Images Redux

Extending SpiderMonkey JavaScript on Windows

Rhino JavaScript to EXE with launch4j

Compiling Rhino JavaScript to Java

Directory Traversal in Rhino JavaScript

Taking Shape

We've Moved!


Popular Posts

A Command-Line MP3 Player for Windows

Auto Save Images from the Clipboard

Java in a Windows EXE with launch4j

An Interview with Tom Zimmer: Forth System Developer

Setting Windows Console Text Colors in C


Random Posts

Compiling Rhino JavaScript to Java

BPL: Batch Programming Language Interpreter

JRuby as a Java Obfuscation Utility

Scrolling GIF Banners with PerlMagick

CP/M Days

Scott Ballantyne: Blazin' Into Forth

Thwarting HTTP Referer Trackbacks

WSH2EXE part 2

Preventing Windows Screen-Saver Activation

Book Review : Using Google App Engine


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Blogroll

MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer