Wednesday, September 23, 2009

How To Turn Web Development Around (Part 1)

Something is bothering me this past week. I've been taking some stabs at reducing the maximum render time of a site, when the caches are all empty. I cache certain components and queries, but when the caches are primed the render time is under 500ms and I think that's pretty good. That worst case senario, however, is just not acceptable. Worse than a couple seconds. That isn't time that should be taken. I dug in and found a really bad pattern.

It isn't hard to make a page faster, but the default is to be as slow as possible. We have to understand this pattern. I am looking at this in relation to Django, but I have a feeling there are similar patterns other places.

The common tagging application is a good example. It makes it really easy to tag objects, count them, query by them, and build those clever little clouds. You're given lots of new wrappers for all the common tag-related queries you'd need to do. This may be a source of the problem. We've gotten into a rut of complacency with components that give us more rope than we need to hang ourselves. Abstraction hides the cost of operations.

Are we asking the really simple question: Why are we pulling when we could be pushing? With one of the most read-heavy information systems in the world, everything revolves around the needs and demands of the almighty HTTP request. A browser asks a question and then we go and figure out the answer. We are, by default, building our software around the read when we should be building around the write.

Caching is lazy. We should be pro-active. How often is a tag cloud going to change? Only when the taggings change, of course. No page request should ever generate a tag cloud. We should be building the cloud, as a static html snippet, every time the tags change. When we're actually rendering a page, we should just insert that current snippet.

The problem is that we make lots of tiny little increases in the pulling we do and we do it all over the place. We hide it behind innocent looking functions and properties and end up using a few of those inside one element that gets repeated and it piles up. The amount of work in one page becomes insane, for what that page is. The problem isn't that it is so difficult to do something better, but that the default should be better. I would like like some practical answers to making that default better.

1 comment:

Dave Richards said...

Sure, but you shouldn't blame the tag app for that. The best way to make it easy to build a cacheable snippet is the best way to plonk it straight into page.

With great power and that...

It's definitely something web frameworks and developers should pay far more attention to, though. Django, Rails and their ilk do make ignoring scalability as easy as PHP made ignoring good app design.

I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive