Skip to content

Celery doesn't re-use DB connections with Django (fixes #4116)#4292

Merged
thedrow merged 1 commit into
celery:masterfrom
cuda-networks:master
Oct 1, 2017
Merged

Celery doesn't re-use DB connections with Django (fixes #4116)#4292
thedrow merged 1 commit into
celery:masterfrom
cuda-networks:master

Conversation

@Schweigi

@Schweigi Schweigi commented Sep 27, 2017

Copy link
Copy Markdown
Contributor

Fixes #4116

Celery doesn't re-use DB connections when the setting CONN_MAX_AGE is set in Django. Instead connections are closed immediately. This leads to a high load on the database when there are a lot of Celery workers. It also affects query performance negatively.

This PR uses the Django close_if_unusable_or_obsolete() method to close a DB connection instead of close().

close_if_unusable_or_obsolete() is available at least since Django 1.8 (see django/django@2830807) which is the minimum supported version for Celery 4.0.

Let me know if you need anything else to merge this.

@georgepsarakis georgepsarakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes seem valid to me, see also here and here.

@Schweigi

Copy link
Copy Markdown
Contributor Author

I would like to add that we use this fix successfully in production and hand no issues so far.

@thedrow
thedrow merged commit c086cfd into celery:master Oct 1, 2017
@thedrow

thedrow commented Oct 1, 2017

Copy link
Copy Markdown
Contributor

Thank you very much!

@ograycode

Copy link
Copy Markdown

Are there any plans for a patch fix (4.1.x) that will include this?

@thedrow

thedrow commented Oct 25, 2017

Copy link
Copy Markdown
Contributor

Yes but we still have to merge a few more PRs in order to release 4.1.

@dralley

dralley commented Mar 1, 2018

Copy link
Copy Markdown

@thedrow Is a 4.1.1 coming soon? Are there any PRs blocking it?

@auvipy

auvipy commented Mar 1, 2018

Copy link
Copy Markdown
Member

4.2 is coming one blocker remain. check the milestone

@thedrow thedrow modified the milestone: v4.2 Mar 1, 2018
snopoke added a commit to dimagi/commcare-cloud that referenced this pull request Nov 21, 2018
* setting is not respected by celery < v4.2
  * celery/celery#4292
* not compatible with 'gevent' gunicorn worker class
  * benoitc/gunicorn#996 (comment)
@auvipy

auvipy commented Nov 22, 2018

Copy link
Copy Markdown
Member

this change is creating regression as per reports, should we revert this?

@thedrow

thedrow commented Nov 24, 2018

Copy link
Copy Markdown
Contributor

If people have problems with one method and others have a problem with another we should introduce a configuration option to use either.
The default should be to use the method in this PR in my opinion.
Please file an issue about it.

@thedrow

thedrow commented Nov 24, 2018

Copy link
Copy Markdown
Contributor

@georgepsarakis What do you think?

@georgepsarakis

georgepsarakis commented Nov 24, 2018

Copy link
Copy Markdown
Contributor

@thedrow I read the issues linking here, I think that they mostly concern finding a correct value for CONN_MAX_AGE. I don't think we should revert, but I agree on the setting or better documentation.

@Chronial

Chronial commented Apr 24, 2019

Copy link
Copy Markdown

This PR actually broke celery's DB handling (see #5483). I would suggest a revert.

@thedrow

thedrow commented Apr 24, 2019

Copy link
Copy Markdown
Contributor

@Schweigi Care to weight in?

@auvipy

auvipy commented May 11, 2019

Copy link
Copy Markdown
Member

celery 4.x doesn't support Django-celery package

@auvipy

auvipy commented May 11, 2019

Copy link
Copy Markdown
Member

Please review this patch witch django-celery-beats and results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django celery fixup doesn't respect Django settings for PostgreSQL connections

7 participants