Jul 29, 2011

High-speed start-up Jython/Clojure by GroovyServ

GroovyServ:
https://github.com/kobo/groovyserv

GroovyServ made a start-up time of the invocation of Groovy script very quick. However, it can be used not only for Groovy but for all JVM languages, e.g. Scala, Jython and Clojure, etc.

On Linux, when setting the following aliases, You can enjoy the power of GroovyServ for Jython:
  1. alias gython="groovyclient -cp /tmp/jython.jar -e 'import org.python.util.jython; jython.main(args)' --"  
  1. $ time jython -c "print('Hello')"  
  2. Hello  
  3.   
  4. real    0m2.503s  
  5. user    0m2.891s  
  6. sys     0m0.431s  
  7.   
  8. $ time jython -c "print('Hello')"  
  9. Hello  
  10.   
  11. real    0m2.613s  
  12. user    0m2.889s  
  13. sys     0m0.435s  
  14.   
  15. $ time gython -c "print('Hello')"  
  16. Hello  
  17.   
  18. real    0m0.959s  
  19. user    0m0.001s  
  20. sys     0m0.003s  
  21.   
  22. $ time gython -c "print('Hello')"  
  23. Hello  
  24.   
  25. real    0m1.156s  
  26. user    0m0.001s  
  27. sys     0m0.003s  

Gython(Jython + GroovyServ) is faster by one second than normal Jython. In the above way, the overhead which groovyclient passes the classpath of the additional jython.jar to groovyserver at each invocation is so large. You can do it still faster by starting groovyserver with CLASSPATH environment variable which has jython.jar.

  1. $ alias gython="groovyclient -e 'import org.python.util.jython; jython.main(args)' --"  
  2. $ export CLASSPATH=/tmp/jython.jar  
  3. $ groovyserver -r  
  1. $ time gython -c "print('Hello')"  
  2. Hello  
  3.   
  4. real    0m0.909s  
  5. user    0m0.001s  
  6. sys     0m0.002s  
  7.   
  8. $ time gython -c "print('Hello')"  
  9. Hello  
  10.   
  11. real    0m0.076s  
  12. user    0m0.001s  
  13. sys     0m0.003s  
  14.   
  15. $ time gython -c "print('Hello')"  
  16. Hello  
  17.   
  18. real    0m0.045s  
  19. user    0m0.001s  
  20. sys     0m0.003s  
Yeah!

Notice 1: I can't assure that a testing framework or a complex library works well. Do it by your self-responsibility ;-)

Notice 2: If your OS is Windows, use Groovy and GroovyServ which are installed from Zip archives. I experienced a trouble by using them of Windows-installer of version 1.8.0.

Examples in my .bashrc

  1. alias glojureserver="env CLASSPATH=/usr/local/Cellar/clojure/1.2.0/clojure.jar groovyserver"  
  2. alias glojure="dgroovyclient -e 'import clojure.main;main.main(args)' --"  
  3. alias gythonserver="env CLASSPATH=/usr/local/Cellar/jython/2.5.2/libexec/jython.jar groovyserver"  
  4. alias gython="groovyclient -e 'import org.python.util.jython; jython.main(args)' --"  
  5. alias jvmserver="env CLASSPATH=/usr/local/Cellar/jython/2.5.2/libexec/jython.jar:/usr/local/Cellar/clojure/1.2.0/clojure.jar groovyserver"  
Usage:
  1. $ glojureserver -r -v  
  2. Groovy command path: /usr/local/bin/groovy (found at PATH)  
  3. GroovyServ home directory: /usr/local/Cellar/groovyserv/0.7/libexec  
  4. Original classpath: /usr/local/Cellar/clojure/1.2.0/clojure.jar  
  5. GroovyServ default classpath: /usr/local/Cellar/clojure/1.2.0/clojure.jar:/usr/local/Cellar/groovyserv/0.7/libexec/lib/*  
  6. Killed groovyserver of 56789(1961)  
  7. Restarting groovyserver  
  8. Starting....  
  9. groovyserver 59802(1961) is successfully started  
  10.   
  11. $ time glojure -e "(println 'Hello)"  
  12. Hello  
  13.   
  14. real    0m0.867s  
  15. user    0m0.001s  
  16. sys     0m0.004s  
  17.   
  18. $ time glojure -e "(println 'Hello)"  
  19. Hello  
  20.   
  21. real    0m0.053s  
  22. user    0m0.001s  
  23. sys     0m0.004s  
  24.   
  25. $ gythonserver -r -v  
  26. Groovy command path: /usr/local/bin/groovy (found at PATH)  
  27. GroovyServ home directory: /usr/local/Cellar/groovyserv/0.7/libexec  
  28. Original classpath: /usr/local/Cellar/jython/2.5.2/libexec/jython.jar  
  29. GroovyServ default classpath: /usr/local/Cellar/jython/2.5.2/libexec/jython.jar:/usr/local/Cellar/groovyserv/0.7/libexec/lib/*  
  30. Killed groovyserver of 59802(1961)  
  31. Restarting groovyserver  
  32. Starting....  
  33. groovyserver 59938(1961) is successfully started  
  34.   
  35. $ time gython -c "print('Hello')"  
  36. Hello  
  37.   
  38. real    0m1.540s  
  39. user    0m0.001s  
  40. sys     0m0.004s  
  41.   
  42. $ time gython -c "print('Hello')"  
  43. Hello  
  44.   
  45. real    0m0.108s  
  46. user    0m0.001s  
  47. sys     0m0.003s  
  48.   
  49. $ time gython -c "print('Hello')"  
  50. Hello  
  51.   
  52. real    0m0.057s  
  53. user    0m0.001s  
  54. sys     0m0.004s