11

Why is Ruby, and Ruby on Rails (1.8.6 One Click Installer, local database) so ruddy slow on Windows?

  • ruby script/server - 30 seconds
  • rake test - 45 seconds
  • etc.

Yet, when I pop over to a much slower linux box, it's virtually instantaneous. I've checked everything - no significant CPU processes running, no network issues... and so on.

Heck, I'd be happy with just a verbose output that at least told me where it was breaking down. Any suggestions?

aronchick
  • 6,786
  • 9
  • 48
  • 75

4 Answers4

7

In general Ruby's MRI interpreter is just not optimized for speed on windows. You might also be running it in development mode on windows vs production mode on the other machines. Rails runs much slower in development mode since it reloads all your classes on every request.

1.8.6 is a very old ruby version. Released almost 3 years ago. You should strongly consider upgrading to 1.9 (or at least 1.8.7). Or switching to JRuby. All of these options will likely lead to a significant performance improvement.

1.8.7 should be fully compatible with 1.8.6. 1.9 has a completely new interpreter that runs 2.5 times faster (Though it has a tendency to occasionally crash on windows). JRuby may be the ideal solution for you since you can run it in either compatibility for 1.8 or 1.9 and it is very stable, but it does not support gems with C extensions and requires a different database adapter.

One last option would be to try running Rails inside of a VMWare with CentOS or another Linux distribution.

Gdeglin
  • 12,432
  • 5
  • 49
  • 65
  • 5
    In addition, it's possible that the OP is using the One-Click Installer, which is now quite old and superseded by RubyInstaller. The RubyInstaller for 1.8.7 is probably the minimum that should used at this point. – Stuart Ellis Mar 06 '10 at 08:53
  • I believe I _am_ using the 1-click installer (they should really remove that from the ruby-lang.org). I'll try moving up to 1.9.1 even though that's not our production environment. Is JRuby significantly faster? – aronchick Mar 06 '10 at 17:33
  • I think they plan on removing it once rubyinstaller "comes out of RC" – rogerdpack Mar 08 '10 at 17:35
2

The reason is that file stat's in windows are dreadfully slow, and, since Ruby is written on Linux (and optimized for Linux), there hasn't been much work to make it faster.

Using the rubyinstaller.org (1.8.6 or 1.9.x) can make it faster--I'd recommend 1.8.6 since 1.9 has some slowdowns of its own.

If you're looking to get really aggressive, you can try my faster_gem_script gem, which tries to cache the heck out of require based look ups and thus speed things up. Do it with a scratch version of ruby, though :)

Unfortunately Jruby also isn't known for its exceedingly fast lookups. Hopefully this situation will change someday. Until then my faster_gem_script and faster_require are the only way I know of to try to get some speedup.

For a speedup you could try my loader speeder upper (helps rails run faster in doze): https://github.com/rdp/faster_require Also checkout spork, which works in doze, and jruby also works well.

-rp

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
  • I haven't tried jruby with rails much on doze--my hunch is it would be about as slow as MRI. My answers are the same for 1.8.7 as for 1.8.6 (and 1.9.x for that matter, is typically worse) though it appears that 1.9.2 is going to be a bit faster in this regard than 1.9.1 [1]). [1] http://redmine.ruby-lang.org/issues/show/2723 – rogerdpack Mar 15 '10 at 18:02
1

UPDATE: Thanks (in part) to some really great work on Fenix by Luis Lavena, Ruby 1.9.3-p327 is much, much faster on Windows. rake used to take 110+ seconds to execute on 1.9.3-p125, and now takes ~20 seconds on p327. Rails is finally usable on Windows!!

Use RubyInstaller to install..

lambinator
  • 10,616
  • 7
  • 55
  • 57
1

I like taking this approach:

slow rails stack

In my case its

finisher_hook: 22.463 sec

That is the culprit

Community
  • 1
  • 1
Matthias
  • 1,884
  • 2
  • 18
  • 35