Forum: RSpec Rspec Rails high overhead

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fe6331dd90e1df7d08f2fceefad70486?d=identicon&s=25 Reza Primardiansyah (Guest)
on 2009-01-04 04:00
(Received via mailing list)
Greetings,
I found out that running RSpec on Rails takes too much overhead. It
takes
more than 16s per run although the specs only take less than 6s, like
seen
below. That means almost 11s overhead.
I can't find the bottleneck. I use latest rspec, and rails 2.2 on
Debian.

$ time rake spec
> sys     0m2.266s
>

I know that Debian's ruby is slow. So I tried using enterprise ruby. Not
much difference

$ time /opt/ruby-enterprise/bin/ruby /var/lib/gems/1.8/bin/rake spec
> sys     0m1.735s
>

The overhead is also felt when using autospec. Even using sqlite's
in-memory-db doesn't change much.

Can anyone give me hint about what happens and what to do to overcome
it?

Thanks all.
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2009-01-04 05:19
(Received via mailing list)
On Sat, Jan 3, 2009 at 6:58 PM, Reza Primardiansyah <
reza.primardiansyah@gmail.com> wrote:


> I found out that running RSpec on Rails takes too much overhead. It takes
> more than 16s per run although the specs only take less than 6s, like seen
> below.


The killer is the time it takes to load environment.rb, which loads
Rails,
runs initializers, etc. The rake spec task also tears down and recreates
the
test database, but that's not as significant.

The solution to the first situation is spec_server, which loads the
environment once, then stays in memory as a DRb process. By passing
--drb to
the spec command, RSpec will have that process run specs. The solution
to
the second situation is to not run rake spec, but instead use spec or
autospec.

All that said, I haven't had as much joy from spec_server as I have in
the
past. Too often it seems to not load changed models. But this might be
related to a patch I had to apply to even get it to run. Things seemed
to
have changed with Rails 2.2.2 and/or RSpec 1.1.11.

///ark
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-01-04 15:45
(Received via mailing list)
On Sun, Jan 4, 2009 at 3:58 AM, Reza Primardiansyah <
reza.primardiansyah@gmail.com> wrote:

>>
> much difference
>> real    0m12.033s
>> user    0m9.948s
>> sys     0m1.735s
>>
>
> The overhead is also felt when using autospec. Even using sqlite's
> in-memory-db doesn't change much.
>
> Can anyone give me hint about what happens and what to do to overcome it?
>

How long does ruby script/server take before the server is up?

Aslak
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-01-04 15:59
(Received via mailing list)
On 2009-01-03, at 23:17, Mark Wilden wrote:
>
>
> ///ark

Mark, would you mind explicitly telling us/me how you get the ``spec''
command to run within DRb, please?

This is what happens I try [and fail] to do so:
http://gist.github.com/43070

Cheers,
Nick
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2009-01-04 22:01
(Received via mailing list)
On Sun, Jan 4, 2009 at 6:57 AM, Nick Hoffman <nick@deadorange.com>
wrote:

>
> Mark, would you mind explicitly telling us/me how you get the ``spec''
> command to run within DRb, please?
>

I use spec rather than script/spec to run specs. script/spec runs my
specs
twice. I also use rake spec:server:start rather than script/spec_server,
but
both commands do work for me.

The problem now is that if I change a model or lib file, it's not
reloaded
by spec_server. I have to stop and restart spec_server for the change to
be
picked up. This means I can't really use it. (To the powers that be, I
apologize for not filing a proper bug report.)

This is what happens I try [and fail] to do so:
> http://gist.github.com/43070
>

That sequence "works for me," I'm afraid.

///ark
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-01-04 22:12
(Received via mailing list)
On Sun, Jan 4, 2009 at 2:52 PM, Mark Wilden <mark@mwilden.com> wrote:
> On Sun, Jan 4, 2009 at 6:57 AM, Nick Hoffman <nick@deadorange.com> wrote:
>>
>> Mark, would you mind explicitly telling us/me how you get the ``spec''
>> command to run within DRb, please?
>
> I use spec rather than script/spec to run specs. script/spec runs my specs
> twice.

That's fixed, so I'm guessing you've got a mixture of old and new
generated files.

> I also use rake spec:server:start rather than script/spec_server, but
> both commands do work for me.
>
> The problem now is that if I change a model or lib file, it's not reloaded
> by spec_server. I have to stop and restart spec_server for the change to be
> picked up. This means I can't really use it. (To the powers that be, I
> apologize for not filing a proper bug report.)

Apology accepted as soon as you do :)
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2009-01-04 22:30
(Received via mailing list)
On Sun, Jan 4, 2009 at 1:03 PM, David Chelimsky
<dchelimsky@gmail.com>wrote:


> > I use spec rather than script/spec to run specs. script/spec runs my
> specs
> > twice.
>
> That's fixed, so I'm guessing you've got a mixture of old and new
> generated files.
>

I did re-gen with .16, but still got that result.

> The problem now is that if I change a model or lib file, it's not reloaded
> > by spec_server. I have to stop and restart spec_server for the change to
> be
> > picked up. This means I can't really use it. (To the powers that be, I
> > apologize for not filing a proper bug report.)
>
> Apology accepted as soon as you do :)
>

The problem, of course, is the "proper" part. But I will try to get at
it -
I love spec_server!

///ark
Fe6331dd90e1df7d08f2fceefad70486?d=identicon&s=25 Reza Primardiansyah (Guest)
on 2009-01-06 04:34
(Received via mailing list)
Aslak,
The best time I get is 6.3 seconds. I'm using "time script/server"
command
and hitting Ctrl-C immediately after I see "** Use CTRL-C to stop."
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-01-06 14:04
(Received via mailing list)
On Tue, Jan 6, 2009 at 4:29 AM, Reza Primardiansyah <
reza.primardiansyah@gmail.com> wrote:

> Aslak,
> The best time I get is 6.3 seconds. I'm using "time script/server" command
> and hitting Ctrl-C immediately after I see "** Use CTRL-C to stop."
>

Ok, so you have 5 seconds of additional overhead. I'm guessing that
RSpec
takes maybe 0.5-1 seconds of the remaining 6 seconds overhead, and that
plugins, gems and other code the rest. Maybe you'll find out more with
http://ruby-prof.rubyforge.org/

Aslak
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-01-06 14:55
(Received via mailing list)
On 6 Jan 2009, at 13:02, aslak hellesoy wrote:

> RSpec takes maybe 0.5-1 seconds of the remaining 6 seconds overhead,
> and that plugins, gems and other code the rest. Maybe you'll find
> out more with http://ruby-prof.rubyforge.org/
>
> Aslak

Worth mentioning that I went down a huge rabbit hole with a similar
problem (slow load of rails environment) a few weeks ago, and it
turned out that all I needed was a reboot. (Mac OSX Leopard). Boy, did
I feel like a chump!


> > wrote:
>
>
> sys     0m1.735s
>
> rspec-users mailing list
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
This topic is locked and can not be replied to.