我一直在尝试通过其批量转换服务让容器化机器学习模型在 AWS sagemaker 上运行,该服务将整个数据集分解为更小的数据集,以便从机器学习模型中进行推理。
容器有一个 flask 服务,它在后台运行带有 gunicorn 和 nginx 的 ML 模型。在执行批处理转换时,我收到 502 错误网关错误,并在日志中出现以下错误(当我运行具有 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 配置:
我是 nginx 和 gunicorn 的新手,并且已经阅读了其他大部分内容,因此上游的帖子在读取响应错误时因连接而过早关闭。我尝试过增加客户端体型等方法,但仍然遇到同样的错误。在这方面的一些帮助将非常有帮助。
最佳答案
这看起来像是 gunicorn worker 超时。您可以根据模型处理推理请求所需的时间来调整两个超时设置:
可在此处调整的 gunicorn worker 超时:https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/scikit_bring_your_own/container/decision_trees/serve#L25
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
关于python - sagemaker 批量转换在读取上游时中断上游过早关闭的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53137133/