December 16
django-orm-scaling
There are couple of things you got to keep in mind when you are using django to build a large scale applications, Django ORM is super cool and awesome but its not designed for large scale applications. Django ORM is written generic to suit different database and you have to careful in using ORM. It tend to fire multiple queries which can be ideally be done in one, when you indented to scaling a app the first and fore most you have to things and plan is the database. Its OK to have de-normalized design, very frequently tables should avoid multiple joins
If you are not sure about queries django is firing make sure you check connection.queries.
>>> User.objects.get_or_create(username='foo')
(<User: foo>, True)
>>> from django.db import connection
>>> connection.queries
[{'time': '0.060', 'sql': u'SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` WHERE `auth_user`.`username` = foo '}, {'time': '0.014', 'sql': u'INSERT INTO `auth_user` (`username`, `first_name`, `last_name`, `email`, `password`, `is_staff`, `is_active`, `is_superuser`, `last_login`, `date_joined`) VALUES (foo, , , , , False, True, False, 2009-12-16 10:46:52, 2009-12-16 10:46:52)'}]
Django ORM executed 2 queries first query to select with the username and second to insert damn! sounds ridicules doesn't it? If you are using MySQL there is a better way to do INSERT IF NOT EXIST
connection.queries tells the last executed query, there are quite a few tools which would help in knowing the performance Cprofile, If you are building a really scalable website I would suggest you taking a look at David Carmer talk about high performance django application.