为了解决与打开的大量数据库连接相关的问题(OperationalError('致命:为非复制超级用户连接保留剩余的连接插槽\ n',))我试过使用https://github.com/jneight/django-db-geventpool并更新了DATABASE设置,但它没有与芹菜一起使用,所有队列都被卡住了。
我不知道它是否与本节https://github.com/jneight/django-db-geventpool#using-django-16-orm-when-not-serving-requests相关,但我不知道如何应用它。
我正在使用:
- Django 1.9.2
- celery 3.1.19
- gevent 1.1b1
我有以下芹菜文件:
# -*- coding: utf-8 -*-
""" Celery configuration file
"""
from __future__ import unicode_literals
from __future__ import absolute_import
import os
def post_fork():
""" post_fork
# if its a gevent queue (all queues except scrapy-* queues)
"""
from gevent import monkey
monkey.patch_all()
from psycogreen.gevent import patch_psycopg
patch_psycopg()
# post_fork must run before anyother imports
if os.environ.get('GEVENT', None):
post_fork()
from celery import Celery
from django.conf import settings
from etc.celerybase.routers import GlobalRouter
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.sites.app')
app = Celery('pb', broker=getattr(settings, 'BROKER_URL', 'redis://'))
app.config_from_object('django.conf:settings')
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_TASK_SERIALIZER='json',
CELERY_ACCEPT_CONTENT=['json'],
CELERY_RESULT_SERIALIZER='json',
CELERY_DEFAULT_QUEUE='low',
CELERY_DEFAULT_EXCHANGE='low',
CELERY_DEFAULT_ROUTING_KEY='low',
CELERY_CREATE_MISSING_QUEUES=True,
CELERY_ROUTES=(
GlobalRouter(),
),
)
主管档案:
[program:celery_medium]
command=newrelic-admin run-program celery -A miap worker -E -Q low -P gevent -c 300 --loglevel=ERROR
directory=/var/lib/app
environment=NEW_RELIC_CONFIG_FILE="/var/lib/app/pb/newrelic
/SETTINGS_FILE/worker-medium.ini",DJANGO_SETTINGS_MODULE="setting.sites.app",GEVENT="True"