Search code examples
pythondjangocelerydjango-celery

When does Celery task time start being counted?


Currently in production with my django app, I am having issues with Celery, where a task sometime takes 1-2 seconds, but sometimes takes 15-25 seconds.

My app is a chatbot related app so it needs to proccess a lot of data. So I was a bit confused, the task time being logged in logger is the amount of time it takes the task to execute after it is received by the worker or does it also take in account the time the task was waiting in the Queue?


Solution

  • The time in the logger is calculated based on when the workers starts executing a task. This is different that calculating based on the time received by the worker (because worker's have an analog of an on-deck circle). The time waiting in queue is not factored into the time that is output. You can see the code for that calculation here (T and runtime are the variables to pay attention to).