Rails 3 initializes extremely slow on Ruby 1.9.2 - ruby-on-rails

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.

Related

Upgrading ruby on a production server with Rails and Passenger

I have a few Rails apps, each running on their own server. They run under Passenger-apache, and currently under ruby 1.9.3. Currently, they run under a ruby installed and managed with rbenv.
I'd like to upgrade them all to ruby 2.2.x. As long as I'm doing this, I'd like to upgrade them from passenger 4.x to 5.x as well.
Let's assume I've tested them all on my development box and am confident they run fine under ruby 2.2.
As I think through this, I get very confused about the best way to do this -- especially with minimal production downtime.
I guess I'd start out by installing ruby 2.2 under rbenv, which theoretically shouldn't disturb the running apps. Passenger is installed under a particular ruby, but then has the option of running apps under different rubies. Should I install the latest passenger first, under the new ruby 2.2, but configured to run the existing apps under the old ruby? And then upgrading the apps to the new ruby... I guess involves running bundle install again, to get all dependencies installed under the new ruby?
Or something else entirely? Is there a way to do this that is relatively safe, and will have limited or zero downtime for my apps?
Has anyone done this before? I'm fairly familiar with all the pieces already, and can brainstorm possible approaches myself, but when I start, there are too many places where I'm not sure what the best approach is. What I could really use is advice from someone who has already done this, or is otherwise pretty sure that what they recommend will work as they say -- not just guesses about things you haven't done that might work. Thanks!
Make sure that your applications work under the new ruby version. I have had some legacy Rails 3.2.x applications that works up to ruby 2.1.5, but breaks in ruby 2.2.x. You should be fine with updating your ruby and passenger versions.
Since each application runs on their own server, you don't have to really worry about running multiple versions of passenger. You should be able to install the new version ruby on each server, install the gems, update apache to the newer passenger and restart apache to have everything take effect. Worst case, you can clone your servers to a virtual environment and test everything prior to doing it on production. This would help you minimize downtime as you would have any workarounds and/or research of bugs done prior to touching the production environment.

Anyone tried having Ruby installed both from RVM and deb at the same time in Ubuntu?

Currently one of the machines on which I'm running has Ruby 1.8.7 installed as a .deb and Rails installed following this tutorial: https://help.ubuntu.com/community/RubyOnRails
I've developed several Rails apps with this machine, and from time to time I have to make little improvements to them. Until now to test the changes using just entering the directory and typing Rails s or Ruby script/server was fine.
Now the problem:
This machine is going to be inherited by someone else, probably with very little knowledge about Rails, so I want to keep everything as simple as possible. But, while this happens, I also want to keep trying the latest versions, and for that I would need to use RVM.
So the question is:
If I keep everything as it is, and now I install RVM along with my needed Ruby versions and gems. Will everything keep working the same as now? Or might I find some nasty surprises?
Maybe there is another solution for this issue. Those are also very welcomed.
As long as you don't activate RVM by calling it in your .bash_profile or similar RVM won't do anything, so, yes, you can have it next to the system Ruby without problems.
Just configure your .bash_profile to load RVM or call the init yourself.
You could have a look at rbenv too.

Upgrading Ruby broke Rails?

So, I upgraded Ruby to 1.8.7 to make a particular gem work. Hooray, it works now! But...now rails doesn't. I tried reinstalling rails through gem, but that hasn't helped, either. Rake is no longer recognized by my windows box as a valid command, and I can't even start the server without a whole string of errors.
My only thought is that maybe I shouldn't have copied my gems file over (a tutorial mentioned it as the only way to save my gems on windows with an upgrade). I'm gonna try reinstalling 1.8.7 without changing anything, and reinstalling everything as needed.
Edit: Okay, just plain 1.8.7 does work, but it's frustrating to have to reinstall all my gems by hand... Is there any better solution, in Windows?
You may have to uninstall the old version first or use something like RVM to manage your multiple versions. I've always run into problems trying to upgrade directly on a windows machine (rake and rails not working basically).
Edit: Looks like even with RVM you have to install gems individually for each version (a good thing), but you can also export and import gem sets. That might be your best bet, short of scripting a solution yourself.
That is normal: each ruby environment has their own set of gems. That might not seem intuitive, but i guess it has something to do with the possible differences in ruby versions and the fact that gems are "installed" and compiled if needed.
I have a script that installs all my needed gems on windows. On windows rvm does not work, but there is an alternative called pik. I have written a blogpost about this process, which also contains a small bat-file i use that will install the most commonly used gems automatically.

Rails initializes extremely slow on ruby 1.9.1

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

Is the default Ruby install on Mac OSX 10.5 "good enough" for Rails development?

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.

Resources