Linux下使用Gunicorn部署flask项目
Gunicorn很容易配置,对cpu的消耗很少,且兼容性好。支持了很多Worker模式,推荐的模式有以下几种:同步Worker:也是默认模式,也就是一次只处理一个请求。异步Worker:通过Eventlet、Gevent实现的异步模式。异步IO Worker:目前支持gthread和gaiohttp两种类型。首先需要安装Gunicorn$ pip install gunicorn然后
·
Gunicorn很容易配置,对cpu的消耗很少,且兼容性好。
支持了很多Worker模式,推荐的模式有以下几种:
同步Worker:也是默认模式,也就是一次只处理一个请求。
异步Worker:通过Eventlet、Gevent实现的异步模式。
异步IO Worker:目前支持gthread和gaiohttp两种类型。
首先需要安装Gunicorn
$ pip install gunicorn
然后我们写一个例子:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "ok"
if __name__=='__main__':
app.run(host='0.0.0.0',port=9000)
使用以下命令启动我们的应用:
$ gunicorn --workers=3 master.test:app -b 0.0.0.0:9000
master是模块的目录名字,test是模块文件的名字,
app是文件中Flask实例的名字。
我们的Worker的数量并不是多了就好,
要根据cpu个数来定,
cpu x 2 + 1
我们可以进入命令行使用
$python -c ‘import multiprocessing;print multiprocessing.cpu_count()’
欢迎进(Q)群,帮你解决问题:
更多推荐
已为社区贡献1条内容
所有评论(0)