【问题标题】:sagemaker batch transform breaks with upstream prematurely closed connection while reading upstreamsagemaker 批量转换在读取上游时因上游​​过早关闭连接而中断
【发布时间】:2018-11-04 02:00:36
【问题描述】:

我一直在尝试通过 AWS sagemaker 的批量转换服务让一个容器化的机器学习模型在 AWS sagemaker 上运行,该服务将整个数据集分解为更小的数据集,以便从机器学习模型进行推断。

容器有一个烧瓶服务,它在后台运行带有 gunicorn 和 nginx 的 ML 模型。在执行批量转换时,我得到 502 bad gateway 错误,日志上有以下错误(当我运行具有 50k 数据集作为输入的相同容器时,它通过 c5.xlarge 实例传递但当我在 80k 下以相同情况运行时失败)

*4 upstream prematurely closed connection while reading response header from 
upstream, client: IP, server: , request: "POST /invocations 
HTTP/1.1", upstream: "http://unix:/tmp/gunicorn.sock:/invocations", host: 
"IP:8080"

"POST /invocations HTTP/1.1" 502 182 "-" "Apache-HttpClient/4.5.x (Java/1.8.0_172)"

Nginx 配置

worker_processes 1;
daemon off; # Prevent forking
pid  /tmp/nginx.pid;
error_log /var/log/nginx/error.log;
events { defaults }
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log /var/log/nginx/access.log combined;

    upstream gunicorn {
        server unix:/tmp/gunicorn.sock;
    }

    server {
       listen 8080 deferred;
       client_max_body_size 5m;

       keepalive_timeout 10000;

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

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

和 gunicorn 配置:

https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/scikit_bring_your_own/container/decision_trees/serve

我对 nginx 和 gunicorn 很陌生,并且已经阅读了其他大部分内容,因此上游过早关闭并在读取响应错误时连接的帖子。我已经尝试过增加客户端尺寸等,但仍然遇到同样的错误。在这方面的一些帮助将非常有帮助。

【问题讨论】:

    标签: python nginx flask gunicorn amazon-sagemaker


    【解决方案1】:

    这看起来像是 gunicorn worker 超时。您可以根据模型处理推理请求所需的时间调整两种超时设置:

    1. gunicorn worker 超时,可以在这里调整:https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/scikit_bring_your_own/container/decision_trees/serve#L25

    2. nginx的proxy_read_timeout设置,可以在这里添加到nginx.conf中:https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/scikit_bring_your_own/container/decision_trees/nginx.conf#L21-L37

    如果您需要对特定转换作业的支持,请在 AWS 论坛上联系:https://forums.aws.amazon.com/forum.jspa?forumID=285&start=0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-21
      • 2012-08-15
      • 2019-01-17
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      相关资源
      最近更新 更多