这是使用Python 2.6.6和Django 1.2.3在Linux上运行的服务器(我认为是CentOS)。
运行django的python进程突然开始使用100%cpu,直到重新启动为止。这种情况最近才发生过两次,不到一个月前才开始这样做。我在大约7个月内没有对代码做过任何重大改动。
从控制台看输出,它没有任何极端用法。在大约10分钟内只有大约10个查询,直到我相信它开始使用100%cpu。打印的唯一错误是管道错误,我认为可能是有人在减速和关闭连接后使用它。
我重新运行了它放慢速度时的所有查询,它们都运行良好,没有任何问题。
服务器本身在某种意义上仍然可用,但速度极慢。我有一系列的测试,我每天都会跑7分钟左右,但是这个测试的速度很慢,只需要2-3个小时。
如果有人有任何想法,我将非常感激。
另外,你可能会注意到,如果有人可以推荐一个如何监控这类活动的良好实践,那么对于这些问题我是一个新手。
谢谢你的时间!
以下是我提到的输出,它开始100%cpu的时间是〜下午4点
[23/Jul/2012 15:49:55] "GET /CFXsearch/?n=&v=all&e=2012Week30&c=all&r=all&p=all&run=all&pl=all&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=plat&sort=sortName&Soft=CFX HTTP/1.1" 200 67228
[23/Jul/2012 15:50:00] "GET /CFXsearch/?n=&v=all&e=2012Week30&c=all&r=all&p=all&run=all&pl=RH5&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=plat&sort=sortName&Soft=CFX HTTP/1.1" 200 33346
[23/Jul/2012 15:50:05] "GET /CFXsearch/?n=&v=all&e=2012Week30&c=all&r=all&p=all&run=all&pl=SLES10&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=plat&sort=sortName&Soft=CFX HTTP/1.1" 200 33394
[23/Jul/2012 15:54:48] "GET /CFXsearch/?n=&v=all&e=2012Week30&c=all&r=all&p=all&run=all&pl=SLES11&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=plat&sort=sortName&Soft=CFX HTTP/1.1" 200 33394
[23/Jul/2012 15:54:53] "GET /results/?n=&e=2012Week30&c=TGTest&pl=SLES11&p=single&p=defined&p=double&run=default&run=hpmpi&run=mpich&run=mpich2&run=Platform&run=pvm%20parallel&run=serial&sort=sortResult&d=&y=&submitOption=latestsearch&Soft=CFX HTTP/1.1" 200 19350
[23/Jul/2012 15:54:57] "GET /results/?n=&e=2012Week30&c=turboexamples&pl=SLES11&p=single&p=defined&p=double&run=default&run=hpmpi&run=mpich&run=mpich2&run=Platform&run=pvm%20parallel&run=serial&sort=sortResult&d=&y=&submitOption=latestsearch&Soft=CFX HTTP/1.1" 200 36729
[23/Jul/2012 15:59:40] "GET / HTTP/1.1" 200 11111
[23/Jul/2012 15:59:40] "GET /site_media/style.css HTTP/1.1" 304 0
[23/Jul/2012 15:59:45] "GET /CFXsearch/ HTTP/1.1" 200 25637
[23/Jul/2012 15:59:45] "GET /site_media/jquery-1.2.6.min.js HTTP/1.1" 304 0
[23/Jul/2012 15:59:45] "GET /site_media/sorttable.js HTTP/1.1" 304 0
[23/Jul/2012 16:00:04] "GET /CFXsearch/?n=&v=14.5&e=all&c=solver54&r=all&p=all&run=all&pl=all&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=plat&sort=sortName&Soft=CFX HTTP/1.1" 200 402737
[23/Jul/2012 16:00:19] "GET /results/?n=&e=2012Week29&c=solver54&pl=SLES11&p=single&p=defined&p=double&run=default&run=hpmpi&run=mpich&run=mpich2&run=Platform&run=pvm%20parallel&run=serial&sort=sortResult&d=&y=&submitOption=latestsearch&Soft=CFX HTTP/1.1" 200 1557488
[23/Jul/2012 16:02:48] "GET /CFXsearch/?n=&v=14.5&e=all&c=solver54&r=all&p=all&run=all&pl=all&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=ex&sort=sortName&Soft=CFX HTTP/1.1" 200 408388
[23/Jul/2012 16:03:01] "GET /CFXsearch/?n=&v=14.5&e=all&c=solver54&r=all&p=all&run=all&pl=all&m=all&o=all&d1=&d2=&submitOption=comparing&compareBy=plat&sort=sortName&Soft=CFX HTTP/1.1" 200 402737
Traceback (most recent call last):
File "/home/install2/testingDatabase/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 281, in run
self.finish_response()
File "/home/install2/testingDatabase/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 321, in finish_response
self.write(data)
File "/home/install2/testingDatabase/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 400, in write
self.send_headers()
File "/home/install2/testingDatabase/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 465, in send_headers
self._write(str(self.headers))
File "/home/install2/testingDatabase/Python-2.6.6/Lib/socket.py", line 318, in write
self.flush()
File "/home/install2/testingDatabase/Python-2.6.6/Lib/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
Traceback (most recent call last):
File "/home/install2/testingDatabase/Python-2.6.6/Lib/SocketServer.py", line 560, in process_request_thread
self.finish_request(request, client_address)
File "/home/install2/testingDatabase/Python-2.6.6/Lib/SocketServer.py", line 322, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/install2/testingDatabase/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 562, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/home/install2/testingDatabase/Python-2.6.6/Lib/SocketServer.py", line 618, in __init__
self.finish()
File "/home/install2/testingDatabase/Python-2.6.6/Lib/SocketServer.py", line 661, in finish
self.wfile.flush()
File "/home/install2/testingDatabase/Python-2.6.6/Lib/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
[23/Jul/2012 16:09:59] "GET /PolyflowSummary/ HTTP/1.1" 200 7561
[23/Jul/2012 16:17:42] "GET /?soft=CFX HTTP/1.1" 200 11112
[23/Jul/2012 16:17:44] "GET /?soft=CFX HTTP/1.1" 200 11112
[23/Jul/2012 16:18:06] "GET /site_media/style.css HTTP/1.1" 200 432
[23/Jul/2012 16:18:23] "GET /site_media/style.css HTTP/1.1" 200 432
[23/Jul/2012 16:18:23] "GET /site_media/favicon.ico HTTP/1.1" 200 1718
答案 0 :(得分:3)
您可以连接到该进程并附加调试器。我以前做过这个,它非常有用。 my full notes are here,但删节版本是:
安装this以便gdb“理解”python
使用gdb -p PID
(PID
或类似的ps
)进行连接
在gdb中生成一个堆栈跟踪,你会看到你正在吃掉CPU的确切位置。
原始信用 - Showing the stack trace from a running Python application(事实上,在输入所有内容之后,也许这是相关问题的欺骗?我猜问题是不同的,即使答案是相同的......)