GoogleCloudPlatform / elixir-runtime

The community-supported runtime for Elixir on Google App Engine.
https://cloud.google.com/elixir
Apache License 2.0
181 stars 14 forks source link

Connection/Pooling Issue with Cloud SQL #20

Open kjrocker opened 5 years ago

kjrocker commented 5 years ago

I've gotten my app and my database talking to each other, but my SQL and App Engine logs are being absolutely flooded by connection errors anyway.

On the App Engine side, I'm seeing the usual /cloudsql/project:region:database/.s.PSQL.5432 not found error. But on the Cloud SQL side, I'm seeing FATAL: remaining connection slots are reserved for non-replication superuser connections

Again: I have pages that launch DB queries that I can load reliably without 500s, so they are actually talking to each other, but something else is clearly going on here.

My limited research has shown that a base PostgresQL instance can support up to 100 connections, and the default pool size I've seen for Phoenix in production is 20.

zeroasterisk commented 5 years ago

@kjrocker do you have a sample project which can replicate this for me?

Basic connection info: https://cloud.google.com/sql/docs/postgres/external-connection-methods And specific to Google App Engine: https://cloud.google.com/sql/docs/postgres/connect-app-engine

That page has a callout which says:

App Engine Standard only supports connections to PostgreSQL from the following runtimes: Python 3.7, Java 8, PHP 7.2, Go 1.11, Node.js

But @dazuma has a tutorial which connects in this same way: https://cloud.google.com/community/tutorials/elixir-phoenix-on-google-app-engine

Access the production database from App Engine The App Engine runtime also runs a Cloud SQL Proxy for you, and makes your databases available via Unix sockets. In the App Engine environment, these are located in the directory /cloudsql at the root of the file system. So, to prepare your app for deployment into App Engine, edit your config/prod.secret.exs file again, and modify the socket_dir database setting to point to the correct location for App Engine... Note that if you need to run another Ecto migration or open another psql session from your local workstation, you can temporarily revert socket_dir to /tmp/cloudsql so that Phoenix can talk to your local Cloud SQL Proxy. If you do, make sure you change it back to /cloudsql before you deploy to App Engine. Alternatively, if you have the ability to create the directory /cloudsql on your local workstation, you can configure Cloud SQL Proxy to open its sockets there instead, and avoid the need to revert socket_dir.