My django application has become painfully slow on the production. Prolly it is due to some complex or unindexed queries.
Is there any django-ish way to profile my application?
My django application has become painfully slow on the production. Prolly it is due to some complex or unindexed queries.
Is there any django-ish way to profile my application?
Try "Django Toolbar": http://github.com/robhudson/django-debug-toolbar It will show you what queries are executed on each page and how much time they take. A really useful, powerful and easy to use tool.
Also, read recommendations about Django performance in docs: http://docs.djangoproject.com/en/dev/topics/db/optimization/
And here: http://jacobian.org/writing/django-performance-tips/
Just type "django-profiling" on google, you'll get these links (and more):
http://code.djangoproject.com/wiki/ProfilingDjango
http://code.google.com/p/django-profile/
http://www.rkblog.rk.edu.pl/w/p/django-profiling-hotshot-and-kcachegrind/
Personally I'm using middleware approach - i.e. each user can toggle "profiling" flag stored in session, and if my profiling middleware notices that flag being set, it uses Python's hotshot module like this:
def process_view(self, request, view_func, view_args, view_kwargs):
# setup things here, along with: settings.DEBUG=True
# to get SQL dump in connection.queries
profiler = hotshot.Profile(fname)
response = profiler.runcall(view_func, request, *view_args, **view_kwargs)
profiler.close()
# process results
return response
EDIT: For profiling SQL queries http://github.com/robhudson/django-debug-toolbar mentioned by Konstantin is a nice thing - but if your queries are really slow (probably because there are hundres or thousends of them), then you'll be waiting insane amounts of time until it gets loaded into browser - and then it'll be hard to browse due to slowliness. Also, django-debug-toolbar is by design unable to give an useful insight into the internals of AJAX requests.