上游过早关闭连接uwsgi nginx

时间:2015-03-29 10:07:11

标签: django nginx uwsgi

下午好,同事们。

帮助解决问题(甚至2:))))

nginx发送错误,但并非总是如此,并且每隔2-5分钟发送一次 tail -f /var/log/nginx/error.log

2015/03/29 12:15:28 [error] 22735#0: *219816 upstream prematurely closed connection while reading response header from upstream, client: 213.ххх.ххх.180, server: ххх, request: "POST /?uuid=a_4526e8e2-e0ac-426e-ac95-7a0c8ac37cc1 HTTP/1.1", upstream: "uwsgi://unix:///home/uwsgi-home/parsecdr/uwsgi.sock:", host: ххх

在日志中uwsgi通常安静而平静,但有时它会发生错误

Traceback (most recent call last):
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 236, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/views/debug.py", line 91, in technical_500_response
    html = reporter.get_traceback_html()
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/views/debug.py", line 350, in get_traceback_html
    return t.render(c)
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/template/base.py", line 148, in render
    return self._render(context)
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/template/base.py", line 142, in _render
    return self.nodelist.render(context)
  File "/home/uwsgi-home/local/lib/python2.7/site-packages/django/template/base.py", line 848, in render
    return mark_safe(''.join(bits))
MemoryError

此错误与nginx错误相同而不是(可能是两个不同的问题)

代码 - 解析器xml。文件和仁慈20-40 KB。 该项目只有一个视图和一个URL。

很可能是nginx或uwsgi confs的问题

要求查看并告知。实际配置:

[uwsgi]
# Django-related settings
# the base directory (full path)
chdir           = /home/uwsgi-home/parsecdr/
# Django's wsgi file
module          = parsecdr.wsgi
module          = parsecdr.wsgi:application
module          = django.core.wsgi:get_wsgi_application()
plugins         = python
# the virtualenv (full path)
home            = /home/uwsgi-home

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
limit-as        = 192
max-requests    = 5000
harakiri    = 120
buffer-size     = 49152
# the socket (use the full path to be safe
socket          = /home/uwsgi-home/parsecdr/uwsgi.sock
# ... with appropriate permissions - may be needed
#chmod-socket    = 666
# clear environment on exit
vacuum          = true
touch-reload    = /home/uwsgi-home/parsecdr/touch-reload
daemonize       = /var/log/uwsgi/parsecdr.log

和nginx     上游parsecdr {         server unix:///home/uwsgi-home/parsecdr/uwsgi.sock; #用于文件套接字     }

server {
    listen      80;
    server_name parsecdr.rt.ru;
    charset     utf-8;

    large_client_header_buffers 8 48k;
    client_max_body_size 50M;
    keepalive_timeout 75s;
    proxy_connect_timeout 60s;
    proxy_read_timeout 60s;


    location / {
        proxy_connect_timeout 300s;
        proxy_send_timeout   600s;
        proxy_read_timeout   600s;
        proxy_buffer_size    64k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;


        uwsgi_pass  parsecdr;
        include     /home/uwsgi-home/parsecdr/uwsgi.params;
    }
}

同样,错误会定期出现。 每50-60条记录一次出错。 第二次测试可能没有错误

更新: 网址:

url(r'^$', xv.parse),

查看:

def parse(request):
    import urllib
    cdr_file = request.POST.get('cdr')
    cdr_file = urllib.unquote(cdr_file)

    cdr = XML_CDR()
    cdr.fs_host = request.META["REMOTE_ADDR"]
    cdr.parse_from_str(cdr_file)
    return HttpResponse(status=201)

0 个答案:

没有答案