Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery: number of workers vs concurrency

What is the difference between having:

  1. one worker with concurrency 4 or
  2. two workers with concurrency 2 each

for the same queue.

Thanks

like image 485
Olivetree Avatar asked Oct 03 '17 10:10

Olivetree


People also ask

How many celery workers can I run?

There is no point in running more than one worker on a particular machine unless you want to do routing. I would suggest running only 1 worker per machine with the default number of processes.

What is default concurrency in celery?

Concurrency settings The default is 4 (four messages for each process). The default setting seems pretty good here. However, if you have very long running tasks waiting in the queue and you have to start the workers, note that the first worker to start will receive four times the number of messages initially.

How do you make multiple workers with celery?

You probably just need to add the --concurrency or -c argument when starting the worker to spawn multiple (parallel) worker instances. Show activity on this post. You can look for Canvas primitives there you can see how to make groups for parallel execution. class celery.

Does celery use multiprocessing?

Celery itself is using billiard (a multiprocessing fork) to run your tasks in separate processes.


1 Answers

I assume that you are running both workers in the same machine. In that case I would recommend you to maintain one worker for a queue.

  • Two workers for the same queue does not benefit you by any means. It would just increase the memory wastage.
  • Two or more workers when you have multiple queues, to maintain priority or to allocate different number of cores to each worker.
  • Two or more workers for a single queue is useful if you run the workers in different machines. The workers in different machines consumes tasks from same queue, you could allocate concurrency based on the cores available in each machine.

I do realise I responded 2+ years later. But I just thought I'll put it here for anyone who still has similar doubts.

like image 197
Aditya Nagesh Avatar answered Sep 16 '22 17:09

Aditya Nagesh