Jython, Python, other stuff.

Wednesday, May 23, 2007

Playing with nailgun

From following the JRuby development list I found NailGun which is described on the website:

NailGun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead.


NailGun runs as a server that listens on port 2113 by default, and takes requests from the ng client, which is written in C. Note that no attempt has been made to make this secure (so beware). Since I use Jython from the command line fairly often for testing and for inspecting Java libraries, and the JVM startup time is an annoyance, I thought I'd give it a try. I set up a script for launching NailGun with the Jython options:


#!/bin/sh
JYTHON_HOME=/Users/frank/src/jython/2.3/dist
JYTHON_JAVA_ARGS="-classpath $JYTHON_HOME/jython.jar:$CLASSPATH"
$JAVA_HOME/bin/java -server $JYTHON_JAVA_ARGS -Dpython.home=$JYTHON_HOME \
com.martiansoftware.nailgun.NGServer


And a launcher for jython that I called ngjy:


#!/bin/sh
ng org.python.util.jython "$@"


So a simple test shows some promise:

[frank@dhcp239-29 bin]$ time jython23 -c 'print "hello"'
hello

real 0m0.961s
user 0m0.845s
sys 0m0.082s
[frank@dhcp239-29 bin]$ time ngjy -c 'print "hello"'
hello

real 0m0.179s
user 0m0.002s
sys 0m0.009s
[frank@dhcp239-29 bin]$ time python -c 'print "hello"'
hello

real 0m0.052s
user 0m0.015s
sys 0m0.034s


Very cool! Though an unfair test, it is pretty cool that Jython can be made to out-perform Python on the command line.

1 comments:

Michael Neale said...

Very handy. I wish more apps could share a JVM like this.