Going Django-less on App Engine
Posted June 16th, 2009
I just finished migrating DNZO to run on the webapp framework, after running on Django 1.0 via app-engine-patch for the past several months. I learned a valuable lesson in the process of switching: The webapp framework is really nice and, perhaps more importantly, way faster than using a zipimported version of Django.
It makes sense that using a zipped up copy of Django would be slow: You’re making the webserver inflate a copy of a framework you’re using to serve requests before it can serve them. The most important thing to note here, however, is that App Engine aggressively kills off application instances, especially during the day (when overall system load is presumably higher) — so you don’t get the opportunity to reuse those inflated copies of Django very often.
As a result, I ended up being hit with the initial load penalty frequently: Almost every request during the day took upwards of two full seconds. And that totally sucks.
So, I started out the transition by building a new section of DNZO that uses the webapp framework. Obviously you lose a lot of goodies provided by Django, but the webapp framework provides a basic class structure, some URL mapping and resolution, and it’s generally really nice and easy to extend. It provides nothing I don’t want, and the stuff I do want that it doesn’t have (like straightforward cookie support — really?) is pretty easy to whip up. Before long, I had a basic structure that worked well and I was ready to migrate the rest of DNZO to the same framework.
A few subversion commits later and we have the new version of DNZO: Now with page loads that are about 5 to 10 times faster than when using the zipimport’d version of Django. Fresh page loads usually take between 300 and 500 milliseconds, down from two to three full seconds: the difference between feeling slow and feeling pretty snappy.
Taylor on June 18th, 2009
Respond to this comment
Update: App Engine SDK 1.2.3 includes Django 1.0.2 without zipimport, which would alleviate some of the heft of using the framework.