Question

I have a simple java application that gets jmx connection url, object name and attribute name as inputs and outputs attribute value. This application runs hundreds of times every minute and has strict running time limitations. Recently many corner cases appeared (converting milliseconds to seconds, folding a list, etc.) and recompiling and redistributing this application becomes tedious. So i've decided to switch to some scripting language with support for JMX.

I've tried groovy, jython and clojure and found that their initialization time is lengthy (around 0.9/1.2/3.5 for groovy/clojure/jython).

Is there anything with faster initialization speed or is there a way to decrease initialization time of these laguages without loading them from java?

Was it helpful?

Solution 2

I have found a solution that should work across all java scripting languages it is nailgun. It has the same principle as jerk and cake suggested in other answers but it runs arbitary java classes.

This blog post has a great instruction on how to run jython scripts with nailgun and i am sure it can be applied to other scripting languages.

OTHER TIPS

Nowawadays, jark seems to be a nice solution.

Write a clojure script like

(ns jarkserver)

(require '[clojure.tools.nrepl :as nrepl])

(defn -main
[& args]
(nrepl/start-server 9000)
(.join (Thread/currentThread)))

Start it with:

 lein run -m jarkserver

Then start a REPL with:

 jark repl

or run your clojure script with:

 jark <path_to_clojure_script>

or just execute some clojure code inline:

 jark -e "(+ 1 1)"

Edit: An easier way to start the Jark server would be:

jark -cp lib/*:lib/dev/*:* -p 9000 server start  

Apparently Cake (https://github.com/flatland/cake), for Clojure, includes a Clojure script launcher which uses an already-initialized JVM which runs in the background. You'll have to look up the details yourself, because I've never used it and don't know anything specific about it. But apparently it cuts way down on startup time.

Other options (I am not familiar with them):

Other avenues worth exploring (in decreasing promisingness) :

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top