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



Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

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


About Jim ...


Click **here**
to try out MailWrench;
a command-line SMTP /
SMTPS (Google Gmail)
mailer for Windows.


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

A Review of Kevin Mitnick's Book Ghost in the Wires

Spellbound by Web Programming

Backlinks to my Blog Posts

Play MP3 Files with Python on Windows


Random Posts

Throwaway Software: HangUp

Taking Shape

Flirting with Forth

Generating Primes with XSLT

PHP, Transparent GIF's, and Web Tracking

Internet Protocols and Rhino JavaScript

Extracting URL Addresses from Text in C

A Command Line Scheduler

A Scrolling Banner using Canvas and JavaScript

Pi Day Meets the HTML5 Canvas


Full List of Posts

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


Recent Posts from my Other Blog

Remembering Dr. San Guinary

Why Some Web Sites will go Dark on Jan 18th

SNL Superhero Skit

More Ruby Games

My Ruby Game Challenge Entry

Steal this Bookmarklet

Nerd Toys

Learn New Jargon, You Must

Spot the Wiebe

Tech Magazine Glory Days

Book Review : Paull Allen - Idea Man

A 90's Experiment in Online Systems - The U.S. West CommunityLink Service