Friday, June 7, 2019

[google-cloud-sql-discuss] Reaching max connections on App Engine django + Cloud SQL postgres

We have a multitenant django application on Python 3.7, deployed on App Engine standard env, instance F4, with a Postgresql Cloud SQL with 1.7gb memory, which allows theorically 50 connections. The page has a neverending ajax calling function that depends on settings; the fastest being every 2 seconds. The endpoint has 4 requests to the database: 1 for session, 1 for tenant, 1 for user and 1 for the data. The endpoint execution time isn't that big, it's just a select for id in an array of ids, inner-joining with another table on id. The whole endpoint request takes around 400ms.

But, having around 5 tabs on browser with this page, it makes the workers and connections to skyrocket up to the limit, displaying the error: OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections. I mitigated it configuring a gunicorn entry point and limiting its workers to 4, and this let me get more tabs open, but I still am getting http code 500 with this error on the ajax calls from time to time. Thus, it seems the configuration is not very scalable atm.

So, what's left for me to configure to stop reaching the limit?

The entry point is configured as:

entrypoint: gunicorn -b :$PORT main:app --workers 4


The db configuration is as follows:

'ENGINE': 'tenant_schemas.postgresql_backend',
'HOST': '/cloudsql/xxxxxx:asia-northeast1:xxxxx',
'USER': 'xxxxxxxx',
'PASSWORD': 'xxxxxxxx',
'NAME': 'xxxxxxx'

Thanks for your help

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/7a9ee6e2-2219-48e8-baec-68d75884bc98%40googlegroups.com.

No comments:

Post a Comment