dongsui3297 2019-08-16 10:24
浏览 278
已采纳

nginx 502错误始终存在,没有应用程序错误

I ran into a strange problem suddenly a few days back.

My application has been running for quite sometime with no issues. Suddenly I started seeing a good number of 502 errors consistently. We operate at about 50000 requests per minute with an average server response time of 12 ms.

There are no application panics (errors) and nginx config also allows upto 10000 worker connections.

Other configuration..

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

Can anyone help me with the direction I should be looking at solving the problem? I get one of these below errors and mostly the first one (sendfile()) below.

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>"

We are on golang and gin framework, if it helps in any debugging.

  • 写回答

1条回答 默认 最新

  • doufu8127 2019-08-27 10:43
    关注

    Looking at the request_length for each request, we figured out that the requests that are being returned 502 are the ones which have POST data size over 200 KB or so. So, we used the config

    client_body_buffer_size
    

    and set it's value to 1 MB, which otherwise by default is size of upto 2 pages (16 KB on 64-bit machines). If the POST data is more than 16 KB, it stores the data in a temp file on disk which causes additional I/O latency. Because of this, the sendfile() failed errors are reduced immediately to zero. For every request I logged

    $request_length

    and hence it was easy to find all 502s from access logs and their corresponding size

    There are still very few readv() errors though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题