Real-life situation:

    I deployed a week's worth of code changes to production. Upon
restart, site wouldn't load anymore. Nothing but a 404 error.

Long story short:

    By using Django's logging, I discovered that a query was being run
tens thousands of times -- obviously in a loop. I inserted
traceback.format_stack() logging into Django's code temporarily to
pinpoint the culprit. I discovered that when the URLs were imported
and admin.autodiscover() was called it imported an admin.py file,
which imported a models.py file, which imported a forms.py file, which
contained a Form subclass that was doing something woefully
inefficient with a "choices" kwarg. Optimized query, moved it into the
form's __init__, problem solved.

But in the meantime:

    The site was down for about a half-hour in the time it took me to
work around the problem by realizing that gunicorn workers were timing
out and increasing the timeout in my supervisord config. And that was
just a quick & dirty "fix" to give me time to find the real problem,
which took considerably longer.

What I need:

    What's the best way to start looking for a problem like this? I
started with pdb, but it's a ridiculously inefficient tool for this
kind of problem, and I went off in the wrong direction a couple of
times trying to zero in on the issue. It's just a pleasant coincidence
that when I checked the log there was a huge number of queries which
set me off in the right direction.

    Maybe part of the problem is that I'm not familiar with Django's
bootstrapping process, so I don't know where to sprinkle logging
statements to isolate the issue.

    I'm looking for a general solution. Don't assume the issue is
necessarily ORM-related or anything in particular. Just that something
is slow and I'm trying to find out what it is.

Thanks in advance for any wisdom and hard-earned experience you can share.

Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to