Why is rake really slow?

R

richpoirier

Is rake supposed to be really slow?

I'm using InstantRails and running rake in a project with one unit
test and two functional tests and it takes 33 seconds total. Is that
normal? It seems really slow to me.

When I turn on trace I can see that it spends most of its time in
"Execute environment" and loading the test files:

C:/InstantRails/ruby/bin/ruby -Ilib;test "C:/InstantRails/ruby/lib/
ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb" "test/unit/
user_test.rb"

Anyone else have this problem or is it normal? Thanks.
 
R

Ryan Davis

Is rake supposed to be really slow?

no, not that it is supposed to be really fast... but it isn't what
gets in your way.
...
C:/InstantRails/ruby/bin/ruby -Ilib;test "C:/InstantRails/ruby/lib/
ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb" "test/
unit/
user_test.rb"

My guess is that your test is slow. To start, take rake out of the
equation:

ruby -rtest/unit test/unit/user_test.rb

After that, you can do something simple like:

def setup
@start_time = Time.now
end

def teardown
puts "** TIME: #{self.name} : #{Time.now - @start_time} seconds
end

And see what's going so slow a little clearer.
Anyone else have this problem or is it normal? Thanks.

I run thousands of tests/assertions in just seconds many times a day:

ruby: Finished in 0.105172 seconds. 252 tests, 735 assertions, 0
failures, 0 errors
ruby: Finished in 1.275824 seconds. 750 tests, 2220 assertions, 0
failures, 0 errors
rails: Finished in 81.681246 seconds. 1924 tests, 12195 assertions, 0
failures, 0 errors
 
J

Jim Weirich

unknown said:
Is rake supposed to be really slow?

I'm using InstantRails and running rake in a project with one unit
test and two functional tests and it takes 33 seconds total. Is that
normal? It seems really slow to me.

When I turn on trace I can see that it spends most of its time in
"Execute environment" and loading the test files:

C:/InstantRails/ruby/bin/ruby -Ilib;test "C:/InstantRails/ruby/lib/
ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader.rb" "test/unit/
user_test.rb"

Anyone else have this problem or is it normal? Thanks.

Rake in and of itself is quite fast. There are two types of things that
can slow you down.

(1) Executing the Rakefile. If you have lots of tasks or complex
dependencies, then whatever time it takes to resolve those can build up
and slow down every rake command.

(2) Slow tasks. Some tasks in rake are naturely slow. Slow takes make
anything that depends upon them slow as well.

I assume you are working in Rails? Add this to your top level Rakefile:

task :noop

Then time the "rake noop" command. This will be the time it takes rake
to run essentially a do nothing task and will give you a sense of the
general Rakefile overhead.

Then time "rake environment". This task loads the rails environment and
can take some time. The environment task is a dependency of most rails
related rake tasks in a Rails project.

In the project I'm currently working on, "rake noop" takes under a
second. "rake environment" takes nearly 3 seconds. ("rake noop" in a
lightweight non-rails project takes under 0.2 seconds).

It sounds like the environment task on your system is painfully slow.
Is it doing anything unusual?

-- Jim Weirich
 
R

richpoirier

Rakein and of itself is quite fast. There are two types of things that
canslowyou down.

(1) Executing the Rakefile. If you have lots of tasks or complex
dependencies, then whatever time it takes to resolve those can build up
andslowdown everyrakecommand.

(2)Slowtasks. Some tasks inrakeare naturelyslow. Slowtakes make
anything that depends upon themslowas well.

I assume you are working in Rails? Add this to your top level Rakefile:

task :noop

Then time the "rakenoop" command. This will be the time it takesrake
to run essentially a do nothing task and will give you a sense of the
general Rakefile overhead.

Then time "rakeenvironment". This task loads the rails environment and
can take some time. The environment task is a dependency of most rails
relatedraketasks in a Rails project.

In the project I'm currently working on, "rakenoop" takes under a
second. "rakeenvironment" takes nearly 3 seconds. ("rakenoop" in a
lightweight non-rails project takes under 0.2 seconds).

It sounds like the environment task on your system is painfullyslow.
Is it doing anything unusual?

-- Jim Weirich

Thanks for the replies. Yes I'm working with rails. I think you are
both right. Running a single unit test without rake takes about 11
seconds (even though it says it finished in 0.118 seconds). The test
simply creates a new user in my User model. So maybe it's taking a
while to connect to my mysql db? I'll have to investigate that (not
sure how to though). rake environment takes about 13 seconds. Where is
the environment task defined? I'd like to take a look at it to see
what it's doing. Using rake to run that one unit test takes 24
seconds, so it's definitely a combination of the environment task
being painfully slow and the test itself being slow too.

Thanks again for the help Jim and Ryan.
 
R

Rich

Thanks for the replies. Yes I'm working with rails. I think you are
both right. Running a single unit test withoutraketakes about 11
seconds (even though it says it finished in 0.118 seconds). The test
simply creates a new user in my User model. So maybe it's taking a
while to connect to my mysql db? I'll have to investigate that (not
sure how to though).rakeenvironment takes about 13 seconds. Where is
the environment task defined? I'd like to take a look at it to see
what it's doing. Usingraketo run that one unit test takes 24
seconds, so it's definitely a combination of the environment task
being painfullyslowand the test itself beingslowtoo.

Thanks again for the help Jim and Ryan.

