Wisdom of Rails Wizards Study in Best ActiveRecord and Fragment Caching Store

Ruby on Rails

One of the great things about Rails is that when you hit a DB/rendering performance bottleneck, you can often alleviate it with caching. For reducing database calls, many sites use memcached.

At the ActionView layer, if page caching is not an option (for example, most of your pageviews are from authenticated users), fragment caching is also a great option which can give you just the exact HTML or partial that you need.

The Ruby/Rails community, if you have not discovered this yet, is also really helpful!

One of the best lessons I’ve learned over the years is to know when you are not an expert in something. While I’ve become quite adept at hacking together Rails applications over the past year, I still do not know hardware / server administration very well (yet!).

That, of course, is the impetus for this post. Wisdom of Crowds is also a great book, and while we are not following its suggested methodology exactly, an incredible amount can be learned, as you’ll see, from ping’ing multiple sources and using that as a guidepost for the path you ultimately choose.

Question Posed to the Rails Wizards for the Best ActiveRecord and Fragment Cache Store

Disclaimer - I know a lot of different variables can go into this, and if you absolutely cannot answer without some of these variables specified, please let me know!

If the exact hardware that’s used matters, assume we’re talking about your average $200 - $400 per month leased server. (fairly high CPU and 4-6 GB of RAM total, depending on whether memcached is being used)

OS: some flavor of linux or bsd (obviously? =)

For ActiveRecord object pulls, would you mind rating the following (1-3/X, in order of fastest to slowest) in terms of mean response time?

* Filestore (top of the line hard-drives, SCSI or SATA, whatever’s faster these days =)
* MySQL database (again 2-3GB of memory allocated to it for a 20GB+ database, usually maxing out memory usage as is)
* Memcached - 2GB of memory dedicated to memcache
* Anything else we’re missing here, that could be faster or comparable…

For cached HTML fragments, would you mind rating the following (1-3/X, in order of fastest to slowest) in terms of mean response time?

* Filestore (top of the line hard-drives, SCSI or SATA, whatever’s faster these days =)
* Memcached - 2GB of memory dedicated to memcache
* Storing fragments as rows in a MySQL database (2-3GB of memory allocated for a 20GB+ database, usually maxing out memory usage as is)
* Anything else we’re missing here, that could be faster or comparable…

For the cached HTML fragments, let’s assume that the most GB of HTML data we’d ever need to actively cache at anytime is 2GB.

Responses

Why Not Just Benchmark?

Good question! One posed to us by Geoffrey Grosenbach when we first posed our question to him.

My $.02 on benchmarking:

Benchmarking on a Non-live System - you’d need a spare machine, not in use, with the same specifications as your production server. (this is not viable for many small startups)

Benchmarking on a live system - you can run one cache store for a few days/week, and then rotate the cache store. You’d just want to make sure you’re measuring at times when the traffic to your site is roughly similar.

My biggest question/concern about live benchmarking: how do you log the results so that it does not affect performance of your main app? i.e. do you just append benchmarking results to a text-file somewhere, or as a database row?

If you have any benchmarking ideas, notes, or code snippets - of how you might test the “Best ActiveRecord and/or fragment cache store”, please drop them in the comments below! This post will be updated with any helpful links, etc.

Helpful Rails Performance Links

A Look at Common Performance Problems in Rails
Notes from Stefan Kaes’ at RailsConf on Rails Performance
Stefan Kaes’ Blog on Rails Performance
RailsCamp links on RoR Performance
Railsbench
memcached

0 Responses to “Wisdom of Rails Wizards Study in Best ActiveRecord and Fragment Caching Store”


  1. No Comments