I just got my rails 2.3.8 app running on ruby 1.9.1. To get into the console, start the webserver, anything that initializes rails, takes 3 - 4 times longer in ruby 1.9 than in ruby 1.8.7. I'm using ruby version managers so I can easily switch between ruby 1.9 and ruby 1.8.7. The speed difference happens in both production and development. I want to use 1.9 because its must faster once everything is running, but the startup time is so bad the app is timing out on Heroku on the first request.
Any ideas why ruby 1.9 would be 3 - 4 times slower? I can't figure it out for the life of me.
Try using 1.9.2-head instead of 1.9.1. It is the recommended version for Rails 3, so you may have better luck. Rails 2.3.8 starts up very quick on 1.9.2-head from the tests I just ran locally (with Authlogic installed too, btw).
If you are using RVM, type the following:
rvm install 1.9.2-head
rvm use 1.9.2-head
Edit: I tried 1.9.1 p378 with the same app and the start up time took about 13 seconds compared to 5 seconds on 1.9.2-head. 1.9.2-rc1 is due out this month I believe, so that's good news :)
It's probably because ruby 1.9 uses gem_prelude (which gives you a large load path) instead of normal rubygems. Checkout the length of $: -- that gets searched once for each require, causing extra time
If you want it the old way, (upgrade to the latest version of rubygems and) run ruby --disable-gems
If you are on windows, take a look into my faster_require gem.
http://github.com/rdp/faster_require
Though I suppose, now that you mention it, it might help in 1.9 Linux. Maybe.
GL!
-rp
Related
I'm using RVM for managing environment, installed Ruby 1.9.2.p136 (i think its latest release.) and Rails 3, created gemsets and run bundler. everything working good so far
but;
Rails initalizes extremely slow when running commands, i.e. generate, destroy, rake etc.
Takes about 30-45 seconds to complete command. This will never happens if use Ruby Enterprise Edition or Ruby 1.8.7
Why this happens. Any thoughts?
Running on Ubuntu 10.10, RVM, Ruby 1.9.2, Rails 3
Thanks.
There is a thread about this on Rails-Core - http://groups.google.com/group/rubyonrails-core/browse_thread/thread/88519ef5a53088a1/c01ba447c6dc0de7?lnk=raot
To quote Yehuda Katz
"There are things that the C require code does in 1.9 that slow things down.
One such example is re-checking $LOAD_PATH to make sure it is all expanded
on every require. This is something that should be addressed by ruby-core.
I'll open a ticket on redmine if there isn't one already."
I am also experiencing this problem and a $LOAD_PATH issue seems like a potential cause. Lets hope it gets fixed soon.
Try to strace (on unix), dtruss (on mac) your command (might need to "sudo" though). It'll show you where the process is spending its time. Notice where it pauses. This is definitely not normal.
Looking to build a Rails 3 stack and trying to sort out Ruby versions.
I'm very interested in the concept of JVM, but not 100% sure if it even relates to Rails 3; meaning why not just do a deploy just for JVM if needed.
Then there's heroku saying there's a bug in Ruby 1.9.1, but they don't say what the bug is, if it's addressed by Ruby 1.9.2 -- or what will happen as a result of running Rails 3 on Ruby 1.8.6.
UPDATE: Found the bug heroku is indirectly linking to: "Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails 3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing."
Anyone have info/link on the subject?
Thanks!
If you're running on windows, my personal recommendation is go with JRuby. MRI (both 1.9.x and 1.8.x) has mountains of problems on windows, whether deploying to XP, Vista, or Windows 7. I don't develop on Windows often, but I do teach Rails classes, and that's my recommendation to Windows students now. Haven't had many issues with JRuby at all, aside from needing to use a different database driver (the jdbc gem versions). RVM doesn't work on windows, but you can use pik (https://github.com/vertiginous/pik) to achieve many of the same goals.
My advice is that if you're starting a new Rails 3 project you should definitely think about kicking it off using Ruby 1.9.2. Heroku supports multiple stacks with the default now being Bamboo (the one that supports 1.9.2 as well as REE). If you're worried about gem compatibility or something else then you can hedge your bets and use RVM and/or multiruby to run your test suite across multiple versions of ruby so you can deploy to either run time.
Personally I'm running a Rails 2 app on REE and a Rails 3 app on 1.9.2 and haven't had any problems.
If you're not deploying on Heroku and are setting up your own server then I would manage your Ruby versions using RVM on your production server so you can easily switch between versions if anything doesn't work.
In summary:
You can run Rails 2 and 3 apps on both REE and Ruby 1.9.2.
For me, no matter what rake task has been executed, it's at least 20 seconds. The time is too long.
My OS: windows xp, rails: 2.3.8, ruby: 1.8.7
UPDATE
Are there any ways of speeding up rake? Someone said upgrade to ruby 1.9, but I don't know does it work well with rails 2.3.8? (I see in the rails' website, they recommend ruby 1.8.7)
http://en.wikibooks.org/wiki/Ruby_Programming/Installing_Ruby#Windows_is_slow
OSX 10.5 comes with Ruby 1.8.6 I believe, but I see a lot of tutorials that recommend installing the latest version of Ruby from source. I've done this in the past and it's caused minor issues down the road if I install something which expects Ruby to be in the default location and it's not (Phusion Passenger pref pane, for instance).
What I'm wondering is if the default version of Ruby is good enough to use for development purposes, so there's no conflicts or multiple versions of Ruby floating about? Obviously the default Rubygems and Rails versions would need to be upgraded, but I'm specifically wondering about the default version of Ruby that comes with 10.5.
Rails 3 will require Ruby 1.8.7 and we're already recommending 1.8.7 for Rails 2.3.4. I'd strongly recommend upgrading.
1.8.6 will be fine for a local dev box. Personally I always install what's on the production box -- usually Ruby Enterprise -- but yea, if you don't want to deal with the hassles involved with replacing ruby entirely, there's no big disaster waiting for you with the stock stuff.
If you do want to keep current (probably a good idea for a serious application) and make sure you're running the same ruby as your production environment then you could try this tutorial (I've used a previous iteration) on handling those hassles.
The Rails team themselves recommend Ruby 1.8.7 for doing Rails development with any of the most recent releases.
I'd also highly recommend that you use the same version of Ruby for development as what will be in your 'production' environment. Avoids surprises.
The Ruby on Rails download page recommends 1.8.7 but says 1.8.6 still works and I'm finding no problems.
I personally do not like the Ruby implementation on the Mac, as I had a a lot of problems with MySql, Postgres, and other gems, always being obscure compilation problems which required me to install XCode and then compile all sorts of obscure libraries. In the end I solved my problems by installing Ubuntu 8.10 on VirtualBox under the Mac, and now everything works great!!!!
Also, when I switched to Snow Leapard I had a lot of the Ruby gems break as well. Also, I would recommend using Ruby 1.9, definitely much faster than 1.8.6 IMHO, again, running best on Ubuntu, NOT Mac.
I guess I would also like to add that many Unix die hards will disagree with me on this post, as things on the Mac CAN be made to work, but I guess I'm just lazy, and would rather have things "work out of the box".
I run REE (Ruby Enterprise Edition) simply because it runs my specs faster than the regular version (about 20%, sometimes more).
It's also nice that it comes with passenger and some of other things you usually want.
Ruby 1.9.1 RC1 was released today so I quickly moved to install it (a test version of course using a suffix of 19). I install Rails and Rack for the 1.9 RubyGems and then create a new Rails site using edge... when I execute:
ruby19 ./script/server
I watch as the processor usage goes up to 99.8 and the terminal just sits there. Trying to run Rails 2.2 using 1.9.1RC1 gives all sorts of fail on the inflector. I was under the impression that Rails 2.2 was 1.9.1 compatible. Is anyone successfully testing Rails under Ruby 1.9.1 or are you seeing similar errors?
The same thing for me.
I'm running the latest edge rails under webrik and just see the blank screen and no response to Ctrl-C. Rails 2.2 isn't working at all.
Also, I've tried run edge under thin (with eventmachine from github fixed to build on ruby 1.9.1, except one broken ruby test - I've just added empty one with 'assert true').
After that, both webrick and thin crashes immediately with:
$ /usr/local/bin/ruby script/server
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.3/lib/rubyeventmachine.bundle: [BUG] Bus Error
ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [i386-darwin9.6.0]
So, I guess, we all need calm down now. There still much work to actually run our rails apps under 1.9.1. Many gems are still at the early stages of bringing compatibility with 1.9.1
Actually, rails 2.2 is not fully compatible with ruby 1.9.1, just a basic compatibility, according to rails core team :)
Full compatibility claimed in upcoming rails 2.3.
I have written a guide on using Rails edge (near enough to 2.3) and Ruby 1.9.1. mysql, postgres and a few other gems like hpricot, thin and mongrel don't work, but the application does work.
Rails 2.2.2 is not compatible with Ruby 1.9.1rc1 when processing characters and strings on ActiveSupport. Rails uses multibyte to support unicode char-set, in other hand Ruby 1.9.1 uses built-in unicode support. Supported versions is 1.8.5 to 1.8.7.