Django development server CPU intensive - how to analyse?

╄→гoц情女王★ 提交于 2019-12-23 09:04:06

问题


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


回答1:


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.




回答2:


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.




回答3:


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

That's the standard approach.




回答4:


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.



来源:https://stackoverflow.com/questions/1750676/django-development-server-cpu-intensive-how-to-analyse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!