请求在Heroku Python Flask应用程序中超时

2024-04-20 07:10:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经训练了一个DL模型,并试图通过RESTAPI将其发布到internet上,方法是将其托管在Heroku服务器上

在本地,我尝试了所有Heroku配置,测试了API,最后在Heroku上成功部署了它。 访问该端点时,请求超时,在heroku日志中,我可以看到以下输出:

2019-09-22T11:11:10.543181+00:00 app[web.1]: [2019-09-22 11:11:10 +0000] [48] [DEBUG] POST /analyse
2019-09-22T11:11:10.556943+00:00 app[web.1]: prediction started
2019-09-22T11:11:40.537864+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/analyse" host=obscure-peak-46855.herokuapp.com request_id=f8f450ca-fd07-491d-aba2-433da710a3e1 fwd="103.242.239.84" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2019-09-22T11:11:41.382624+00:00 app[web.1]: [2019-09-22 11:11:41 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:48)
2019-09-22T11:11:42.402385+00:00 app[web.1]: [2019-09-22 11:11:42 +0000] [49] [INFO] Booting worker with pid: 49
2019-09-22T11:12:39.861556+00:00 app[web.1]: [2019-09-22 11:12:39 +0000] [49] [DEBUG] Closing connection.

表示Python代码的示例:

statusDict = {}
print('prediction started')
predictionResult = 1 if model.predict(inputData)[0] > 0.5 else 0
print('prediction complete')
statusDict['input comment'] = inputSentence
statusDict['status'] = 'prediction complete'
statusDict['prediction'] = predictionResult
response.update(statusDict)

在Heroku上公开您的ML模型时,是否有人遇到过类似的请求超时? 我甚至在Heroku日志中看不到预测完成打印语句


Tags: debug模型appherokustatuspostpidcomplete
1条回答
网友
1楼 · 发布于 2024-04-20 07:10:59

发生这种情况是因为加载模型花费了太多时间。你能告诉我们更多关于弹头的尺寸和型号吗。当模型的整个流程渲染页面所需时间超过30秒时,会出现此错误。您是否可以共享Procfile和app.py以查看它花费的时间。尝试删除文件中不必要的库(如果有)

相关问题 更多 >