Ok I've narrowed down the environment part of the problem. What's
taking long is the require_frameworks method in rails' Initializer.
The active_record, action_controller and action_web_services
frameworks take a while (a few seconds each) to load. So now the
question is why? I'm not sure where to look to dig deeper into this,
i.e., see what the require method is actually doing. Any ideas?

I still have to look into why the test itself is slow too.
 
H

hemant

Ok I've narrowed down the environment part of the problem. What's
taking long is the require_frameworks method in rails' Initializer.
The active_record, action_controller and action_web_services
frameworks take a while (a few seconds each) to load. So now the
question is why? I'm not sure where to look to dig deeper into this,
i.e., see what the require method is actually doing. Any ideas?

I still have to look into why the test itself is slow too.

Its normally a good idea to take out actual db connections when
running tests. Did you look into mocha or something?
 
R

Rich

Its normally a good idea to take out actual db connections when
running tests. Did you look into mocha or something?

I'm running rails tests though. Don't most rails tests require a db
connection?
 
A

Alexey Verkhovsky

On my 3GHz dual-core Athlon, under either Cygwin or virtualized Ubuntu,
with RAID-0 10,000-RPM drives, initializing the rails environment takes
7-10 seconds.

On my 2.16GHz dual-core MacBook Pro, with a single 5200-RPM drive,
initializing the rails environment takes a second or two.

You can imagine my workaround.

Err... is it to run One-Click Installer Ruby instead of Cygwin?
 
R

Rich

Probably useless data point:

On my 3GHz dual-core Athlon, under either Cygwin or virtualized Ubuntu,
with RAID-0 10,000-RPM drives, initializing the rails environment takes
7-10 seconds.

On my 2.16GHz dual-core MacBook Pro, with a single 5200-RPM drive,
initializing the rails environment takes a second or two.

You can imagine my workaround.

Jay Levitt

That's really interesting Jay. I'm running RoR on my HP dual core AMD
Turion 1.6GHz laptop. So maybe the 10+ seconds my environment takes to
initialize is normal for my system then? Should I just get a MacBook
or is there any way I can speed the initialization up?
 
R

Rich

That's really interesting Jay. I'm running RoR on my HP dual core AMD
Turion 1.6GHz laptop. So maybe the 10+ seconds my environment takes to
initialize is normal for my system then? Should I just get a MacBook
or is there any way I can speed the initialization up?

Ok here's an easy way to compare performance. I decided to see if it
would be any quicker at work so I installed InstantRails and just ran
rake in the rails_apps/typo-2.6.0 directory and it took 44 seconds
total. With trace on, I can see that the environment task takes about
8 seconds, and the test_unit and test_functional tasks take about 12
seconds each -- that's 12 seconds of loading before any actual tests
are run; the tests themselves run quite quickly (a fraction of a
second each). This was a completely clean installation of InstantRails
on a machine that had never touched ruby or rails before. Could
someone else try the same and see how long rake takes in the
typo-2.6.0 app? Thanks.
 
E

Ed Howland

Its normally a good idea to take out actual db connections when
running tests. Did you look into mocha or something?

Also, switching to RSpec might help here. In addition to mocks to
isolate the DB from the tests, you can run rspec_server which loads
the Rails environment once and then when you run your tests, they
connect to the server, and respond much more quickly.


Ed
--
Ed Howland
http://greenprogrammer.blogspot.com
"The information transmitted is intended only for the person or entity
to which it is addressed and may contain proprietary, confidential
and/or legally privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance
upon, this information by persons or entities other than the intended
recipient is prohibited. If you received this in error, please contact
the sender and delete the material from all computers."
 
R

Rich

Also, switching to RSpec might help here. In addition to mocks to
isolate the DB from the tests, you can run rspec_server which loads
the Rails environment once and then when you run your tests, they
connect to the server, and respond much more quickly.

Ed
--
Ed Howlandhttp://greenprogrammer.blogspot.com
"The information transmitted is intended only for the person or entity
to which it is addressed and may contain proprietary, confidential
and/or legally privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance
upon, this information by persons or entities other than the intended
recipient is prohibited. If you received this in error, please contact
the sender and delete the material from all computers."

Ok Ed, I've taken your advice and tried out rspec. I actually noticed
that the environment is loaded once before the tests are run and once
before each test task starts, so it's unnecessarily run three times if
you're testing units and functionals. So spec_server sounded like a
great solution and BDD is also very appealing.

However, I can't seem to get spec_server working properly. I can get
it running but executing a spec after that tells me the server is not
running, when I know it definitely is. I've tried with and without
rake. I'm using Windows Vista, so maybe that's the problem? Do you
know anyone who's gotten it working in Vista? Thanks.
 
R

Rich

Ok Ed, I've taken your advice and tried out rspec. I actually noticed
that the environment is loaded once before the tests are run and once
before each test task starts, so it's unnecessarily run three times if
you're testing units and functionals. So spec_server sounded like a
great solution and BDD is also very appealing.

However, I can't seem to get spec_server working properly. I can get
it running but executing a spec after that tells me the server is not
running, when I know it definitely is. I've tried with and withoutrake. I'm using Windows Vista, so maybe that's the problem? Do you
know anyone who's gotten it working in Vista? Thanks.

Ok I got it working. Turns out I didn't actually have any specs to
run. But it was still telling me no server was running which is
strange. I created a spec and ran it and man did it run fast compared
to Test::Unit.

So I think I'm all set now. rspec is awesome! Thanks for everyone's
help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top