diff --git a/dispatcharr/celery.py b/dispatcharr/celery.py index 8ccb3c33..0d63f063 100644 --- a/dispatcharr/celery.py +++ b/dispatcharr/celery.py @@ -49,6 +49,11 @@ app.conf.update( worker_task_log_format='%(asctime)s %(levelname)s %(task_name)s: %(message)s', ) +# Route long-running DVR recordings to a dedicated `dvr` queue consumed by a thread-pool worker. +app.conf.task_routes = { + 'apps.channels.tasks.run_recording': {'queue': 'dvr'}, +} + # Add memory cleanup after task completion @task_postrun.connect # Use the imported signal def cleanup_task_memory(**kwargs): diff --git a/docker/entrypoint.celery.sh b/docker/entrypoint.celery.sh index b38b6ac3..c795d781 100644 --- a/docker/entrypoint.celery.sh +++ b/docker/entrypoint.celery.sh @@ -67,4 +67,8 @@ NICE_LEVEL="${CELERY_NICE_LEVEL:-5}" if [ "$NICE_LEVEL" -lt 0 ] 2>/dev/null; then echo "Warning: CELERY_NICE_LEVEL=$NICE_LEVEL is negative, requires SYS_NICE capability" fi -nice -n "$NICE_LEVEL" celery -A dispatcharr worker -l info --autoscale=6,1 + +# DVR worker: thread pool for the long-running, I/O-bound run_recording task. +nice -n "$NICE_LEVEL" celery -A dispatcharr worker -Q dvr -n dvr@%h --pool=threads --concurrency=20 -l info & +# Default prefork worker: every queue except `dvr`. +nice -n "$NICE_LEVEL" celery -A dispatcharr worker -Q celery -n default@%h --autoscale=6,1 -l info diff --git a/docker/uwsgi.debug.ini b/docker/uwsgi.debug.ini index d2847335..bc21275d 100644 --- a/docker/uwsgi.debug.ini +++ b/docker/uwsgi.debug.ini @@ -7,9 +7,10 @@ exec-before = python /app/scripts/wait_for_redis.py ; Start Redis first attach-daemon = redis-server -; Then start other services with configurable nice level (default: 5 for low priority) -; Users can override via CELERY_NICE_LEVEL environment variable in docker-compose -attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker --autoscale=6,1 +; Default prefork worker: every queue except `dvr`. +attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker -Q celery -n default@%%h --autoscale=6,1 +; DVR worker: thread pool for the long-running, I/O-bound run_recording task. +attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker -Q dvr -n dvr@%%h --pool=threads --concurrency=20 attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr beat attach-daemon = daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application attach-daemon = cd /app/frontend && npm run dev diff --git a/docker/uwsgi.dev.ini b/docker/uwsgi.dev.ini index 51aae9a5..dd799500 100644 --- a/docker/uwsgi.dev.ini +++ b/docker/uwsgi.dev.ini @@ -9,9 +9,10 @@ exec-pre = python /app/scripts/wait_for_redis.py ; Start Redis first attach-daemon = redis-server --protected-mode no -; Then start other services with configurable nice level (default: 5 for low priority) -; Users can override via CELERY_NICE_LEVEL environment variable in docker-compose -attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker --autoscale=6,1 +; Default prefork worker: every queue except `dvr`. +attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker -Q celery -n default@%%h --autoscale=6,1 +; DVR worker: thread pool for the long-running, I/O-bound run_recording task. +attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker -Q dvr -n dvr@%%h --pool=threads --concurrency=20 attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr beat attach-daemon = daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application attach-daemon = cd /app/frontend && npm run dev diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini index 920bac48..3972c3d9 100644 --- a/docker/uwsgi.ini +++ b/docker/uwsgi.ini @@ -9,9 +9,10 @@ exec-pre = python /app/scripts/wait_for_redis.py ; Start Redis first attach-daemon = redis-server -; Then start other services with configurable nice level (default: 5 for low priority) -; Users can override via CELERY_NICE_LEVEL environment variable in docker-compose -attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker --autoscale=6,1 +; Default prefork worker: every queue except `dvr`. +attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker -Q celery -n default@%%h --autoscale=6,1 +; DVR worker: thread pool for the long-running, I/O-bound run_recording task. +attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr worker -Q dvr -n dvr@%%h --pool=threads --concurrency=20 attach-daemon = nice -n $(CELERY_NICE_LEVEL) celery -A dispatcharr beat attach-daemon = daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application