gunicorn

安装用 pip 就可以

启动 flask 命令: gunicorn surge:create_app()
启动 django 命令: gunicorn app:wsgi

配置可以写在根目录的 gunicorn.conf.py 文件里, 内容可以包括:

accesslog = "/tmp/rhinoauth/logs/gunicorn.access.log"
errorlog = "/tmp/rhinoauth/logs/gunicorn.error.log"
worker_class = "gevent"
workers = 5
logLeveL = "info"
bind = "0.0.0.0:8000"
timeout = 60

这里详细说一下 worker_class, 这个配置用来处理并发的情况.
默认值是 sync, 一个 worker 只能处理一个 request, CPU 计算类型的应用可以配置这个.
如果并发量较小, cpu 和 io 较均衡, 可以用 gthread.
对于 flask, django 这类并发和 IO 高的应用, 用 eventlet/gevent 更合适, 更推荐 gevent.
详情见: https://dev.to/lsena/gunicorn-worker-types-how-to-choose-the-right-one-4n2c

for flask or django web application, worker_class is important, if not config it to gevent/eventlet, web page maybe not response, especially when your view contain external api request.
see this article: https://medium.com/@danieldng/use-gevent-when-your-gunicorn-worker-is-waiting-for-data-180efef96367