I have some fairly busy celery queues, but not sure which tasks are the problematic ones. Is there a way to aggregate results to figure out which tasks are taking a long time? I have 10-20 workers on 2-4 servers.
Using redis as the broker and as the result backend as well. I noticed the busy queues on Flower, but can't figure out how to get time statistic aggregated per task.
Method 1:
If you have enabled logging when celery workers are started, they log time taken for each task.
This will generate logs like this
You can filter lines which have
succeeded in
. Split these lines using,
[
,:
as delimiters, print task name and time taken by each of it and then sort all the lines.As you can see
add
is very fast &foo
is slow.Method 2:
Celery has
task_prerun_handler
,task_postrun_handler
signals which run before/after task. You can hookup functions which will track time and then note the time somewhere.References: https://stackoverflow.com/a/31731622/2698552