Epoll bug(?)消耗100%CPU(Python,PyMongo,Tornado)

时间:2012-10-04 18:09:57

标签: python mongodb tornado

我正在运行带有tailable游标的上限集合(mongodb)。它运行良好,直到 - 突然,在20-300秒后 - 它跳到100%cpu和mongostat显示getmore完全停止。

我在python脚本上做了cProfile,发现了这个:

    1    0.000    0.000    0.000    0.000 {method 'lstrip' of 'str' objects}
   77    0.000    0.000    0.000    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
   11    0.000    0.000    0.000    0.000 {method 'partition' of 'str' objects}
   34  242.726    7.139  242.726    7.139 {method 'poll' of 'select.epoll' objects}
   12    0.000    0.000    0.000    0.000 {method 'pop' of 'dict' objects}

所以epoll明确地站在这里,而其他一切看起来都很正常,这很可能是导致挂断和CPU崩溃的原因。

但它是什么意思? (也许提示here?)发生了什么,我该如何解决?

这是最有可能触发epoll的代码:

while WSHandler.cursor.alive:
        try:
            doc = WSHandler.cursor.next()

在一个单独的线程中运行(threading.thread())。

(我正在使用Tornado WebSocket,三个用于插入db的mongodb脚本,以及一个用于拖尾光标的脚本.cProfile来自拖尾脚本。)

1 个答案:

答案 0 :(得分:1)

这是因为在三个不同的脚本中使用Tornado运行了三个IOLoops。这会使IOLoop使用的epoll变得混乱。解决了将所有三个脚本放在一个IOLoop

运行AWS micro instance!

相关问题