【问题标题】:Will I reach Heroku's Postgres Connection Limit?我会达到 Heroku 的 Postgres 连接限制吗?
【发布时间】:2019-02-16 22:33:58
【问题描述】:

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

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

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

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

【问题讨论】:

标签: python django postgresql heroku gunicorn


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

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

    Python Postgres psycopg2 ThreadedConnectionPool exhausted

    【讨论】:

      猜你喜欢
      • 2020-03-19
      • 2012-08-03
      • 2017-05-24
      • 2018-08-18
      • 2012-06-08
      • 2020-03-03
      • 2018-05-19
      • 2018-01-24
      • 1970-01-01
      相关资源
      最近更新 更多