Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to improve jRuby load time?

I have to wait quite long time (comparing to my friends machines) for executing scripts on jRuby, especially when I'm running rake tasks or tests. I've tried jRuby version 1.3.1 and 1.4.1 with and without ruby-debug gem and the same problem occurred in each configuration.

The question is simple: Is there any way to improve jRuby load process? ..or have I something wrong with my jvm configuration or jRuby installation (I'm using jRuby via rvm - ruby version manager)?

like image 227
luacassus Avatar asked Feb 08 '10 19:02

luacassus


2 Answers

There are a couple of things you could try:

  • use the very latest and greatest version of JRuby (due to the extensive testsuites, even the bleeding edge git master branch is usually pretty stable), they are constantly working on startup time
  • choose your JVM wisely, Oracle JRockit for example is geared towards servers and thus startup performance is not a concern (those apps are only restarted once every couple of years anyway), Sun has mainly neglected the desktop for the last ten years or so, but has gotten consistently better since 1.6u12 (try the recently released 1.6u18) and also in 1.7. IBM's J9 is also said to be pretty lightweight.
  • try nailgun, which is a project that keeps a JVM running as a daemon in the background (there is builtin support in JRuby, try running your scripts with jruby --ng)
  • just don't use JRuby for unit tests and rake tasks: the ThoughtWorks Mingle team, for example uses MRI for unit tests, rake tasks and development and JRuby for integration tests, regression tests and production. (This obviously only works if you don't use any Java libraries in your rake tasks and tests.)

However, tests and scripts are the worst case scenario for JRuby. The JRuby runtime alone is already pretty heavy, much heavier than MRI. Just loading the entire beast from disk into RAM can already take longer than running the same script in MRI. And we haven't even added the startup time for the JVM yet!

like image 118
Jörg W Mittag Avatar answered Oct 06 '22 10:10

Jörg W Mittag


Also, make sure that you run JVM in client mode (assuming that you're using Sun's JVM), since this mode provides faster startup and better overall performance for things like test suites. JRuby by default should use JVM in client mode, but this depends on the system and your JVM settings, etc. To verify that you're using client JVM, invoke jruby -v and you should see something like this

Java HotSpot(TM) *Client* VM 1.6.0_18

Update: Take a look at Charles' blog post with tips to improve startup: http://blog.headius.com/2010/03/jruby-startup-time-tips.html

like image 36
Vladimir Sizikov Avatar answered Oct 06 '22 11:10

Vladimir Sizikov