我会达到 Heroku 的 Postgres 连接限制吗?

Will I reach Heroku's Postgres Connection Limit?

我想检查一下我对 Heroku 的 Postgres 连接限制的理解。

我目前使用连接限制为 120 的 Postgres Standard 0 插件。我也是 运行 两个 Standard 1x dynos 中的 Django 应用程序。每个 dyno 使用 gunicorn 和两个 worker 运行应用程序。

首先,我假设我的应用程序可以同时处理四个请求是否正确?

其次我会达到 Postgres 连接限制吗?我假设不会,因为在任何时候只有四个连接到 Postgres。

答案是否定的,我不会 运行 使用此设置进入 Postgres 连接限制。最多有四个到 Postgres 的连接。

Heroku 在这里详细介绍了这一点 https://devcenter.heroku.com/articles/python-concurrency-and-database-connections

我认为您唯一需要担心达到连接限制的情况是您使用的是异步服务器。

您最好的选择是通过 ORM 或 pgbouncer 使用连接池。我为 psycopg2 编写了自己的异步线程连接。

您可以在此处的答案中找到我的代码: