7

I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this?

Thanks!

Martin

Hoff
  • 38,776
  • 17
  • 74
  • 99

4 Answers4

19

FWIW, you should do the profiling, but when you do I'll bet you find that the answer is "polling for changes to your files so it can auto-reload." You might do a quick test with "python manage.py runserver --noreload" and see how that affects the CPU usage.

Carl Meyer
  • 122,012
  • 20
  • 106
  • 116
4

Hit Control-C and crash the process. It will probably crash somewhere that it's spending a lot of time.

Or you could use a profiler.

wisty
  • 6,981
  • 1
  • 30
  • 29
  • 1
    You might think this is a joke, but seriously, this can be a fast way to find out where your program is spending a lot of time. Beyond this fast-and-brutal approach, use a profiler. – steveha Nov 18 '09 at 04:13
3

http://docs.python.org/library/profile.html

That's the standard approach.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
1

The standard approach is to use a profiler. If, for some reason you can't (such as there is no profiler available in the Apache modpython that is running your Django) your best bet might be simply to instrument your program with logging. Watch the messages from your program, and see what you can learn from them.

If you see a message "Entering CalculateFoo()" and then five seconds later "Exiting CalculateFoo()" that's a major clue there. Or if one particular function keeps printing over and over and over.

Here's a short discussion of Python logging.

Python debugging tips

EDIT: I just noticed that you specifically said this is on your Windows 7 desktop. So, use a profiler. But I'll leave this answer up to cover the general case.

Community
  • 1
  • 1
steveha
  • 74,789
  • 21
  • 92
  • 117