当前位置:网站首页>解决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高阶---存储引擎、索引、锁
- [npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
- Two good php debug tutorials
- MySql -- 不存在则插入,存在则更新或忽略
- punch day05
- MySQL Advanced Study Notes
- 有人开源全凭“为爱发电”,有人却用开源“搞到了钱”
- Nodejs安装教程
- Node installation and environment configuration
- August 2022 plan, focusing on ue4 video tutorials
猜你喜欢

APP special test: traffic test

MySql COUNT statistics function explanation

MySQL - Multi-table query and case detailed explanation

MySQL union query (multi-table query)

数据库概论之MySQL表的增删改查1

武汉高性能计算大会2022举办,高性能计算生态发展再添新动力

Node installation and environment configuration

How does abaqus quickly import the assembly of other cae files?

数据库概论-MySQL的数据表的基本操作

MySQL高阶---存储引擎、索引、锁
随机推荐
(笔记整理未完成)【图论】图的遍历
ASP.NET Core Web API 幂等性
HCIP 第二天
The second day HCIP
推出 Space On-Premises (本地部署版) Beta 版!
每周推荐短视频:为什么产品开发需要数字化?如何做到数字化?
Connection reset by peer 问题解析
【暑期每日一题】洛谷 P3156 【深基15.例1】询问学号
Submit code process
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
【21天学习挑战赛】顺序查找
【暑期每日一题】洛谷 P1551 亲戚
Technology empowers Lhasa's "lungs", Huawei helps Lalu Wetland Smart Management to protect lucid waters and lush mountains
MySQL高级SQL语句(二)
MySQL 23道经典面试吊打面试官
Nacos installation detailed process
MySQL union query (multi-table query)
数据库概论之MySQL表的增删改查2
At age 94, pioneer Turing award winner, computational complexity theory, Juris Hartmanis, died
mysql高阶语句(一)