【问题标题】:How do I cleanup in uwsgi after nginx so_keepalive timeout?nginx so_keepalive超时后如何在uwsgi中清理?
【发布时间】:2014-12-06 12:38:28
【问题描述】:

我的nginx配置是这样的:

server {
    listen 80 so_keepalive=30m::;

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

    ...
}

在我的蟒蛇中:

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 没有收到通知。

【问题讨论】:

    标签: python nginx wsgi uwsgi


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      • 2011-10-04
      • 2013-04-15
      • 1970-01-01
      • 2019-05-22
      • 2015-02-09
      相关资源
      最近更新 更多