Sobes.tech
Junior — Middle

Is it possible to dynamically manage the number of workers in Celery during task execution?

sobes.tech AI

Answer from AI

In Celery, the number of workers (worker processes) is usually set at startup via a command, for example:

celery -A proj worker --concurrency=4

During task execution, it is not possible to dynamically change the number of workers directly using Celery. To change the number of workers, you need to start or stop individual worker processes.

However, you can manage the load within a worker, for example, using the --autoscale parameter, which allows the worker to automatically scale the number of active threads within specified limits:

celery -A proj worker --autoscale=10,3

This means the worker will automatically increase or decrease the number of threads from 3 to 10 depending on the load.

To change the total number of workers (processes), process management tools (systemd, supervisord, Kubernetes, etc.) are usually used, restarting or creating new workers.