Further development on Singleshot

I still don’t know what was causing the weird lossage on the new photos site but it appears to be related to performance. I’ve seen evidence of proxy servers between me and the app and they appear to get cranky if the request is taking too long. The evidence, besides the sometimes failing to complete requests, includes bizarre failures where the browser receives multiple requests muddled together. It looks like the proxy sometimes just mangles the HTTP/1.1 connection. I did find a number of places to speed the site up, though, which also appears to have made the failures happen significantly less.

Roughly in order, I:

  • Modified my push script to make sure everything is compiled to .pyc files after pushing new code. Oops. Python is not so fast when it has to compile everything from source on each request.
  • Profiled various types of requests and made some tweaks to speed things up.
  • Ran out of cheap tweaks and radically redesigned the data/view model to allow me to cache Image metadata more effectively. There’s less code and it’s more clearly what I meant, too.

I got between 50% and 60% speed-up from all of these changes. I was prepared to change how granular the metadata cache to make it faster to load but it turned out the next hotspot after all that other was is … Python’s initialization and module loading. Around 40ms to load the metadata cache. A pittance to execute the request and emit the template. And around 280ms of module loading.

Sigh. It’s much snappier now, but it looks like I’m nearly out of options without using FastCGI or some other process persistance.