This project is archived and is in readonly mode.
script/console execs irb, causes double process-launch and limits other impls
Reported by Charles Oliver Nutter | February 28th, 2009 @ 11:53 PM | in 3.0.6
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.
Comments and changes to this ticket
-
Charles Oliver Nutter February 28th, 2009 @ 11:58 PM
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.
-
Repository March 1st, 2009 @ 01:04 AM
- State changed from new to committed
(from [3b169cd693f45911ee71e26708fb9267811c8d83]) Speed up script/console by launching IRB directly.
[#2104 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
JasonKing March 2nd, 2009 @ 01:38 AM
Fix for the bug iffy mentions here: http://github.com/rails/rails/co...
-
CancelProfileIsBroken March 2nd, 2009 @ 01:41 AM
- Assigned user set to Jeremy Kemper
- State changed from committed to open
- Milestone cleared.
-
Repository March 2nd, 2009 @ 03:04 AM
(from [04fdb6eccb3a49b26bdbf779031f427da23a8bb4]) Revert "Speed up script/console by launching IRB directly."
[#2104 state:open]
This reverts commit 3b169cd693f45911ee71e26708fb9267811c8d83. http://github.com/rails/rails/co...
-
Charles Oliver Nutter March 3rd, 2009 @ 02:43 PM
I noticed the whole commit was reverted, even though a fix was proposed. Is there something else wrong with the change?
-
Jeremy Kemper March 3rd, 2009 @ 04:45 PM
The fix doesn't work. The environment has already been loaded by boot.rb at that point.
-
JasonKing March 3rd, 2009 @ 10:01 PM
Umm, my fix does work, it moves the command line arg parsing into railties/bin/console before the boot is loaded.
-
Jeremy Kemper March 8th, 2009 @ 08:32 PM
- 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. -
Charles Oliver Nutter March 13th, 2009 @ 01:18 PM
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.
-
buddy12lbcat May 16th, 2009 @ 11:28 AM
- 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.
-
buddy12lbcat May 16th, 2009 @ 07:07 PM
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. :)
-
buddy12lbcat May 16th, 2009 @ 07:11 PM
sorry looks like lighthouse monkeyed with my post. #1 should say: symlink /usr/local/ruby/bin -> /usr/local/ruby/1.9.1-p129/bin
-
buddy12lbcat May 16th, 2009 @ 08:07 PM
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.
-
Jeremy Kemper June 17th, 2010 @ 06:48 PM
- Milestone cleared.
-
Jeremy Kemper August 30th, 2010 @ 04:10 AM
- Milestone cleared.
- Importance changed from to Medium
-
Charles Oliver Nutter November 24th, 2010 @ 07:47 AM
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.
-
Charles Oliver Nutter November 24th, 2010 @ 07:34 PM
Also, to make it sound less snarky...I'd happily work with someone to get an acceptable patch put together.
-
Jason King November 24th, 2010 @ 08:27 PM
I haven't really begun digging around in Rails3 yet, but I'm pretty sure your benchmarks should be including
config/application.rb
notconfig/boot.rb
. I think you'll get much more similar times then becauseboot.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. -
Santiago Pastorino February 27th, 2011 @ 03:15 AM
- Milestone changed from 3.0.5 to 3.0.6
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2104 script/console execs irb, causes double process-launch and limits other impls [#2104 state:committed]
- 2104 script/console execs irb, causes double process-launch and limits other impls [#2104 state:open]
- 2091 [PATCH] I want script/console to invoke used Ruby's irb. This is being pursued with a slightly different patch on ...
- 2625 Rails should exec 'irb' from ruby bin directory instead of PATH Related ticket: #2104 - which proved to have unwanted sid...