【发布时间】:2021-11-09 09:51:32
【问题描述】:
我们在 Hasura 2.0.9 (GCP) 的当前设置中使用 Cloud Run 和 Cloud SQL
Cloud Run 设置为运行最少 5 个实例,最多 150 个实例,平均运行大约 80-90 个实例。
Cloud SQL 设置为接受多达 500 个连接(4vCPU 和 15GB 内存)
Cloud Run 上的平均每秒请求数约为 350
我在 Cloud SQL 上遇到错误:
db=postgres,user=postgres FATAL: remaining connection slots are reserved for non-replication superuser connections
和:
db=postgres,user=postgres FATAL: sorry, too many clients already
Cloud Run 上出现 500/503 错误:
severity: "ERROR". <--- 500
textPayload: "The request failed because the instance could not start successfully."
severity: "ERROR" <--- 503
textPayload: "The request failed because either the HTTP response was malformed or connection to the instance had an error."
这是databases.yaml
- name: default
kind: postgres
configuration:
connection_info:
database_url:
from_env: HASURA_GRAPHQL_DATABASE_URL
isolation_level: read-committed
pool_settings:
connection_lifetime: 600
idle_timeout: 180
max_connections: 400
retries: 1
use_prepared_statements: true
tables: "!include default/tables/tables.yaml"
functions: "!include default/functions/functions.yaml"
上面的 yaml 是否可以使用,或者我应该将 max_connections 限制为 150 个实例 / 500(数据库连接限制)= ~2 max_connections?现在在数据库监控中,我看到连接超出了池的400 max_connections 设置,并达到了Cloud SQL 的500 连接限制。
我找不到最佳位置,因此基础架构不会出现故障。我什至尝试使用pgpool(我已经从databases.yaml 中删除了pool_settings)但它不会变得更好。过去几天我一直在尝试组合,但没有成功。
非常感谢任何帮助。
【问题讨论】:
-
创建网络拓扑图。为所有项目添加最大连接限制。你可以用这个更新你的问题。我的建议是,要么减少 Cloud Run 实例,要么增加现有实例的并发性。更少的单独连接,但一个连接上的流量更多。和/或绝对将 max_connections 增加到更大的值,直到您没有达到其他一些限制,例如内存或 TCP 限制。
-
@Pentium10 感谢您的评论。 Cloud Run 根据 Cloud SQL 配额和限制将每个实例连接到 SQL 限制为 100 个连接。我不知道 Hasura 如何使用连接池设置处理水平缩放,例如。每个实例都有一个包含 400 个连接的池(通过使用上面的
databases.yaml)或者这个池是否跨实例“传播”?我可以在 Cloud SQL 上设置一个标志来增加max_connections,我会尝试实现你的想法并回来。 -
您是如何将 Cloud Run 与 Cloud SQL 连接起来的?如果您只使用连接器,则存在限制,但如果您创建 VPC 连接器,则存在完全不同的限制,这可能是一个很好的可扩展性升级。您是否将 VPC 与 Cloud Run 和 Cloud SQL 结合使用?如果不试试看。
-
@Pentium10 没有 VPC 连接器,我试试这个。我已经将数据库上的
max_connections标志增加到 4.000 次连接,将 Cloud Run 实例的最大客户端数增加到 596,并且在过去 7 小时内到目前为止出现了 0 个错误。
标签: postgresql docker google-cloud-sql google-cloud-run hasura