Performance issues with Django
Question: I'm trying to track down some performance issues I have had with Django. There
seems to be a 600-800 ms delay from the time I click refresh to the time the
browser gets a response.

I set up a simple view and the profile middleware and this is the view and
results:

the view function:

    
    
    def test(request):
        return HttpResponse("It works")
    

The profile results( i used <http://www.djangosnippets.org/snippets/186/>):

    
    
    9 function calls in 0.000 CPU seconds
    
    Ordered by: internal time, call count
    
    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/http/__init__.py:487(__init__)
        1    0.000    0.000    0.000    0.000 /home/mysite/mysite/mysite/map/views.py:19(test)
        1    0.000    0.000    0.000    0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/http/__init__.py:532(__setitem__)
        3    0.000    0.000    0.000    0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/http/__init__.py:517(_convert_to_ascii)
        2    0.000    0.000    0.000    0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/utils/functional.py:274(__getattr__)
        1    0.000    0.000    0.000    0.000 /usr/lib/python2.6/Cookie.py:573(__init__)
        0    0.000             0.000          profile:0(profiler)
    
    
    ---- By file ----
    
     tottime
    0.0%   0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/utils/functional.py
    0.0%   0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/http/__init__.py
    0.0%   0.000 /usr/lib/python2.6/Cookie.py
    0.0%   0.000 /home/mysite/mysite/mysite/map/views.py
    
    ---- By group ---
    
      tottime
    0.0%   0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/utils
    0.0%   0.000 /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/http
    0.0%   0.000 /usr/lib/python2.6
    0.0%   0.000 /home/mysite/mysite/mysite/map
    

So with that, the profiler isn't returning any numbers, yet Chrome reports a
647 ms delay from requesting the resource to actually getting any response. My
ping time to the server is about 50 ms. Any ideas how I can get better
profiling so I can see where in Django is causing this slowdown?

My WSGI config. I'm using Cherokee with uwsgi.

    
    
    import os
    import sys
    
    path = '/home/mysite/mysite/mysite/'
    if path not in sys.path:
        sys.path.append(path)
    
    
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

I see this delay(within 20 ms) on different computers as well as different
networks. I'm also seeing it when I just use manage.py runserver.


Answer: Looks like you python interpreter gets reloaded for every request. My guess:
The delay happens before the profiling. If you use mod_wsgi, what is your
maximum-requests setting? What does your wsgi configuration look like?

Or, you use a lot of JavaScript and the delay is in your browser.

