Rails app on JRuby 1.7 in Nailgun mode does not start

别说谁变了你拦得住时间么 提交于 2019-12-23 07:27:30

问题


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.


回答1:


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?



来源:https://stackoverflow.com/questions/14213679/rails-app-on-jruby-1-7-in-nailgun-mode-does-not-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!