16

I'm pretty new to the whole JRuby world. I'm using RSpec on a pretty big test suite. I'd like to be able to run the specs frequently but the JVM takes so long to startup it's becoming a real time drain.

Is there a way to keep the JVM running? or a way to get specs to run faster with JRuby?

user229044
  • 232,980
  • 40
  • 330
  • 338
jpoz
  • 2,257
  • 1
  • 23
  • 29

1 Answers1

21

There are two things you could look into:

  1. Run a nailgun server and send spec runs to it. jruby --ng-server & and then jruby --ng -S spec or jruby --ng -S rake

  2. Use spork. http://www.ruby-forum.com/topic/190163 I hear that Roger Pack has a version that may work with JRuby. http://github.com/rdp/spork

zishe
  • 10,665
  • 12
  • 64
  • 103
Nick Sieger
  • 3,315
  • 20
  • 14
  • If I use a nailgun server for my specs it takes ~23 seconds and just running them with rake spec takes ~8 seconds. I must be doing something wrong. Also I wasn't able to get spork to work either. Gave an error about Fork not being supported on my platform. I haven't tried Roger Pack's version though. – jacklin Nov 08 '11 at 19:50
  • 1
    Try the same tasks a few times. My initial load time was 30 s just to run 'jruby --ng -S gem list' but approached < 1 s after 10 runs. The JIT compiler along with the OS caches/buffers should start to speed things up (esp. those w/o ssds). Also be sure to use the --server JVM along with the other standard GC flags. Watch memory usage, cpu and i/o to determine the bottleneck (if any). HTH. –  Nov 14 '11 at 19:03
  • Agreed, spork and nailgun together in my project brought my single-test time from 30 to 5 seconds. I have a handy helper script to run rspec with spork and nailgun, only when they are running, in case you are interested: http://ylan.segal-family.com/blog/2012/10/02/faster-rspec-jruby/ – Ylan S Oct 03 '12 at 04:11
  • @YlanS I have tried with your blog post, but most that you have explained is to use spork with nail gun and that solves the problem. What spork version did you use, as I am having problems doing the same :/ if you could help me – Aleks Sep 28 '13 at 16:17
  • @Aleks I am currently using spork 0.9.2. What sort of problems are you having? – Ylan S Sep 29 '13 at 17:05
  • thank you. At the end I was able to solve a problem. almost the same way as it is said. I will open a separate question for spork and nailgun and answer it by myself so other can see it. thanks for giving an assistance – Aleks Oct 01 '13 at 22:01