Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q configured to use redis but keeps a continuous connection to db #559

Closed
olichose123 opened this issue May 20, 2021 · 3 comments
Closed

Comments

@olichose123
Copy link

We've deployed an app on AWS and mistakenly configured Q to use the database, which prevented the db from going to sleep and costing us more than anticipated. Having fixed that, it seems that somehow a lone connection to the database is either kept or quickly reconnected upon disconnect, preventing the db from sleeping.

The settings are simple enough (where DB_CONN_MAX_AGE is 60 anyways)

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": os.environ.get("DB_DATABASE"),
        "USER": db_username,
        "PASSWORD": db_password,
        "HOST": os.environ.get("DB_HOST"),
        "PORT": os.environ.get("DB_PORT", "3306"),
        "CONN_MAX_AGE": int(os.environ.get("DB_CONN_MAX_AGE", "60")),
    },
}

Q_CLUSTER = {
    "redis": {
        "host": os.environ.get("REDIS_HOST"),
        "port": os.environ.get("REDIS_PORT"),
    },
    "timeout": 30,
    "max_attempts": 2,
    "retry": 60,
    "save_limit": 30,
    "queue_limit": 20,
    "cached": 60,
}

Tasks are executed each couple of hours so I'd expect the connection to cut until the broker figures out is has to execute something, but there's that one connection that keeps on going even if all instances but the q cluster instance are off.

(Here the part with 0 connections was a shutdown)
image

Any ideas?

@Koed00
Copy link
Owner

Koed00 commented May 20, 2021

The scheduler works by checking the schedule database every 30 seconds for schedules that fall within the current timespan and then creates a task for them. This to cater for minute schedules and one-off scheduled tasks create through the code.
You can turn off the scheduler to prevent the polling, but that's probably not what you want.
We could add a way of reducing the poll interval, but that would then affect the accuracy of the schedules.

@olichose123
Copy link
Author

Thinking out loud here: If I had a different database for scheduling, which would be simple, light and cheap, that would kind of fix my always-on problem, right? Does Django Q support accessing another database?

@olichose123
Copy link
Author

olichose123 commented May 20, 2021

Alternatively, I suppose a solution would be to interact with the POLL config value?

POLL = conf.get("poll", 0.2)

edit: nope

Sets the queue polling interval for database brokers that don’t have a blocking call. Currently only affects the ORM and MongoDB brokers. Defaults to 0.2 (seconds).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants