Hacker News new | past | comments | ask | show | jobs | submit login

The problem is not that you need better hardware for this scenario, you just need a better programmer.

"Not helping matters was the fact that the sysadmins found some public pages that went into MySQL 1500 times with 1500 separate queries (instead of one query returning 1500 rows)."

Looks like someone forgot to use :include on some finders. Let's say you have 1000 users with an address each. This will produce 1000 SQL queries:

  User.all.each do |user|
    p user.address.street_name
  end
This, however, will only issue two queries:

  User.all(:include =>:address).each do |user|
    p user.address.street_name
  end



Well, if you know your way around RoR, the first thing you do after most development is done, is to load the query_reviewer plugin to get an automated profiling on each page, and take steps to limit the number of queries. Either by memcached, or by adding indexes. It's not unusual to go from a couple of hundred queries per page to less than 10 per page in a day of optimizing.


The classic ActiveRecord 1+N trap.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: