django-celery-beat icon indicating copy to clipboard operation
django-celery-beat copied to clipboard

Long running celery-beat queries crash postgres database

Open bioworkflows opened this issue 2 years ago • 6 comments

Summary:

The database backend of my website crashes today. Upon inspection, I found all slots are filled with database query, and ran more than 8 hrs.

SELECT "django_celery_beat_periodictasks"."ident", "django_celery_beat_periodictasks"."last_update" FROM 
"django_celery_beat_periodictasks" WHERE "django_celery_beat_periodictasks"."ident" = 1 LIMIT 21 FOR UPDATE

My periodic database had hundreds of insertion/deletion operations today but it has less than 50 entries at peak, so I am wondering what is going on here. Is it some sort of deadlock that prevented these queries from completion?

  • Celery Version: celery==5.3.0b1
  • Celery-Beat Version: django-celery-beat==2.5.0

Exact steps to reproduce the issue:

I am not sure how to reproduce this.

Detailed information

  • Right now I have 25 periodic tasks, 20 or them are executed daily, 5 of them are on crontab, also run daily.
  • The database was hosted on DigitalOcean with a connection pool. The following is the "Currently running queries" from the admin
image

bioworkflows avatar Aug 12 '23 03:08 bioworkflows

We've experienced this issue a few times now and it does eventually eat up all of the available connections and take down the database. Any updates on a possible root cause?

rjcampion3 avatar May 07 '24 18:05 rjcampion3

Hey at @bioworkflows or @rjcampion3 any work around that y'all came up with? I just upgraded a project and am having connections get slurped up by this.

curtisim0 avatar Jul 22 '24 00:07 curtisim0

@curtisim0 We did the following settings in django:

CELERY_BROKER_TRANSPORT_OPTIONS = {
    "socket_keepalive": True,
    "socket_keepalive_options": {
        socket.TCP_KEEPIDLE: 60,
        socket.TCP_KEEPCNT: 5,
        socket.TCP_KEEPINTVL: 10,
    },
}

And we added --without-mingle to the celery command. That seemed to do the trick. I think the without-mingle was the main thing that seemed to resolve it, but the other settings are probably good to have anyway

rjcampion3 avatar Jul 23 '24 19:07 rjcampion3