Rails Console Running Incredibly Slowly When Editing Text

Pasting text into IRB is incredibly slow. Readline issue?

It looks like REE's installer.rb adds -I/opt/local/include and -L/opt/local/lib -Wl, linker flags. After clearing out those flags, REE compiles successfully without including the 2nd readline library, but the resultant ruby will not execute due to other load errors.

A solution is to temporarily remove MacPorts while installing REE so that it doesn't link to the extra readline library.

  1. Quit all processes that are accessing MacPorts files. You can see which ones are running with sudo lsof | grep /opt/local.
  2. sudo mv /opt/local /opt/localbak
  3. Open a new terminal, then compile and install REE
  4. sudo mv /opt/localbak /opt/local

After that, the REE installation will work properly alongside MacPorts.

Other solutions:

  • Uninstall MacPorts permanently, and install REE as usual
  • Use MRI or another version of Ruby instead of REE

edit: I've noticed that installing REE with ruby-build doesn't exhibit this problem

Ruby on Rails website is slow; could it be the SQL queries?

I see two problems: a lack of SQL indexes, and too many calls to Post.all.

Your slow queries involve WHERE published = ?. If posts.published is not indexed, this will have to scan the entire table, not just the published posts. You also tend to sort by posts.published_at and without an index this will also be slow.

To fix this, add an index on posts.published and posts.published_at in a migration.

add_index(:posts, :published)
add_index(:posts, :published_at)

You can read more about indexes in the answers to What is an index in SQL?


Using Post.all or Post.published means loading every post from the database into memory. If you're not using them all, it's a huge waste of time.

For example, it's unwieldy to display every post on your index and home pages. Instead you should use pagination to fetch and display only a page of posts at a time. There are gems for this such as kaminari and will_paginate as well as larger administrative solutions such as ActiveAdmin. And if you don't like page links, if you look around you can find examples of using them for "infinite scroll".


Finally, you can add caching. Since your site isn't going to update very frequently, you can cache at various levels. Have a read through Caching with Rails: An Overview.

But caching brings its own problems. Consider if you need it after you do basic performance optimizations.

Validate value in text_area

You can instruct the user to wrap the code section around a specific keyword..for instance {code}
then in your template you can extract and decorate the the code section:

<p> <pre><%= comment.content.scan(/{code}(.*?){code}/m)  %></pre></p>

How can I find out why my app is slow?

If it is just slow on the first time you load it is probably because of passenger killing the process due to inactivity. I don't remember all the details but I do recall reading people who used cron jobs to keep at least one process alive to avoid this lag that can occur with passenger needed to reload the environment.

Edit: more details here

Specifically - pool idle time defaults to 2 minutes which means after two minutes of idling passenger would have to reload the environment to serve the next request.

rails console doesn't load

You could be running out of memory on your server and so the machine can't respond to you. If you are running mongrel then get monit onto it to limit the memory it can use and restart where necessary.

If you are using Passenger, try limiting the amount of instances, and if you have already done that look up a script that kills passenger instances when too big via a cron job.

If it's not a memory issue then I'd probably need more information.



Related Topics



Leave a reply



Submit