ActiveRecord: biting the hand that feeds you

October 09 Bullet_white By Derek Bullet_white Comments Comments

Richard Schneeman (better known as Schneems) recently wrote about how he reduced his database server load by 80%...with one simple trick. In the Hacker News discussion that followed, much of the debate was on the merits of using an ORM like ActiveRecord...or not:

hn

In every case I can think of, writing raw SQL is likely to execute queries faster than using ActiveRecord. So, why don't I just write raw conn.exec('SELECT * FROM users') everywhere?

Performance is an important thing, but it's not THE most important thing. In Richard's case, he had a 20 minute blip where response times were significantly higher for his app (a side project, btw):

chart

Some points:

  • The impacted app, CodeTriage, is a side project for Richard. We'd all be happy to have a side project like this running in production. A 20 minute spike in response times isn't a deal-beaker. He has traffic on a side project - this is a great problem!
  • Productivity and momentum trump execution in side projects almost every time. It would take a special developer to get a side project up and running faster without using an ORM.
  • Rather than over-optimizing, Richard has a toolset he can use to optimize when there is a problem. I'd rather launch with some performance quirks that get exposed than over-optimize and waste time on an unused feature.

In our jobs as developers - and in life - our biggest challenge is choosing how to best spend our time. I'm not against raw SQL, but I rely on tools to tell me when I need to drop down to that level.

PS - our database monitoring is in early access. This would have gotten to the problem query quicker, I believe :).

Get notified of new posts.

Once a month, we'll deliver a finely-curated selection of optimization tips to your inbox.

Comments

comments powered by Disqus