Forum: Ruby on Rails Ruby on Rails Performance question

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.
4b875f7fe147af4ceaa337a9a5699c9e?d=identicon&s=25 Jang Choe (Guest)
on 2006-06-02 16:31
(Received via mailing list)
I'm wondering if this is a typical thing.

What I'm doing is getting about 5000+ records from a database and
displaying all of it on a page.

I've used the benchmark helper to benchmark the views for that page
and that takes about 25 seconds to render that view. Is this pretty
typical?

What I'm doing is using find_by_sql to get all the values that I need
from the tables and saving that to an instance variable in the
controller. Then I iterate it through that instance variable using
.each_with_index (I need the index value as well)  to render the View.
The view is just a table. So I'm just rendering
<tr><td>@foo.bar</td>... </tr>  Nothing complicated.

And that's taking about 25 sec according to the benchmark helper.

Is there anything I'm doing in the algorithm that's wrong? Is there
any way to speed things up? I'm getting pressure from the higher ups
saying that 25 seconds isn't acceptable. They need something like 6
seconds.

The reason I use find_by_sql is so that I don't hit the database
through each iteration. And I figure that'll help in the speed. Also,
I tested the find_by_sql SQL query I wrote and checked the speed on
that. That's not the issue (it took about 0.2 seconds for mysql to
dump all the data).
6edd67c92a1dab5eb23fed79f3c18564?d=identicon&s=25 David Heinemeier Hansson (Guest)
on 2006-06-02 16:59
(Received via mailing list)
> What I'm doing is getting about 5000+ records from a database and
> displaying all of it on a page.

I would start by questioning why you would need to present 5K+ objects
on a single page. It would there are better ways to present massive
amounts of records than just to dump them all on one screen.

But if you must, I'd encourage you to go straight to the metal. Grab
the connection (ActiveRecord::Base.connection), then use select_all to
get hashes back instead of AR objects. If that's not fast enough,
investigate what methods your particular database adapter has for
returning records as arrays instead of as hashes.
--
David Heinemeier Hansson
http://www.loudthinking.com -- Broadcasting Brain
http://www.basecamphq.com   -- Online project management
http://www.backpackit.com   -- Personal information manager
http://www.rubyonrails.com  -- Web-application framework
Df0a460118ef876e45b13b8c1a471454?d=identicon&s=25 Marston A. (marstoni)
on 2006-06-02 16:59
I'm wondering the same thing, so it will be great to have peoples input
on this.  Personally I have something similar setup but with much less
data than you, < 100 rows and iterating via a table.  My page actually
takes 6 seconds to load which I think is way to long.
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-06-02 17:29
(Received via mailing list)
On Jun 2, 2006, at 16:59, Marston A. wrote:

> I'm wondering the same thing, so it will be great to have peoples
> input
> on this.  Personally I have something similar setup but with much less
> data than you, < 100 rows and iterating via a table.  My page actually
> takes 6 seconds to load which I think is way to long.

Less than 100 rows, that's sounds strange. Can you reproduce that in
a minimal example?

-- fxn
4b875f7fe147af4ceaa337a9a5699c9e?d=identicon&s=25 Jang Choe (Guest)
on 2006-06-02 18:02
David Heinemeier Hansson wrote:
>> What I'm doing is getting about 5000+ records from a database and
>> displaying all of it on a page.
>
> I would start by questioning why you would need to present 5K+ objects
> on a single page. It would there are better ways to present massive
> amounts of records than just to dump them all on one screen.

Well who know what and how PHBs think. I personally think they're only
going to show 100 at a time, but they want it optimised enough so that
5000+ records can render in about 6-7 seconds. Or maybe they do want to
show 5000+ at the same time for some crazy reason.

We are a Java shop and we have application servers running that can
pretty much do that (display 5000+ records in a very short amount of
time). So I'm guess they want something comparable.


>
> But if you must, I'd encourage you to go straight to the metal. Grab
> the connection (ActiveRecord::Base.connection), then use select_all to
> get hashes back instead of AR objects. If that's not fast enough,
> investigate what methods your particular database adapter has for
> returning records as arrays instead of as hashes.

Wow, that worked really well. The benchmarks for rendering the view came
down from 25 sec to about 7 seconds. That's crazy. Thanks David.
This topic is locked and can not be replied to.