我有一个连接到uWSGI后端的Nginx反向代理。我已将nginx配置为以以下方式登录到集中式远程syslog服务:
error_log syslog:server=example.com:514,tag=nginx_error debug;
。
这里的问题是,当我从nginx.conf中删除上述行时,请求处理时间变得非常长,并且导致客户端超时(返回HTTP 460)。
当我启用登录nginx.conf时,根本没有获得HTTP 460。但是,引入了额外的开销,从而增加了CPU利用率。我怀疑nginx正在将HTTP请求缓慢发送到我的uWSGI后端,而我的uWSGI后端能够正常处理它们,并将响应成功写回nginx。启用日志记录后,后端的平均响应时间也会飙升至5倍。
一旦禁用日志记录,CPU使用率就会下降,而请求将泛洪到uWSGI后端,并且后端需要一些时间才能在定义的客户端超时时间内返回响应。如果请求需要花费一些时间来处理,并且客户端(Android / iOS应用)尚未收到响应,则在达到超时或用户取消请求时,它将中止连接。
我想知道是否需要向我的nginx添加代理缓冲区来排队请求并将其发送到我的后端,而不是使请求溢出。或任何其他解决方案表示赞赏。
nginx.conf文件:
error_log syslog:server=example.com:514,tag=nginx_error error;
#daemon off;
upstream django{
server unix:/home/example/conn.sock;
}
server{
listen 80;
charset utf-8;
location / {
uwsgi_pass django;
proxy_connect_timeout 10;
proxy_send_timeout 40s;
proxy_read_timeout 40s;
uwsgi_send_timeout 40s;
uwsgi_read_timeout 40s;
include /home/example/uwsgi_params;
sendfile on;
tcp_nopush on;
reset_timedout_connection on;
keepalive_timeout 40;
keepalive_requests 100000;
}
}
nginx_error.log
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 post event 0000557BCA896120
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 delete posted event 0000557BCA884110
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http run request: "/v1/api/notes/details/?"
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http upstream check client, write event:0, "/v1/api/notes/details/"
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [info] 10#10: *90754 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 10.0.1.236, server: , request: "PUT /v1/api/notes/details/ HTTP/1.1", upstream: "uwsgi://unix:/home/example/conn.sock:", host: "example.com"
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 finalize http upstream request: 499
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 finalize http uwsgi request
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 free rr peer 1 0
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 close http upstream connection: 13
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 free: 0000557BCA872DD0, unused: 48
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 event timer del: 13: 1561818412561
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 reusable connection: 0
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http finalize request: 499, "/v1/api/notes/details/?" a:1, c:1
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http terminate request count:1
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http terminate cleanup count:1 blk:0
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http posted request: "/v1/api/notes/details/?"
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http terminate handler count:1
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http request count:1 blk:0
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http close request
Jun 29 14:26:12 b80edd13e307 nginx_error: 2019/06/29 14:26:12 [debug] 10#10: *90754 http log handler