Heroku - Django - How to reduce cool down of keep alive

45 Views Asked by At

I have an API that creates a model object whenever an action is true.

Slight problem, everytime the API sends some data it creates a connection and these connections dont seem to cool down very quickly.

Connections seem to stay on for more than 60 minutes.

This results in getting the following error: too many connections for role xxx

As a result, I implemented the following code in my prod.py:

from .base import *
from decouple import config
import django_on_heroku 
# Heroku Settings
django_on_heroku.settings(locals(), staticfiles=False)

# Adjust database settings
import dj_database_url

DATABASES['default'] = dj_database_url.config(conn_max_age=450, ssl_require=True)

This was implemnted following Heroku's guidlines : https://devcenter.heroku.com/articles/python-concurrency-and-database-connections

What I was hoping to achieve here was to have connections lasting a maximum of 45 seconds. (users dont need to spend more than 20 seconds on the site to get what they need).

I seem to be missing something. Would you be able to shed some lights?

Is there a better practice to ensure connections do not reach their limit?

Edit: worth mentioning, I am on the Basic plan. Planning to move to Standard0 when ready for production. I am assuming the plan shouldnt affect the ability to define keep alives.

0

There are 0 best solutions below