views:

1248

answers:

8

Rails, on development mode is SLOW. Very, very slow. I run Vista, and I set config.cache_classes = true in development.rb... But, it's still slow and I have to restart the server after I change my code.

My coworker develops Rails on a Mac and sees similar slowness.

My development time slows down significantly because it takes minutes to test out code changes.

Is this as good as Rails development gets? Or am I missing something that'll make it fast and my life happy?

A: 

I'm assuming your requests are taking seconds? (Otherwise you probably wouldn't have noticed). It has always been fast for me. Especially since I started using sinatra instead of rails :D

Oh, and I forgot to mention - I used to run rails locally, but I currently use a virtual centos server with VMWare. Both were fast

Sean Clark Hess
har har har. Well, I should not have to explain, but Sinatra is not an option. I am already deep into my current project. Is it fun to install a plugin that allows you to (gasp) run updated code without restarting the dev server. oh snap :)
tell me more about this virtual centos server...
I think VMWare makes a windows version, but basically, you buy/download a program that lets you run multiple OSes virtually. For example, on my mac, I have windows and Centos (linux) running in a virtual machine. The software lets you share folders so a folder on your machine is mirror in the virtual os. You set it up just like a server, and it has a local IP address. You can either type in that IP address to hit it, or edit your hosts file to make a fake domain. For example, http://blog.local goes to my virtual server.
Sean Clark Hess
so do you set Rails to be in production or development mode when it's on this vmware server?
Whichever you want :) I'd put it in development mode.
Sean Clark Hess
A: 

I set config.cache_classes = true in development.rb. It's still slow and I have to restart the server after I change my code.

You should not use that cache in development (especially if it is still slow when using it). Having to restart the server all the time will slow you down even more.

Are you sure Ruby itself is slow? Not for example some DB access code that you run? Is a simple "Hello World" demo equally slow?

And how slow are we talking? Page load times more than 10 seconds?

Thilo
load times are approx 8 seconds. DB access is not slow, as I have a testing-production server (not local) that is connected to the same DB.for your first point, it's essentially a choice between the lesser of two evils.
+2  A: 
Andrews-MacBook-Pro:Sites askegg$ rails test
Andrews-MacBook-Pro:Sites askegg$ cd test
Andrews-MacBook-Pro:test askegg$ ./script/generate model test
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/test.rb
      create  test/unit/test_test.rb
      create  test/fixtures/tests.yml
      create  db/migrate
      create  db/migrate/20090812005217_create_tests.rb
Andrews-MacBook-Pro:test askegg$ ./script/performance/benchmarker 1000000 Test.new
            user     system      total        real
#1     25.140000   0.200000  25.340000 ( 25.549605)

Hmmm. 25 seconds to instantiate 1 million objects in development mode on a macbook pro with 12 other programs loaded. Seems OK to me.

askegg
So you're saying I should appreciate the massive behind the scenes complexity the Rails app sorts through to give me a smooth dev experience and count the slow dev server time as one small side of a very good tradeoff?
Not at all. I am demonstrating that Rails (at least on my machine) is not slow at all. I just ran another test (in development mode) on a project I recently completed - it loads 1,000 objects in 0.271 seconds. This is a far cry from your 8 second load times. Something is wrong with your configuration, so it really isn't a Rails specific problem.
askegg
Oh - in addition try profiling the method calls you are making to see where the app might be slowing. eg "./script/performance/profiler Page.first 1000"
askegg
instead of Page.first 1000, I write my own DB query? thanks!
Yes. "Page.first" was only an example from one of my projects. I have a Page model in a very slim CMS. Just replace it with your own code.
askegg
+4  A: 

Are you talking about:

  • Slowness starting the app (like running script/server)?

    If it's the server startup, then what server are you using? From my experience webrick is slower than mongrel is slower than thin. Passenger really is the most efficient for local development (though I've never tried to get it running on windows).


  • Slow page responses from hitting the dev server?

    This could be inefficient database queries, too much computation in the view that could be reworked, etc. If it's running ok in production this is probably not your issue. However, the web server you run will make a difference in your speed locally as well. I think the same order for startup applies for execution as well.


  • Rake tasks taking forever to start?

    I've had this issue as well. If you have a large project with lots of plugins (which means lots of initialization that needs to run), it can take a while to ramp up the rails environment. There are things that will probably speed it up, but there's no silver bullet. Make sure you don't have any plugins installed you are no longer using, take a careful look at your environment and initializers to make sure it's in good shape, etc.


Bottom line being, stating "Rails is slow in development" doesn't really pinpoint the problem. If you can clarify what is slow, then you can get specific help to speed it up. I've worked on lots of pretty large projects that have suffered from performance issues in development as well as production. I've never had a situation that couldn't be improved if given the right attention. Pinpoint the problem and you can usually diagnose a better solution to speed things up.

Jeff Whitmire
+1  A: 

The rails-dev-boost plugin speeds up Rails development mode. I was having the same problem, and this plugin made my application very snappy (compared to few second load per page). It will run at similar speed as production!

http://github.com/thedarkone/rails-dev-boost

To install it:

script/plugin install git://github.com/thedarkone/rails-dev-boost
Richard Millan
Just tried out this plugin and it helped a lot - awesome, thanks!
Brian Armstrong
A: 

I have been running into the same issues. My app, in dev mode, keeps getting slower and slower. As an example, I create a new controller with a new action:

  def test
    render :text => 'nothing'
  end

In dev mode, this takes between 12-15 seconds to complete (when requesting via FF and IE). I am using mongrel (not clustered). I am on a macbook pro.

In prod mode this takes ~130ms.

There has to be a way to find out which files are being loaded per request (basic profiling) so I can try to figure out what is going on and where the bottleneck is.

FF Firebug Net shows that most of the time (11-14 seconds) are spent in WAIT state.

Console shows:

Completed in 2ms (View: 0, DB: 152)

.

Any ideas?

Carlos
A: 

faster_require

http://github.com/rdp/faster_require

might help

speeds mine up significantly on windows

also spork can be used with jruby to speed up unit tests

http://github.com/rdp/spork

rogerdpack
A: 

I arrived at this post trying to understand why I was seeing so much time between requests in development mode.

I'm working on a modest-size application - 4000 LOC, 113 classes - and slumming it on a slow machine. More than 9/10ths of the time between requests happens while loading model code.

Predictably, config.cache_classes = true speeds things up considerably.

scottburton11