相关疑难解决方法(0)

Django 超过最大 Postgres 连接数

我遇到了一个 Django 应用程序的问题,该应用程序在Gunicorn使用异步eventlet工作者运行时超过了与 Postgres 的最大同时连接数 (100) 。当达到连接限制时,应用程序开始返回500-errors,直到可以建立新连接。

这是我的数据库配置:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'django',
        'USER': 'django',
        'HOST': 'postgres',
        'PORT': 5432,
        'CONN_MAX_AGE': 60,
    }   
}   
Run Code Online (Sandbox Code Playgroud)

Gunicorn 是这样启动的:

gunicorn --bind 0.0.0.0:8080 --worker-class eventlet --workers 5 myapp.wsgi:application
Run Code Online (Sandbox Code Playgroud)

这些是已安装的软件包:

  • djano v1.7
  • gunicorn v19.3
  • eventlet v0.17
  • psycopg2 v2.6

与 Gunicorn 工作人员一起运行时,Django 是否无法跨 HTTP 请求重用连接?某种 3rd 方数据库连接池是我唯一的选择吗?

15-03-23 更新:CONN_MAX_AGE异步 Gunicorn 工人似乎存在问题。连接确实是持久的,但从未在本文中提到的任何顺序请求中重用。设置CONN_MAX_AGE0强制 Django 在请求结束时关闭连接,防止形成未使用的持久连接。

django postgresql psycopg2 eventlet gunicorn

7
推荐指数
1
解决办法
3067
查看次数

标签 统计

django ×1

eventlet ×1

gunicorn ×1

postgresql ×1

psycopg2 ×1