内存泄漏与gunicorn gevent流响应和zeromq

时间:2013-09-17 14:27:03

标签: wsgi zeromq gevent gunicorn pyzmq

我正在与gevent工作者一起为枪支提供MJPEG流媒体响应。一切正常,但当客户端终止连接时,似乎zeromq订阅者没有GC,只是继续接受图像数据。

以下是gunicorn的内存使用情况:

memory leak

以下是wsgi app的源代码:

from gevent_zeromq import zmq


context = zmq.Context()


def app(environ, start_response):
    if environ['PATH_INFO'] == '/':
        subscriber = context.socket(zmq.SUB)
        subscriber.connect("ipc:///tmp/camera")
        subscriber.setsockopt(zmq.SUBSCRIBE, "")
        boundary = "--ipcamera"

        status = '200 OK'
        headers = [('Content-type', 'multipart/x-mixed-replace;boundary={}'.format(boundary))]
        start_response(status, headers)

        def get_frames():
            while True:
                yield subscriber.recv()

        return get_frames()

    status = '404 NOT FOUND'
    headers = []
    start_response(status, headers)
    return status

我正在运行gunicorn -max-requests 5来帮助,但显然不是解决方案。我甚至不知道从哪里开始追捕罪魁祸首:/

1 个答案:

答案 0 :(得分:0)

我能够通过删除gevent_zeromq并使用包含gevent支持的pyzmq == 13.1.0来纠正此内存泄漏。