简体   繁体   English

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

[英]Request TImed Out in Heroku Python Flask Application

I have trained a DL model and trying to expose it on the internet via REST API by hosting it in Heroku server.我已经训练了一个 DL model 并尝试通过 REST API 在 Internet 上公开它,方法是将其托管在 Z1A78417461CFAD3BE93 服务器中。

In local I have tried all the Heroku configuration, tested the API and then finally deployed it successfully on Heroku.在本地,我尝试了所有的 Heroku 配置,测试了 API,最后在 Heroku 上成功部署。 While accessing that endpoint the request is getting timed out and in heroku log I can see the following output:在访问该端点时,请求超时,在 heroku 日志中,我可以看到以下 output:

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.

the representing Python code:代表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)

Did anyone faced similar request timed out while exposing your ML model on Heroku?在 Heroku 上暴露您的 ML model 时,是否有人遇到过类似的请求超时? I can't even see the prediction complete print statement also in Heroku log.我什至在 Heroku 日志中也看不到预测完整的打印语句。

This is happening because your model is taking too much time to load.发生这种情况是因为您的 model 加载时间过长。 Can you tell us more about the slug size and model.你能告诉我们更多关于蛞蝓尺寸和 model 的信息吗? This error comes when the overall flow of your model takes more than 30 sec to render the page.当您的 model 的整体流程需要超过 30 秒来呈现页面时,就会出现此错误。 can you share the Procfile and app.py as well to see where it is taking the time.你能分享 Procfile 和 app.py 看看它在哪里花时间。 Try to remove unecessary libraries if any in the file.如果文件中有任何不必要的库,请尝试删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM