Archive for June, 2008

Issues with Active Scaffold and Rails 2.1, Solved

Saturday, June 28th, 2008

If you are looking to upgrade to Rails 2.1 and you are using Active Scaffold, be aware it still has a few rough edges.

Make sure you install the Rails 2.1 branch of Active Scaffold:


git clone git://github.com/activescaffold/active_scaffold
cd active_scaffold
git branch -r (just lists the branches)
git checkout origin/rails-2.1

(Check out the full thread for Rails 2.1 and Active Scaffold compatibility)

Second, I had to patch vendor/plugins/active_scaffold/lib/extensions/generic_view_path.rb. On line 53, make it look like this:


if !@template.controller.is_a?(ActionMailer::Base) && @template.controller.class.uses_active_scaffold?

I had to add !@template.controller.is_a?(ActionMailer::Base) &&

All my tests are now passing!

I still love Active Scaffold, even though it’s a bit behind the times.

Scalable Counters for Web Applications

Saturday, June 28th, 2008

So you need to provide a count or counter for your web application, but you want it to scale. The naive approach would be to simply select count(*) from table. That will fail under load because it requires scanning your entire collection.

The first question you need to ask is, Do you need exact counts or will approximate counts be good enough? I bet in many situations, an approximate count will be perfectly reasonable. Think about the use case of tracking web hits. When you’re talking about millions of hits, what is the difference between 1,000,000 and 1,000,001? Of course, only your business expert will know if approximate or exact answers are required. The decision, though, is crucial because it’s the difference between an easy implementation and a hard (costly) implementation.

Let’s say, for the purposes of this article, that you’ll need very close to accurate counts, plus you need to scale a lot. The first step is to pre-calculate the count, and cache the results. When a new web hit occurs, grab the current count, add one, and put it back. This approach will scale for a while, but the chance of missing a count goes up as load goes up. Because we’re not explicitly locking on the row (which can be expensive), the last person to write the record back to the database wins.

The next option is to wrap the “grab record, increment, put record back” inside a locking transaction. This will ensure that only one writer can access the counter at a time. This ensures an accurate count, but will greatly slow down the site as contention around the single counter increases.

The third option, and the best option, is to split the counter up into smaller counters. When it’s time to get the full, single count, simply grab all the counter partitions and add them up. For very high loads, increase the number of partitions. The theory is it’s quick to add up 100 partitions, while you’re providing 100 different counters to lock around.

How do you pick which partition to increment? One easy way is to create a hash of the timestamp (or some other part of the request that changes frequently) of the request, and mod it on the number of partitions in the system. The theory here is you’ll be spreading the load across the partitions as the number of concurrent requests increases.

In any scalable web system, reads should be by key and writes are expensive. Do whatever you can to read a single object by a key, and minimize your writes. Minimize the contention around objects in the data store, too. Realize that ad hoc queries can almost always be implemented by pre-calculating the answers, so that an ad hoc query is simply retrieving a record by a key (instead of scanning through all rows, computing the answer as you go.)

For more on this technique, I recommend the excellent video Builing Scalable Web Applications with Google App Engine.

Announcing Whatever Is Fine With Me, The Easiest Friend Polling Site

Friday, June 27th, 2008

World, meet Whatever Is Fine With Me. I think you two will really hit it off.

Whatever Is Fine With Me is a easy, quick polling or voting application that you can use to find an answer to a question faster than you can sing the Canadian national anthem.

The site was created after we found it difficult to make ad hoc decisions among our group of friends. Most famous is “where are we going to lunch?” Of course, the most common answer to that is: “whatever is fine with me.”

I wanted to create a site that is task focused, fast to use, and with as close to a zero barrier of entry as possible. I am sick of creating accounts on sites, so my first rule was banish account signups. It’s still fairly secure, as each page is identified by a very hard to guess URI.

Why use Whatever Is Fine With Me?

  • No login required for you or your friends
  • Extremely fast and easy
  • Totally and completely free

I’d love to hear feedback, please post any comments to the Whatever Is Fine With Me Forums. If enough people begin to use it, I’d be happy to add features.

Some new features I was thinking about or have been suggested:

  • Make “whatever is fine with me” an explicit option when choosing your votes
  • Remember your friend list, so you don’t have to type it in multiple times
  • Remember all your past questions

So please give it a shot and I hope it’s useful!

(I’m posting this to see if anyone wants to use it. I’m really hoping so, so I can justify spending time on it.)

And while Whatever Is Fine With Me is perfect for asking your friends questions, if you want to ask the world a question, you definitely want to check out Ask 500.

Proposed Enhancements For Web Browsers

Tuesday, June 10th, 2008

I was listening to Muxtape (quite possibly the best user interface for a web application). I use Firefox and I have lots of tabs open. Muxtape is playing the background, in another tab. Sometimes a song comes up on Muxtape that I don’t like and wish I could skip, however, I’m in “the flow” and don’t want to leave my current tab or application.

I’d like to propose an enhancement for web browsers to simplify the interaction with tabs in the background. Web applications should be able to specify a small menu of commands which can be executed from the tab without having to pull that tab into the foreground.

I’d love to be able to right-click on the tab and see options such as “Skip”, “Pause”, “Back”, or “Repeat”. This context relative menu is specific to each tab, and by clicking on any of the options, a Javascript function would be called.

I envision this as easily specified as part of the larger effort of HTML 5 to address modern day requirements of web applications to offer a richer experience.