在nginx so_keepalive超时后如何清理uwsgi?

时间:2014-12-05 08:49:29

标签: python nginx wsgi uwsgi

我的nginx配置如下:

server {
    listen 80 so_keepalive=30m::;

    location /wsgi {
        uwsgi_pass  uwsgicluster;
        include     uwsgi_params;
        uwsgi_read_timeout 30000;
        uwsgi_buffering off;
    }

    ...
}

在我的python中:

def application_(environ, start_response):
    body = queue.Queue()
    ...
    gevent.spawn(redis_wait, environ, body, channels)
    return body

def redis_wait(environ, body, channels):
    server = redis.Redis(connection_pool=REDIS_CONNECTION_POOL)

    client = server.pubsub()

    try:
        for channel in channels:
            client.subscribe(channel)

        messages = client.listen()

        for message in messages:
            if message['type'] != 'message' and message['type'] != 'pmessage':
                continue

            body.put(message['data'])
    finally:
        client.unsubscribe()
        client.close()

当客户端连接中断(网络连接突然丢失,应用程序终止等)时,会出现问题.redis显示服务器上的连接仍处于打开状态。我该如何解决?即使使用so_keepalive,连接也不会被清除。我该如何解决这个问题?

编辑:我已经通过nginx_status页面注意到断开连接后活动连接数 发生故障。问题是uwsgi没有得到通知。

1 个答案:

答案 0 :(得分:0)

您必须等待uwsgi套接字以及redis套接字,以便在uwsgi套接字关闭时通知您。示例:http://nullege.com/codes/show/src%40k%40o%40kozmic-ci-HEAD%40tailer%40__init__.py/72/uwsgi.connection_fd/python

相关问题