performance - Django Slow on Production, fast in test -
our web sites hosted django extremely slow on production server: database access seems slow (mysql), downloading file slow (i tried x-sendfile, without impact).
profiling using based on this snippet, heaviest:
ncalls tottime percall cumtime percall filename:lineno(function) 11570 0.577 0.000 0.577 0.000 /var/lib/python-support/python2.6/mysqldb/times.py:43(datetime_or_none) 5786 0.500 0.000 0.617 0.000 /usr/local/lib/python2.6/dist-packages/django/db/models/base.py:244(__init__) 5796 0.205 0.000 0.576 0.000 /usr/local/lib/python2.6/dist-packages/django/forms/widgets.py:411(render_option) 8 0.190 0.024 1.014 0.127 /var/lib/python-support/python2.6/mysqldb/cursors.py:282(_fetch_row) 21.6% 0.577 /var/lib/python-support/python2.6/mysqldb/times.py 19.4% 0.520 /usr/local/lib/python2.6/dist-packages/django/db/models/base.py 9.5% 0.253 /usr/local/lib/python2.6/dist-packages/django/forms/widgets.py 7.4% 0.199 /var/lib/python-support/python2.6/mysqldb/cursors.py 33.0% 0.882 /var/lib/python-support/python2.6/mysqldb 32.6% 0.873 /usr/local/lib/python2.6/dist-packages/django/db 15.4% 0.413 /usr/local/lib/python2.6/dist-packages/django/forms 10.5% 0.280 /usr/local/lib/python2.6/dist-packages/django/utils
this call above run on admin page.
what do: - update mysql - update whole django framework (still running on 1.1)
but think, there must else why slow. ideas?
it should slow first time on production server following access pages behavior should different if django memcached example.
install django-memcached on production server settings.py: cache_backend ="memcached://127.0.0.1:11211/" # change ip server ip cache_timeout =60*60 #to keep items in cache it's # if wish cache data permanently in high demand views.py : django.core.cache import cache project.settings import cache_timeout # example of how use cache in methods def method(request): model_cache_key = request.path c = cache.get(model_cache_key) if not c: c=get_object_or_404(model,id=self.id) cache.set(model_cache_key,c,cache_timeout) #end of use cache here foo=c.modelname_set.all() # more code here return #whatever want