My Django application is insanely slow, I want to figure out what is taking time :
I tried Django-debug-toolbar
but was unable to find a panel that can give me the break-up of the load time.
My requirements:
- A stack-trace type output with time of execution for each module called to render the page.
- I want to realize what part of the whole page rendering process is taking the time ?
- Also, what part is consuming how much CPU [ MOST IMPORTANT ] ?
Can django-debug-toolbar
do that ? [ What panel ? ]
Any other django-app that can do that ?
It's not profiling , but i generally simply use a view to calculate the execution time , it works also for views that need user login, it displays execution time in a simple page
it's a good start i think , hope it will help someone
Finally figured out a way to profile my django webapp :
Following 2 django snippets provide
middleware
that profile the whole flow and outputs if request hasprof
inGET keys
:http://djangosnippets.org/snippets/727/ [ Uses cProfile ]
http://djangosnippets.org/snippets/186/ [ Uses hotshot ]
Plain and simple profiling - Saved my day !
django-silk can help.
pip install django-silk
settings.py
:urls.py
:You can then browse in your internet browser to
/silk
to find the page requested there.I would recommend writing some integration tests instead, or at least using the built in testing client to automate requests and put lots of debugging statements in the views
Django has a built in testing client:
And then in your view:
Automating the process of making requests and being able to replicate them again and again while you make small changes is how you will improve your code. CPU time can be worked out if you measure the time it takes to run each function. It won't take you long to hone in on the part that is actually chewing up resources.
You can try the profiling panel of the django-debug-toolbar (make sure you use the application's latest version from github). Enable the panel like so in your settings.py:
This existence of this panel is not documented on the readme of django-debug-toolbar; that's why I answer here in the first place.
EDIT: If you're using django-debug-toolbar v1.0 and above the panel has been renamed to
debug_toolbar.panels.profiling.ProfilingPanel
and is now documented here http://django-debug-toolbar.readthedocs.org/en/1.0/panels.html#non-default-built-in-panels. It's still not enabled by default.