High ActiveRecord CPU Utilization

J

Jeremy Kemper

Hi, are these results in production or development?

There is no difference between the two in this case, so the script
doesn't set RAILS_ENV at all.

Talking about template rendering, I'm just wondering if anyone has
thought of pre-processing the template for a production environment.
For example, I'd imagine it's might convenient to do things like '<%
tylesheet_tag %>' etc when linking in files. But, each time Rails hits
one of those, it needs to render it. Would it make sense to have a
smart pre-processor that goes through the templates to see what
constants there are (like links to the same stylesheet, javascript
files, etc.) and even things like "form_start_tag"/ "form_end_tag" etc.
to pre-render it so that the number of times you need to create
something is reduced.

Yes! See Stefan Kaes' template optimizer: http://railsexpress.de/plugins/trac

Has anyone benchmarked the time for rendering a page with many or few
such items?

Yes. See Stefan's blog; he regularly benchmarks his apps against each
new Rails release. I think he's covered the impact of the template
optimizer.

jeremy
 
M

M. Edward (Ed) Borasky

Brian said:
Interesting. Do you mind if I ask where you got the 10 to 30% figure?
Stability is more important to me than raw speed, so I'd prefer to not
use anything newer than Ruby 1.8.5-p12.

I'm running a 32 bit kernel because 64 bit was, let's say,
problematic. My gcc is 4.1.2.
http://www.jhaampe.org/software/ruby-gcc and
http://rubyforge.org/viewvc/MatrixBenchmark/?root=cougar

The 1.8.6 preview 3 is due for release this weekend, IIRC. I'm not sure
how one measures stability for a Ruby interpreter, but there are
definitely a few performance tweaks -- my MatrixBenchmark picked up
about 10 or 11 percent on a Pentium III from the switch. (with -O2
-march=pentium3, of course.) :)
 
J

Jeremy Kemper

The 1.8.6 preview 3 is due for release this weekend, IIRC. I'm not sure
how one measures stability for a Ruby interpreter, but there are
definitely a few performance tweaks -- my MatrixBenchmark picked up
about 10 or 11 percent on a Pentium III from the switch. (with -O2
-march=pentium3, of course.) :)

Preview 3 is out:
ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-preview3.tar.gz

I used it for the earlier benches and it has posed no problems for any
of my Rails apps in development.

Be sure to work with Rails' 1-2-stable branch (or edge) for a
smattering of 1.8.6 compatibility fixes due out in the upcoming Rails
1.2.3.

jeremy
 
R

Rob Sanheim

Hi Brian,

I wrapped this up in a simple script that anyone with MySQL or SQLite
and the AR gem can run. It benchmarks AR create vs using the db
connection directly. See attached.

Excerpted results on a new MacBook Pro:
user system total real
raw quoted 0.460000 0.000000 0.460000 ( 0.480184)
create 2.760000 0.080000 2.840000 ( 3.225227)

(Nearly 7 times slower.) I haven't tried profiling the methods yet.

In my experience with typical Rails apps, you'll hit a wall with ERB
template rendering much sooner than with Active Record creation. This
is an interesting pursuit nonetheless -- I'm interested to see what
you all come up with.

Best regards,
jeremy


Jeremy

Are there, or could there be, performance tests like this added to the
Rails test suite? It would be great to be able to track performance
like this over Rails releases.

- Rob
 
J

Jeremy Kemper

Are you saying that config/production.rb and config/development.rb
are identical?

No, sorry: it doesn't load a Rails environment at all, just vanilla
Active Record.

The Rails environment has no bearing on Active Record in isolation,
beyond choosing the default database connection:
$ grep -r RAILS_ENV lib/ |grep -v svn|wc -l
2

Your Rails app reloads application classes during development so some
AR caches, like the per-class table metadata, are wiped as a result.

jeremy
 
J

Jeremy Kemper

Are there, or could there be, performance tests like this added to the
Rails test suite? It would be great to be able to track performance
like this over Rails releases.

Sure; I think so. But I don't want to compile or maintain the suite ;-)

jeremy
 
B

Brian Adkins

Mohit, do you mind if I ask how you're posting messages to
comp.lang.ruby? While reading Jeremy's posts I realized I didn't see
either of your posts via my newsreader. When I noticed the first time, I
thought my ISP might have just randomly dropped some posts, but when I
went to:

http://www.ruby-forum.com

I saw both of your posts, but neither showed up via my newsreader
(Thunderbird). That seemed too coincidental for a Bellsouth screw up, so
I thought I'd ask.

Thanks,
Brian
 
J

James Edward Gray II

Mohit, do you mind if I ask how you're posting messages to
comp.lang.ruby?

I believe that was a cross-posted reply by Jeremy. I never saw the
message either.

James Edward Gray II
 
B

Brian Adkins

James said:
I believe that was a cross-posted reply by Jeremy. I never saw the
message either.

James Edward Gray II

Interesting. I guess I mistakenly assumed a one-to-one correspondence
between comp.lang.ruby and the "ruby" forum at
http://www.ruby-forum.com/ but now that I look more closely at the
latter, it does say "Gateway to the ruby-talk mailing list."

Thanks for confusing me Jeremy :(
 
J

James Edward Gray II

Interesting. I guess I mistakenly assumed a one-to-one
correspondence between comp.lang.ruby and the "ruby" forum at
http://www.ruby-forum.com/ but now that I look more closely at the
latter, it does say "Gateway to the ruby-talk mailing list."

I don't believe ruby-forum is involved here. I think Jeremy cross-
posted from the Rails list.

James Edward Gray II
 
B

Brian Adkins

James said:
I don't believe ruby-forum is involved here. I think Jeremy
cross-posted from the Rails list.

James Edward Gray II

Well if you go to: http://www.ruby-forum.com/topic/100325

You'll see this thread and you'll see Mohit's postings. As far as I can
tell, the above forum appears to be a superset of this comp.lang.ruby
thread. That's why I thought some postings were dropped, but if you
didn't see them either, I'll stop worrying about it and continue on my
way :)
 
J

James Edward Gray II

Well if you go to: http://www.ruby-forum.com/topic/100325

You'll see this thread and you'll see Mohit's postings. As far as I
can tell, the above forum appears to be a superset of this
comp.lang.ruby thread. That's why I thought some postings were
dropped, but if you didn't see them either, I'll stop worrying
about it and continue on my way :)

Ah yes, I see it now. This is some quirk of ruby-forum I'm not
familiar with. Disregard my earlier posts. Sorry for spreading
confusion.

James Edward Gray II
 
J

Jeremy Kemper

Interesting. I guess I mistakenly assumed a one-to-one correspondence
between comp.lang.ruby and the "ruby" forum at
http://www.ruby-forum.com/ but now that I look more closely at the
latter, it does say "Gateway to the ruby-talk mailing list."

Thanks for confusing me Jeremy :(

Ha! Sorry. I just hit "Reply All" to Mohit's message. Blame GMail ;-)

jeremy
 
M

M. Edward (Ed) Borasky

Jeremy said:
Sure; I think so. But I don't want to compile or maintain the suite ;-)

jeremy
I would think someone in the "core Rails team" would step up to the
plate for Rails-specific benchmarks. But if the specific case under
discussion here -- ActiveRecord -- turns out to have a bottleneck
somewhere in the Ruby interpreter, rather than just an inefficient
strategy in the ActiveRecord code itself, then I'd say this benchmark
belongs in a Ruby benchmark suite rather than a Rails benchmark suite.
 

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top