当前位置:网站首页>解决Pytorch模型在Gunicorn部署无法运行或者超时问题
解决Pytorch模型在Gunicorn部署无法运行或者超时问题
2022-08-02 06:12:00 【[email protected]】
@TOC解决Pytorch模型在Gunicorn部署无法运行或者超时问题
问题描述
训练出了一个Pytorch 文本生成模型,想要用Flask+Gunicorn的方法部署。但是请求模型进行生成的接口时,一直没有结果,最后导致timeout。
我的模型生成接口大概长这样:
model = load_model() #load_model会返回一个pytorch模型
@app.route('/generate')
def generate_texts():
text = model.generate()
return text
当我用gunicorn部署:
gunicorn -c gunicorn_conf.py news_server:app > logs/runlog.txt 2>&1 &1
我的gunicorn_conf.py文件长这样的:
#!/usr/bin/python
#coding=utf-8#nohup gunicorn -c gunicorn_conf.py online_server:app &
import multiprocessingpreload_app = True
debug = True
bind = '0.0.0.0:9091'
workers = 3
threads = 6
backlog = 32 #服务器中在pending状态的最大连接数,即client处于waiting的数目。超过这个数目, client连接会得到
一个error。
worker_class = 'gevent'
worker_connections = 10 #最大客户端并发数量,默认情况下这个值为1000。此设置将影响gevent和eventlet工作模式
#timeout = 1
#proc_name = 'gunicorn.pid'
pidfile = 'logs/gunicorn.pid'
accesslog = 'logs/access.log'
access_log_format = '%(h)s %(t)s %(U)s %(q)s'
#errorlog = 'logs/gun_error.log'
#loglevel = 'logs/debug'
#logfile = 'logs/gun_debug.log'
部署并没有发现什么异常。但是每次请求这个模型生成文本接口时,一直得不到结果,最后超时。
经过一天的debug和查资料,发现国外一个老哥有很类似的问题。
https://stackoverflow.com/questions/67069183/worker-timeout-when-preloading-pytorch-model-in-flask-app-on-render-com
问题原因
Pytorch会在和Gunicorn的preload_app选项为True时出现bug。应该是gunicorn的共享内存机制和Pytorch有一些冲突。
解决方案
将gunicorn的preload_app设置为False。
preload_app的作用主要是在启动app时能节省一点时间,进程之间共享内存。但是有很大的副作用,具体可以参考这篇文章:https://zhuanlan.zhihu.com/p/371115835
————————————————
原文链接:https://blog.csdn.net/Ang_Quantum/article/details/122496024
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zzddada/article/details/126040885
边栏推荐
- MySQL Advanced Study Notes
- 解决C#非静态字段、方法或属性“islandnum.Program.getIslandCount(int[][], int, int)”要求对象引用
- SphereEx苗立尧:云原生架构下的Database Mesh研发实践
- Connection reset by peer problem analysis
- 暑期总结(三)
- 【暑期每日一题】洛谷 P1255 数楼梯
- MySQL高级学习笔记
- APP special test: traffic test
- MySQL - 多表查询与案例详解
- See the picture to understand | How to choose sales indicators to measure the health of business growth
猜你喜欢

HCIP day one

MySQL Advanced Statements (1)

Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题

【npm install 报错问题合集】- npm ERR! code ENOTEMPTY npm ERR! syscall rmdir

专家见解|经济低迷期把握创新机会的 3 大方法

MySQL 23 classic interviews hang the interviewer
![[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir](/img/c5/2c42e26e577506573985b30669ca6c.png)
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
![[数据集][VOC]男女数据集voc格式6188张](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[数据集][VOC]男女数据集voc格式6188张

(笔记整理未完成)【图论】图的遍历

MySQL高级SQL语句
随机推荐
chrome 插件开发指南
MySQL Advanced Statements (1)
提交代码流程
.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
Kind of weird!Access the destination URL, the host can container but not
速看!PMP新考纲、PMBOK第七版解读
aTrust项目的相关操作与分享
The stock price has repeatedly hit new lows, and the real estate SaaS giant is in trouble. How should Mingyuan Cloud transform and save itself?
ASP.NET Core Web API 幂等性
PMP新考纲通关秘籍,告别抓瞎
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
Nodejs installation tutorial
看图就懂|衡量业务增长健康的销售指标如何选择
有点奇怪!访问目的网址,主机能容器却不行
abaqus如何快速导入其他cae文件的assembly?
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
See the picture to understand | How to choose sales indicators to measure the health of business growth
Xgboost报错ValueError:无效的形状:标签(1650 2)
postgres 多个变量填充字符串,字串格式化
2022年7月18日-7月31日(Ue4视频教程和文档,20小时。合计1412小时,剩8588小时)