Elements or Lower

Mon, 18 Aug 2008

Serving static files with Django and AWS - going fast on a budget

Serving static files with Django and AWS - going fast on a budget: This is the kind of problem where mod_perl shines. We have a similar approach for a caching layer on Window on Woking, but we stop short of actually serving static HTML files from disk (though it would certainly be worth exploring this in the future).

A simple mod_perl handler, early in the Apache request cycle, determines whether the visitor is authenticated and whether a cached copy of the requested resource exists. If the cache can be served, it is, and no further dynamic code is run (except for our logging phase, once the content has already been dispatched).

Because of mod_perl’s tight integration with Apache, this handler is pre-loaded into memory, and the database connection can also be pre-loaded, so there’s next to no initialisation overhead. Were the cached content a static file on disk, it wouldn’t even require the database call, just a file test.