How to improve jRuby load time?

2020-02-06 06:56发布

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)?

4条回答
闹够了就滚
2楼-- · 2020-02-06 07:11

spork might help, if its unit tests you want to improve time on.

查看更多
神经病院院长
3楼-- · 2020-02-06 07:14

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!

查看更多
太酷不给撩
4楼-- · 2020-02-06 07:16

JRuby now has a --dev flag which combines many speedy options. I ran my model tests on Rails 5 and JRuby 9.1.7.0 with over 80% improvement!

$ time rspec spec/models
Finished in 2.85 seconds (files took 10.63 seconds to load)
86 examples, 0 failures

rspec spec/models  57.79s user 1.14s system 288% cpu 20.425 total


$ time JRUBY_OPTS=--dev rspec spec/models
Finished in 1.4 seconds (files took 4.15 seconds to load)
86 examples, 0 failures

JRUBY_OPTS=--dev rspec spec/models  11.51s user 0.48s system 139% cpu 8.600 total

Don't want to type all of this? Create a Makefile! You can add -G to include bundle exec

# Makefile
tests:
    JRUBY_OPTS='--dev -G' rspec

Then simply run

$ make tests

source: https://github.com/jruby/jruby/wiki/Improving-startup-time

查看更多
【Aperson】
5楼-- · 2020-02-06 07:23

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

查看更多
登录 后发表回答