Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

script/console execs irb, causes double process-launch and limits other impls

#2104

Currently script/console (via railties/lib/commands/console.rb) launches the actual IRB session using exec and by default "irb". However this causes problems for many reasons:

  • Implementations may not have IRB installed as IRB; for example, in JRuby it's "jirb", and I have Ruby 1.9 installed as irb1.9.
  • For implementations with a slower process startup time, this penalizes them. JRuby has to start the JVM twice. On platforms or JVM versions with slow startup, this causes us to be doubly slow.
  • On platforms where exec doesn't actually replace the calling process, this cases two processes to be in memory rather than just the one. This affects JRuby and running any impls on Windows.

The odd thing is that it doesn't appear that the exec is actually necessary. I'm attaching a patch that simply launches IRB from within the same process. This resolves all issues I list above. It may not be perfect but it should be a good starting point.

FWIW, the reason it works at all in JRuby is because we have long had a hack in "exec" logic that if the command being executed is "irb" we force it to run in the same JVM. But it's buggy, and we'd like to be able to get rid of that.

Reported by Charles Oliver Nutter · February 28th, 2009 @ 11:53 PM

State: open
Milestone: 3.0.6
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: Medium

Activity

  1. Charles Oliver Nutter
    Charles Oliver Nutter

    I just noticed that the script/console script also requires config/boot, which means that the exec is also causing a second load of Rails and the application. So this fix would potentially improve the startup time of the console on all implementations.

    February 28th, 2009 @ 11:58 PM

  2. Repository
    Repository
    • State changed from new to committed

    (from [3b169cd693f45911ee71e26708fb9267811c8d83]) Speed up script/console by launching IRB directly.

    [#2104 script/console execs irb, causes double process-launch and limits other impls state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    March 1st, 2009 @ 01:04 AM

  3. JasonKing
  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • Assigned user set to Jeremy Kemper
    • State changed from committed to open
    • Milestone cleared.

    March 2nd, 2009 @ 01:41 AM

  5. Repository
    Repository

    (from [04fdb6eccb3a49b26bdbf779031f427da23a8bb4]) Revert "Speed up script/console by launching IRB directly."

    [#2104 script/console execs irb, causes double process-launch and limits other impls state:open]

    This reverts commit 3b169cd693f45911ee71e26708fb9267811c8d83. http://github.com/rails/rails/co...

    March 2nd, 2009 @ 03:04 AM

  6. Charles Oliver Nutter
    Charles Oliver Nutter

    I noticed the whole commit was reverted, even though a fix was proposed. Is there something else wrong with the change?

    March 3rd, 2009 @ 02:43 PM

  7. Jeremy Kemper
    Jeremy Kemper

    The fix doesn't work. The environment has already been loaded by boot.rb at that point.

    March 3rd, 2009 @ 04:45 PM

  8. JasonKing
    JasonKing

    Umm, my fix does work, it moves the command line arg parsing into railties/bin/console before the boot is loaded.

    March 3rd, 2009 @ 10:01 PM

  9. Jeremy Kemper
    Jeremy Kemper

    Sorry Jason, I misread your patch.

    March 3rd, 2009 @ 10:49 PM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 2.x

    Postponing this since existing apps' script/console will appear to work but load the wrong environment. Fixing it will require everyone to rake rails:update:scripts which hasn't been part of the 2.3 RC.

    March 8th, 2009 @ 08:32 PM

  11. Charles Oliver Nutter
    Charles Oliver Nutter

    Couldn't the new console behavior be added in a different file, and new script/console require that one instead? Then the old behavior would still work in existing apps and newly-generated apps would get the new behavior, starting up fastest, etc.

    I'd really like to see this get into 2.3.

    March 13th, 2009 @ 01:18 PM

  12. buddy12lbcat
    buddy12lbcat
    • Tag changed from console, irb, jruby to console, irb, jruby, ruby1.9

    hi, i wanted to add my 2 cents by saying that this issue should include the use of /usr/bin/env ruby sherbangs in multiple files. i need to be able to support a custom compiled ruby1.9 on production servers that use 1.8 system gems. unfortunately, console, dbconsole, and lots of other scripts use env to load (for me) the wrong ruby.

    i just returned from dhh and was inspired by his "have it your way" speech. in light of this, why can't we just have an optional RUBY_PATH constant that can be set explicitly if i need to. without it, the scripts do as expected, but if present, it just loads everything from that directory. this seems much cleaner and incurs less overhead than doing all manner of gyrations to "detect" ruby automagically.

    i guess i don't believe that convention over configuration means no explicit configuration at all. however implemented, it should be a clean one-line explicit statement.

    May 16th, 2009 @ 11:28 AM

  13. buddy12lbcat
    buddy12lbcat

    ok. so not to be a whiner without a solution, i've patched my rails to do the following:
    1) symlink /usr/local/ruby/bin -> /usr/local/ruby//bin
    2) replaced all /usr/bin/env ruby sherbangs with /usr/local/ruby/bin/ruby
    3) added RUBY_PATH = '/usr/local/ruby/bin' to boot.rb
    4) changed console.rb and other references to RUBY_PLATFORM to say irb = "#{RUBY_PATH}/irb" || RUBY_PLATFORM ...

    not sure if this is generalizeable to other systems, but it seems to take care of most of my issues and allows me to switch ruby versions with just the symlink. i kept the symlink off the usual paths so it doesn't screw with my production 1.8 gems/paths. at the very least this will give me experience maintaining my own rails patches via git clone/rebase. :)

    May 16th, 2009 @ 07:07 PM

  14. buddy12lbcat
    buddy12lbcat

    sorry looks like lighthouse monkeyed with my post. #1 Migrations will not run on a fresh database should say: symlink /usr/local/ruby/bin -> /usr/local/ruby/1.9.1-p129/bin

    May 16th, 2009 @ 07:11 PM

  15. buddy12lbcat
    buddy12lbcat

    ok. so maybe rails has done this before :) turns out that if you use rails -r /path/to/ruby it will reset all your shebangs. so don't need that. i have legacy code and don't run rails to create new projects at all so i missed that option. so that just leaves console using path/irb. i defer to the great oz that is rails core.

    May 16th, 2009 @ 08:07 PM

  16. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  17. Rohit Arondekar
    Rohit Arondekar

    Any updates to this ticket?

    June 17th, 2010 @ 07:11 AM

  18. Jeremy Kemper
  19. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • Importance changed from to Medium

    August 30th, 2010 @ 04:10 AM

  20. Jeremy Kemper
  21. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:33 AM

  22. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    November 8th, 2010 @ 01:48 AM

  23. Santiago Pastorino
  24. Charles Oliver Nutter
    Charles Oliver Nutter

    Any chance of getting this prioritized some day? JRuby itself starts up pretty fast, Rails less so...and with this double-booting it's almost unbearable.

    Here's a gist showing the differing times from starting up IRB alone, IRB with RubyGems (with a tweak in my env to speed it up), IRB with RubyGems and boot.rb, and the Rails 3 console. Compared to IRB alone, Rails 3's console takes an order of magnitude longer to start up, and compared to IRB + boot.rb, it's almost 2x, as you'd expect from double-initializing.

    https://gist.github.com/713286

    November 24th, 2010 @ 07:47 AM

  25. Charles Oliver Nutter
    Charles Oliver Nutter

    Also, to make it sound less snarky...I'd happily work with someone to get an acceptable patch put together.

    November 24th, 2010 @ 07:34 PM

  26. Jason King
    Jason King

    I haven't really begun digging around in Rails3 yet, but I'm pretty sure your benchmarks should be including config/application.rb not config/boot.rb. I think you'll get much more similar times then because boot.rb is only doing the Bundler setup now.

    You'll get more similar times because... I think your change has been included in Rails3 as part of their general improvements. Looking in railties/lib/rails/commands/console.rb I see IRB.start now.

    November 24th, 2010 @ 08:27 PM

  27. Santiago Pastorino
  28. Santiago Pastorino
    Santiago Pastorino
    • Milestone changed from 3.0.5 to 3.0.6

    February 27th, 2011 @ 03:15 AM