Rails 3 too slow?

I'm using Ruby 1.9.2, Rails 3.0.3, Passenger 3.0.0 and MySQL 5.1

rails new library
cd library

rails generate scaffold Book name:string
rake db:migrate RAILS_ENV=production

rails console production
200.times { |i| Book.create(:name => "Book #{i}") }

ab -n 100 -c 10 http://testlibrary.dyndns.org/books

This gives me a pathetic 4.55 requests/sec

Here is the log

Started GET "/books" for 189.71.229.236 at 2010-12-08 18:12:11 +0000
  Processing by BooksController#index as HTML
Rendered books/index.html.erb within layouts/application (349.2ms)
Completed 200 OK in 359ms (Views: 349.9ms | ActiveRecord: 0.2ms)

359 ms for a 2.9 KB page

What is wrong? I was expecting something like 50-100 requests/sec
I remember trying this before in rails 2.3.8 and it was much faster

I’m using Ruby 1.9.2, Rails 3.0.3, Passenger 3.0.0 and MySQL 5.1

rails new library

cd library

rails generate scaffold Book name:string

rake db:migrate RAILS_ENV=production

rails console production

200.times { |i| Book.create(:name => “Book #{i}”) }

ab -n 100 -c 10 http://testlibrary.dyndns.org/books

This gives me a pathetic 4.55 requests/sec

Here is the log

Started GET “/books” for 189.71.229.236 at 2010-12-08 18:12:11 +0000

Processing by BooksController#index as HTML

Rendered books/index.html.erb within layouts/application (349.2ms)

Completed 200 OK in 359ms (Views: 349.9ms | ActiveRecord: 0.2ms)

359 ms for a 2.9 KB page

What is wrong? I was expecting something like 50-100 requests/sec

I remember trying this before in rails 2.3.8 and it was much faster

Hi, you need to provide much more information? For example, application

mode (i.e. production, development, and so on), operating system, and so

on.

-Conrad

Conrad Taylor wrote in post #967247:

359 ms for a 2.9 KB page

What is wrong? I was expecting something like 50-100 requests/sec
I remember trying this before in rails 2.3.8 and it was much faster

Hi, you need to provide much more information? For example, application
mode (i.e. production, development, and so on), operating system, and so
on.

-Conrad

It's running in production mode on a Ubuntu 10.10 system on a Linode 512
(http://www.linode.com)

I reverted back to Rails 2.3.8 and Passenger 2.2.15 and I'm now getting
12.1 requests/sec even though the page is now bigger due to the old
obtrusive destroy links

That's still a low number IMO and it's certainly disappointing to see
Rails getting slower with a new release

replacing this

<td><%= link_to 'Show', book %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, :confirm => 'Are you sure?', :method =>
:delete %></td>

with this

<td><a href="/books/<%= book.id %>">Show</a></td>
<td><a href="/books/<%= book.id %>/edit">Editar</a></td>
<td><a href="/books/<%= book.id %>" data-confirm="Are your sure?"
data-method="delete" rel="nofollow">Deletar</a></td>

raises the requests/sec from 4 to 70, wow just wow, those link_to
helpers are really slow

another option would be using a fragment cache, but that's not always
possible

replacing this

<td><%= link_to 'Show', book %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, :confirm => 'Are you sure?', :method =>
:delete %></td>

with this

<td><a href="/books/<%= book.id %>">Show</a></td>
<td><a href="/books/<%= book.id %>/edit">Editar</a></td>
<td><a href="/books/<%= book.id %>" data-confirm="Are your sure?"
data-method="delete" rel="nofollow">Deletar</a></td>

raises the requests/sec from 4 to 70, wow just wow, those link_to
helpers are really slow

My application is suffering for performance problems too. How do you
discover that link_to was responsible for that? Did you use a code
profiler? If yes, which one you've used?

Sorry I have never used any profiler tool, I just read here
(http://www.infoq.com/articles/Rails-Performance) that the link_to
helper can be slow and tried removing it

I suggest you look at the logs to determine if it's the rendering or the
activerecord that is causing the performance problems in your
application

If your database is too big (hundreds of thousands of rows) your queries
may run slow if they are not using the indexes. Use EXPLAIN + the sql to
verify if the indexes are being used

You may also need to use includes or joins to avoid too many queries.
The infoq link i posted before explain how to do this

If the problem is in the rendering try removing some of the helpers such
as link_to and check if performance improves. You may also use fragment
caching to speed up

There's also this page in the rails guides about profilers. I've never
used it so I don't know if it helps
http://guides.rubyonrails.org/performance_testing.html

And also this railscast
http://railscasts.com/episodes/161-three-profiling-tools

Sorry I have never used any profiler tool, I just read here
(http://www.infoq.com/articles/Rails-Performance) that the link_to
helper can be slow and tried removing it

Have you tried erubis? It says to be 10 times faster than ERB. erubis
has a feature that you can preprocess your template code to be just
evaluated one time. Check section 5.2 in
http://www.kuwata-lab.com/erubis/users-guide.05.html#topics-rails.

Has anyone used erubis? I'm curious if using it really brings all this
performance improvement.

I have box prepared to work on rails 2, i installed rails 3 and is very slow so i was blaming rails 3, but then i installed rails 3 in my macbook and is very fast, that means the is something wrong with the environment.