gunicorn

记一次 gunicorn 启动 flask 出问题的经历

北城以北 提交于 2020-11-25 07:08:37
出错现象: gunicorn+nginx+flask 部署项目, 部署过程没问题,项目也正常启动了,但是一旦访问接口,就会报错: Traceback (most recent call last): File " /usr/local/lib/python3.6/dist-packages/gunicorn/workers/sync.py " , line 135, in handle self.handle_request(listener, req, client, addr) File " /usr/local/lib/python3.6/dist-packages/gunicorn/workers/sync.py " , line 176, in handle_request respiter = self.wsgi(environ, resp.start_response) TypeError: __call__ () takes from 1 to 2 positional arguments but 3 were given 但是我通过 runserver运行的话,是没有问题的,外网可以正常访问. 所以问题就出在gunicorn 和 flask 的 wsgi 对接上. gunicorn 启动时的方式是 gunicorn [options] file:app

django 重写 mysql 连接库实现连接池

…衆ロ難τιáo~ 提交于 2020-11-02 06:44:54
django 重写 mysql 连接库实现连接池 问题 django 项目使用 gunicorn + gevent 部署,并设置 CONN_MAX_AGE 会导致 mysql 数据库连接数飙升,在高并发模式可能会出现 too many connections 错误。该怎么解决这个问题呢?首先看下 django 源码,找到问题的根源。 本文 django 版本为 2.2.3。 问题分析 首先查看连接部分源码: # django/db/backends/mysql/base.py class DatabaseWrapper(BaseDatabaseWrapper): vendor = 'mysql' ... ... ... def get_new_connection(self, conn_params): # 每次查询都会重新建立连接 return Database.connect(**conn_params) ... ... ... 再查看其基类 BaseDatabaseWrapper # django/db/backends/base/base.py class BaseDatabaseWrapper: """Represent a database connection.""" # Mapping of Field objects to their column types.