2012-05-03 9 views
7

私はredis' pubsubを使ってイベントを配信するためにtornado-redis(基本的にはbrükvaというフォークがadispの代わりにtornado.genインターフェイスで動作するように少し変更されています)を使用しようとしています。pymplerを使用して竜巻 - 赤字のメモリリークを追跡/修正する方法はありますか?

だから、私はちょっとしたスクリプトを書いて、触発されたものをthis exampleでテストしました。残念ながら

import os 

from tornado import ioloop, gen 
import tornadoredis 


print os.getpid() 

def on_message(msg): 
    print msg 

@gen.engine 
def listen(): 
    c = tornadoredis.Client() 
    c.connect() 
    yield gen.Task(c.subscribe, 'channel') 
    c.listen(on_message) 

listen() 

ioloop.IOLoop.instance().start() 

は、私がPUBLISHredis-cliメモリ使用量を上昇に保たれて。

メモリ使用量をプロファイルするために、最初にguppy-peを使用しようとしましたが、python 2.7(はい、トランクを試しても問題ありません)で動作しないため、pymplerに戻りました。

import os 

from pympler import tracker 
from tornado import ioloop, gen 
import tornadoredis 


print os.getpid() 

class MessageHandler(object): 

    def __init__(self): 
     self.memory_tracker = tracker.SummaryTracker() 

    def on_message(self, msg): 
     self.memory_tracker.print_diff() 

@gen.engine 
def listen(): 
    c = tornadoredis.Client() 
    c.connect() 
    yield gen.Task(c.subscribe, 'channel') 
    c.listen(MessageHandler().on_message) 

listen() 

ioloop.IOLoop.instance().start() 

PUBLISHエド、私はいくつかのオブジェクトが解放されなかったことを見ることができるたびに:これらのオブジェクトが作成される場所

          types | # objects | total size 
===================================================== | =========== | ============ 
               dict |   32 |  14.75 KB 
               tuple |   41 |  3.66 KB 
                set |   8 |  1.81 KB 
             instancemethod |   16 |  1.25 KB 
               cell |   22 |  1.20 KB 
          function (handle_exception) |   8 | 960  B 
            function (inner) |   7 | 840  B 
              generator |   8 | 640  B 
          <class 'tornado.gen.Task |   8 | 512  B 
          <class 'tornado.gen.Runner |   8 | 512  B 
    <class 'tornado.stack_context.ExceptionStackContext |   8 | 512  B 
               list |   3 | 504  B 
                str |   7 | 353  B 
                int |   7 | 168  B 
          builtin_function_or_method |   2 | 144  B 
               types | # objects | total size 
===================================================== | =========== | ============ 
               dict |   32 |  14.75 KB 
               tuple |   42 |  4.23 KB 
                set |   8 |  1.81 KB 
               cell |   24 |  1.31 KB 
             instancemethod |   16 |  1.25 KB 
          function (handle_exception) |   8 | 960  B 
            function (inner) |   8 | 960  B 
              generator |   8 | 640  B 
          <class 'tornado.gen.Task |   8 | 512  B 
          <class 'tornado.gen.Runner |   8 | 512  B 
    <class 'tornado.stack_context.ExceptionStackContext |   8 | 512  B 
               object |   8 | 128  B 
                str |   2 | 116  B 
                int |   1 |  24  B 
               types | # objects | total size 
===================================================== | =========== | ============ 
               dict |   32 |  14.75 KB 
               tuple |   42 |  4.73 KB 
                set |   8 |  1.81 KB 
               cell |   24 |  1.31 KB 
             instancemethod |   16 |  1.25 KB 
          function (handle_exception) |   8 | 960  B 
            function (inner) |   8 | 960  B 
              generator |   8 | 640  B 
          <class 'tornado.gen.Task |   8 | 512  B 
          <class 'tornado.gen.Runner |   8 | 512  B 
    <class 'tornado.stack_context.ExceptionStackContext |   8 | 512  B 
               list |   0 | 240  B 
               object |   8 | 128  B 
                int |   -1 | -24  B 
                str |   0 | -34  B 

は今、私はメモリリークが実際にそこに知っていることを、どのように私は追跡していますか?私はhereを始めるべきだと思いますか?

答えて

4

Tornadoをバージョン2.3にアップグレードすると、この問題が解決するはずです。

ExceptionStackContextが非常に迅速に漏れていたのと同じ問題が発生しました。このバグレポートに関連していたのはhttps://github.com/facebook/tornado/issues/507で、このコミットで修正されました:https://github.com/facebook/tornado/commit/57a3f83fc6b6fa4d9c207dc078a337260863ff99。 2.3へのアップグレードは、私の問題を解決しました。

+0

この問題を私に指摘してくれてありがとう。私はアップグレードし、リーク+減速は去った:) –

関連する問題