Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails app on JRuby 1.7 in Nailgun mode does not start

I installed JRuby 1.7.2 in RVM, created a gemset, executed bundle install. Now, I run this:

Term 1:

[lzap@lzapx my_app]$ bundle exec jruby --ng-serv
NGServer started on all interfaces, port 2113.

Term 2:

[lzap@lzapx my_app]$ JRUBY_OPTS="--1.9 --ng" bundle exec rails s

The issue is nothing happens, on both sides the terminals do not print anything, it just hangs forever. Top does not show any java/jruby processes working.

If I try to start the application without --ng, it works okay. What is the issue? Bundler?

Firewall is disabled of course.

like image 948
lzap Avatar asked Jan 08 '13 11:01

lzap


1 Answers

One Nailgun Server

It's possible to generate a binstub for rails …

$ bundle binstubs rails

… and edit it to set the JRUBY_OPTS.

ENV['JRUBY_OPTS'] = '--1.9 --ng --nailgun-port 2113'
load Gem.bin_path('rails', 'rails')

This way only the bundler-wrapped portion of the client is executed in the bundler-wrapped nailgun server.

Since nailgun doesn't propagate signals you might want to use a controller to stop it:

class RailsController < ApplicationController
  def stop
    Process.kill :INT, 0
  end
end

Benchmark:

$ time bin/rails -v  # modified
Rails 3.0.11

real    0m3.737s
user    0m6.579s
sys     0m0.223s

$ time bin/rails -v  # unmodified
Rails 3.0.11

real    0m5.547s
user    0m12.739s
sys     0m0.411s

$ time bundle exec rails -v
Rails 3.0.11

real    0m9.145s
user    0m20.708s
sys     0m0.682s

Two Nailgun Servers

A second 'non-bundle-exec'ed server could be used in theory. To avoid explicit restarts but allow killing (with two Ctrl-C presses) I'd suggest this loop:

$ while sleep 1; do jruby --ng-server 2112; done

The port for the second nailgun instance has to be specified in the outside client:

$ JRUBY_OPTS='--1.9 --ng --nailgun-port 2112' bin/rails s

I didn't see a performance improvement and the output appearing in the 'wrong' console is annoying. But maybe this is faster on other systems. And someone else might see a way improve this approach?

like image 168
kunysch Avatar answered Nov 15 '22 21:11

kunysch