Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance issues with Django

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.

like image 591
Mike Avatar asked Dec 05 '25 11:12

Mike


2 Answers

Django might be slowing down due to several reasons. One of the main reason might be inappropriate or no use of Memcached. Go through the docs to get the idea about the pros and cons of having a cache. You may also find this article useful.

like image 135
Ali Raza Bhayani Avatar answered Dec 07 '25 00:12

Ali Raza Bhayani


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.

like image 45
guettli Avatar answered Dec 07 '25 01:12

guettli