等待请求时 Nginx 错误 recv() failed (14: Bad address)

问题描述

我有一个 Nginx + flask + gunicorn 应用程序,我将其 dockerize 并将其放置在 AWS EC2 实例中。 它运行良好,我的负载测试达到了 4000 TPS。

如果我将相同的应用程序部署到网络负载均衡器后面的 ECS,我会遇到以下错误

[alert] 66#0: *3501872 recv() Failed (14: Bad address) while waiting for request,client: *IP*,server: 0.0.0.0:8080
[error] 124#0: *6027194 connect() to unix:/tmp/gunicorn_predictor.sock Failed (11: Resource temporarily unavailable) while connecting to upstream,server:,request: “POST /invocations HTTP/1.1”,upstream: “http://unix:/tmp/myapp.sock:/invocations”,host: “url:80”

这是我的 Nginx 配置:

worker_processes 96; #number of cpu cores
daemon off; # Prevent forking

pid /tmp/Nginx.pid;
error_log /var/log/Nginx/error.log;

worker_rlimit_nofile 65535;
events {
  worker_connections 665;
  use epoll; 
  multi_accept on; 
}

http {
  include /path/conf/mime.types;
  default_type application/octet-stream;

  access_log off;
  
  open_file_cache max=200000 inactive=20s; 
  open_file_cache_valid 30s; 
  open_file_cache_min_uses 2;
  open_file_cache_errors on;

  sendfile on; 
 
  tcp_nopush on;
  
  tcp_nodelay on;

  reset_timedout_connection on;
  
  upstream gunicorn_interceptor {
    server unix:/tmp/gunicorn_interceptor.sock;
  }

  keepalive_timeout 3600s;
  keepalive_requests 500000;

  upstream gunicorn_predictor {
    server unix:/tmp/gunicorn_predictor.sock;
    keepalive 512;
  }

  server {
    listen 8080 deferred;
    client_max_body_size 5m;

    proxy_read_timeout 3600s;
    proxy_connect_timeout 3600s;
    proxy_send_timeout 3600s;

    location ~ ^/(ping) {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://gunicorn_interceptor;
    }

    location ~ ^/(invocations) {
      proxy_buffers 8 24k;
      proxy_buffer_size 2k;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://gunicorn_predictor;
    }


    location / {
      return 404 "{}";
    }
  }
}

是否与 somaxconn 之类的内核参数有关?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)