Моя цель — сократить количество опросов Celery Redis. В настоящее время он опрашивает каждую секунду, что проблематично.
Я сделал три шага
- Я пытался изменить настройки в Django для Celery, включая использование таких параметров, как CELERY_IGNORE_RESULT, CELERY_WORKER_CONCURRENCY, CELERY_BROKER_HEARTBEAT и, наконец, CELERY_BEAT_MAX_LOOP_INTERVAL
Код: Выделить всё
CELERY_RESULT_BACKEND = None CELERY_IGNORE_RESULT = True # Ignore task results to reduce Redis usage CELERY_ACCEPT_CONTENT = ["json"] CELERY_TASK_SERIALIZER = "json" CELERYD_PREFETCH_MULTIPLIER = 1 # Fetch only 1 task at a time CELERY_ACKS_LATE = True # Acknowledge tasks after completion to avoid re-execution on failure # Celery transport options CELERY_BROKER_TRANSPORT_OPTIONS = { 'ssl': { 'ssl_cert_reqs': ssl.CERT_NONE # Suggestion: CERT_REQUIRED for stronger security }, 'visibility_timeout': 3600, # Timeout for long-running tasks 'polling_interval': 30 # Poll every 30 seconds } CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS = { 'ssl': { 'ssl_cert_reqs': ssl.CERT_NONE # Same as broker for consistency } } # Reduce the number of threads/processes CELERY_WORKER_CONCURRENCY = 1 # Disable sending task events CELERY_WORKER_SEND_TASK_EVENTS = False # Disable remote control commands CELERY_WORKER_ENABLE_REMOTE_CONTROL = False # Disable broker heartbeat messages CELERY_BROKER_HEARTBEAT = None CELERY_BEAT_MAX_LOOP_INTERVAL = 3600 # Check for scheduled tasks every hour - Во-вторых, я даже попробовал настроить динамический опрос, чтобы график опросов был чаще в ночное время и снова сокращался
Код: Выделить всё
def set_polling_interval(): now = datetime.now() if now.hour == 23 and now.minute >= 59 or now.hour == 0 and now.minute Подробнее здесь: [url]https://stackoverflow.com/questions/79056504/celery-polling-redis-every-second[/url]