Why my erb rendering time is so long

I have found my rails app has got a so slow rendering speed,no matter it
works under development or production enviroment,no matter it works
under windows or linux,no matter it is started by webrick or
apache+mongrel,here is the log:

Rendering users/topusers
e[4;35;1mProfile Columns (0.016000)e[0m e[0mSHOW FIELDS FROM
profilese[0m
e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 1) LIMIT 1e[0m
e[4;35;1mUser Load (0.000000)e[0m e[0mSELECT * FROM users WHERE
(users.id = 2) LIMIT 1e[0m
e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 6) LIMIT 1e[0m
e[4;35;1mUser Load (0.016000)e[0m e[0mSELECT * FROM users WHERE
(users.id = 5) LIMIT 1e[0m
e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 3) LIMIT 1e[0m
e[4;35;1mUser Load (0.000000)e[0m e[0mSELECT * FROM users WHERE
(users.id = 4) LIMIT 1e[0m
Completed in 0.89000 (1 reqs/sec) | Rendering: 0.67100 (75%) | DB:
0.03200 (3%) | 200 OK [http://127.0.0.1/]

I can see that this rendering will take 0.89 second to finish,and DB
occupies only 3% of the time.Here is the rhtml:
<% @profiles.each do |profile| %>

<% unless profile.image.nil? %>
<img src=<%=
url_for_image_column profile, “image”, :size => “24x24”, :name
=> “medium” %> height=16 width=16 /img>
<% else %>
<%= user_thumb(“default”) %>
<% end %>

<%= link_to_remote " “+h(”#{profile.user.login}")+ " ",
{ :url => { :controller => ‘users’, :action => ‘view’, :id =>
“#{profile.user.id}” },
{ :href => url_for( :controller => ‘users’, :action => ‘view’,
:id => “#{profile.user.id}” )} %>
<% end %>

And here is the action:

def topusers
@profiles = Profile.find(:all, :order => ‘updated_at DESC’, :limit
=> 10)
render :layout => false
end

It is very simple,but the rendering time is so long. Although i have
notices such article that route may effect the rendering time, it seems
to improve very little to the performance. From many persons’
experience,they are easy to reach a concurrency of 100 req/sec, i can
only get 1 req/sec, a very large gap. Have i made some mistakes?

Please use action_profiler to benchmark your app. Rendering is slow and
is a
problem, but much of it can be alleviated by generating routes manually.
Also search for Stefan K.’ optimizations.

Vish

On Oct 7, 2006, at 7:16 PM, Benson wrote:

e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 4) LIMIT 1e[0m
“24x24”, :name
‘view’,
end

It is very simple,but the rendering time is so long. Although i have
notices such article that route may effect the rendering time, it
seems
to improve very little to the performance. From many persons’
experience,they are easy to reach a concurrency of 100 req/sec, i can
only get 1 req/sec, a very large gap. Have i made some mistakes?

Are those calls to user_thumb and the other image operations doing
resizing on the fly? That could account for low performance. Other
then that I don’t see anything that should be taking so much time.
Can you do a benchmark of an action that just does a render :text =>
‘hello!’ to get a baseline perf measurement?

-Ezra

The above log is based on the adoption of Stefan K.’ optimizations.

Vishnu G. wrote:

Please use action_profiler to benchmark your app. Rendering is slow and
is a
problem, but much of it can be alleviated by generating routes manually.
Also search for Stefan K.’ optimizations.

Vish

Are those calls to user_thumb and the other image operations doing
resizing on the fly? That could account for low performance. Other
then that I don’t see anything that should be taking so much time.
Can you do a benchmark of an action that just does a render :text =>
‘hello!’ to get a baseline perf measurement?

-Ezra
User_thumb is a very simple helper method:
def user_thumb (id)
“<img src=”/images/default_user_thumb.gif" width=30 height=30/>"
end

Here are some more measurement:
1 I remove the code of user_thumb,and the rhtml refers to:
<% @profiles.each do |profile| %>
<%= link_to_remote " “+h(”#{profile.user.login}")+ " ",
{ :url => { :controller => ‘users’, :action => ‘view’, :id =>
“#{profile.user.id}” },
{ :href => url_for( :controller => ‘users’, :action => ‘view’,
:id => “#{profile.user.id}” )} %>
<% end %>

Then the log is:
Completed in 1.64100 (0 reqs/sec) | Rendering: 1.31200 (79%) | DB:
0.03200 (1%) | 200 OK [http://127.0.0.1/]

2 I use render :text => “hello”
The log is:
Completed in 0.34400 (2 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.00000 (0%) | 200 OK [http://127.0.0.1/]

3 I change the action “topusers” to :
def topusers
render :text => ‘hello’
end
The log is:
Completed in 0.17200 (5 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.00000 (0%) | 200 OK [http://127.0.0.1/]

These following test is done under windows, but it does not improve much
under linux.

Could the calls to profile.user, profile.image be generating lots of
database queries? (in which case consider eager loading). Often stuff
like that doesn’t really show up as database time, because the
individual queries themselves are so fast.

But as others have said why not stop guessing and use something like
action_profiler?

Fred

Benson wrote:

Rendering users/topusers
e[4;35;1mProfile Columns (0.016000)e[0m e[0mSHOW FIELDS FROM
profilese[0m
e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 1) LIMIT 1e[0m
e[4;35;1mUser Load (0.000000)e[0m e[0mSELECT * FROM users WHERE
(users.id = 2) LIMIT 1e[0m
e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 6) LIMIT 1e[0m
e[4;35;1mUser Load (0.016000)e[0m e[0mSELECT * FROM users WHERE
(users.id = 5) LIMIT 1e[0m
e[4;36;1mUser Load (0.000000)e[0m e[0;1mSELECT * FROM users WHERE
(users.id = 3) LIMIT 1e[0m
e[4;35;1mUser Load (0.000000)e[0m e[0mSELECT * FROM users WHERE
(users.id = 4) LIMIT 1e[0m
Completed in 0.89000 (1 reqs/sec) | Rendering: 0.67100 (75%) | DB:
0.03200 (3%) | 200 OK [http://127.0.0.1/]

Seeing that, an :include for find is needed.

Joe

On Oct 8, 2006, at 12:58 AM, Benson wrote:

def user_thumb (id)
‘view’,
0.00000 (0%) | 200 OK [http://127.0.0.1/]
These following test is done under windows, but it does not improve
much
under linux.

I wouls say you have some other issue at this point. If a simple

action ith render :text => ‘foo’ is that slow then no other rails
actions can be faster. render :text is the minimum action rails can
serve while exercising the full stack. So you need to figure out why
your setup is so slow. I don’t know about on windows but on linux or
osx a render :text action should get much closer to 100req/sec when
it doesnt access the db.

-Ezra

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs