celery missed heartbeat from w1@iZm5e3ewkwzrm7li62fylqZ 丢失的心跳
在使用celery的时候开启两个worker
w1每隔30s,循环打印1到9
celery multi start w1 -A CeleryPro -l info --pool=solo -Q default --logfile=~tmp/crontablog.log
w2在00:00时刻打印“计算最小值”
celery multi start w2 -A CeleryPro -l info --pool=solo -Q data_queue --logfile=~tmp/crontablog.log
开启beat
nohup celery -A CeleryPro beat -l info --logfile=~tmp/task.log &
日志中出现以下信息
[2019-07-16 15:09:37,198: WARNING/MainProcess] 0
[2019-07-16 15:09:38,199: WARNING/MainProcess] 1
[2019-07-16 15:09:39,201: WARNING/MainProcess] 2
[2019-07-16 15:09:40,201: WARNING/MainProcess] 3
[2019-07-16 15:09:41,203: WARNING/MainProcess] 4
[2019-07-16 15:09:42,204: WARNING/MainProcess] 5
[2019-07-16 15:09:42,855: INFO/MainProcess] missed heartbeat from w1@iZm5e3ewkwzrm7li62fylqZ
[2019-07-16 15:09:43,206: WARNING/MainProcess] 6
[2019-07-16 15:09:44,207: WARNING/MainProcess] 7
[2019-07-16 15:09:45,209: WARNING/MainProcess] 8
[2019-07-16 15:09:46,210: WARNING/MainProcess] 9
[2019-07-16 15:09:46,212: INFO/MainProcess] Task CeleryPro.tasks.upper[15041a43-2b93-44e2-9b9b-4ca0617e1011] succeeded in 10.015910722315311s: 'FUJIE'
解决方案
这个是celery中的线程在做心跳检测的时候超时所导致的,可能是因为我的服务器和redis不在同一区域所造成的网络延迟,默认心跳间隔为2秒,
这里可以去关闭心跳事件或者加长间隔时间
--without-heartbeat
不要发送事件心跳。
--heartbeat-interval
发送工作者心跳的间隔(以秒为单位)
我选择加长间隔时间,将以上命令加上–heartbeat-interval=10
celery multi start w1 -A CeleryPro -l info --pool=solo -Q default --logfile=~tmp/crontablog.log --heartbeat-interval=10
celery multi start w2 -A CeleryPro -l info --pool=solo -Q data_queue --logfile=~tmp/crontablog.log --heartbeat-interval=10
具体查询官方文档
celery.worker.heartbeat的源代码
官方参数说明