因此,我构建了一个聊天应用程序并将其与heroku一起部署。由于我在hobby-dev上,所以我只能与Postgres建立20个连接,因此,根据一些在线建议,我决定使用pgbouncer可能是个好主意。关于设置构建包的heroku文档(例如https://devcenter.heroku.com/articles/python-concurrency-and-database-connections#number-of-active-connections的最后一部分)是有限的,我发现的所有内容都要求我更改Procfile中的某些内容。问题是我使用的是docker容器,因此最终使用heroku.yml和daphne命令运行该程序。在网络中直接添加bin/start-pgbouncer
只会导致整个应用程序失败。
这是我当前的运行命令
run:
web: daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2
我试过了
run:
web: bin/start-pgbouncer-stunnel daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2
和
run:
web: start-pgbouncer-stunnel daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2
都失败了。我还在heroku日志中发现heroku似乎会自动将
/bin/sh -c
附加到我的运行命令中(例如/bin/sh -c daphne\ test_project.asgi:application\ --port\ \53166\ --bind\ 0.0.0.0\ -v2
)。这可能引起问题吗?我应该在网络中放置什么以与我的应用程序一起运行pg-bouncer?
最佳答案
最简单的解决方案是创建一个bash脚本run.sh
。
set -ev
service pgbouncer start
daphne test_project.asgi:application --port $PORT --bind 0.0.0.0 -v2
service pgbouncer stop
run:
web: run.sh
关于docker - 如何使用daphne在heroku.yml中运行pgBouncer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59999516/