Py学习  »  NGINX

nginx 502错误一致,没有应用程序错误

kausal_malladi • 4 年前 • 890 次点击  

几天前我突然遇到一个奇怪的问题。

我的应用程序已经运行了很长一段时间,没有问题。突然间,我发现有502个错误一直存在。我们以每分钟50000个请求的速度运行,平均服务器响应时间为12毫秒。

没有应用程序死机(错误),nginx config也允许多达10000个工作连接。

其他配置。。

sendfile        on;
keepalive_timeout  600;
server_tokens off;
client_max_body_size 20m;

有人能帮我指明解决问题的方向吗?我得到了下面的一个错误,大部分是下面的第一个(sendfile())。

2019/08/16 15:01:42 [error] 30#0: *60729 sendfile() failed (32: Broken pipe) while sending request to upstream, client: <IP>, server: <hostname>, request: "POST <endpoint> HTTP/1.1", upstream: "http://127.0.0.1:8080/<endpoint>", host: "<hostname>"

2019/08/16 15:01:45 [error] 30#0: *60821 readv() failed (104: Connection reset by peer) while reading upstream, client: <IP>, server: <hostname>, request: "POST <endpoint> HTTP/1.1", upstream: "http://127.0.0.1:8080/<endpoint>", host: "<hostname>"

2019/08/16 14:55:27 [error] 20#0: *42152 upstream timed out (110: Connection timed out) while reading response header from upstream, client: <IP>, server: <hostname>, request: "POST <endpoint> HTTP/1.1", upstream: "http://127.0.0.1:8080/<endpoint>", host: "<hostname>"

我们使用的是golang和gin框架,如果它有助于调试的话。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52893
 
890 次点击  
文章 [ 1 ]  |  最新文章 4 年前
kausal_malladi
Reply   •   1 楼
kausal_malladi    4 年前

查看每个请求的请求长度,我们发现返回的请求502是POST数据大小超过200kb左右的请求。 所以,我们使用了

client_body_buffer_size

并将其值设置为1 MB,否则默认情况下大小为2页(64位计算机上为16 KB)。如果POST数据大于16kb,它会将数据存储在磁盘上的临时文件中,这会导致额外的I/O延迟。因此,sendfile()失败的错误将立即减少为零。对于我记录的每个请求

$请求长度

因此,很容易从访问日志及其相应的大小中找到所有502

不过,readv()错误仍然很少。