Tips For Decreasing JRuby Startup
Charles Nutter has posted a blog of ‘JRuby Startup Time Tips,’ for anyone who is frustrated by slow startup times of JRuby implementations. Nutter admits that some of the bottleneck is JRuby’s fault, but blames the majority of the JRuby lag on configuration issues. He proposes several ways to combat this:
Make sure you’re running the client JVM – the ‘server’ backend takes a lot longer to compile and uses more resources during compile time.
Regenerate the JVM’s shared archive – the Class Data Sharing feature of the HotSpot JVM loads all the common Java Development Kit classes as a single archive into a shared memory location. Nutter provides a short tutorial on how to force your system to generate this useful shared archive.
Delay or disable JRuby’s JIT, as the JIT has been known to slow execution during short runs.
Avoid spawning “sub-rubies” – they may have some positive effects, but there’s always a cost for starting up JRuby instances.
Do less at startup – an ambiguous tip, but Nutter takes pains to explain why it’s advisable to leave the heavy processing until the application window and server have ‘warmed up.’
Try using the Nailgun library and client-side tool for small JRuby command-line invocations.
Play around with JVM flags, especially heap-sizing and GC flags.
Please see Nutter’s blog post for full details on each of the above points.