在 MariaDB 连接器中设置极光后数据库连接增加
DB connections increase after setting aurora in MariaDB connector
我们正在使用 MariaDB JDBC 连接器 Aurora 特定功能测试故障转移行为。
我们已将 JDBC URL 设置为 the documentation suggest:
jdbc:mysql:aurora://cluster.cluster-xxxx.us-east-1.rds.amazonaws.com/db
问题是,一旦我们在 URL 模式中添加 aurora:
部分,我们就可以看到与数据库编写器的连接增加,直到我们必须回滚更改(它甚至达到 3.000 个连接)。
版本:
配置:
master {
profile = "slick.jdbc.MySQLProfile$"
db {
driver = "org.mariadb.jdbc.Driver"
url = "jdbc:mysql:aurora://cluster-name.cluster-xxx.us-east-1.rds.amazonaws.com/db_name?characterEncoding=utf8mb4&rewriteBatchedStatements=true&usePipelineAuth=false"
user = "rw_user"
password = "rw_user_pass"
numThreads = 20
queueSize = 1000000
}
}
slaves = [
{
profile = "slick.jdbc.MySQLProfile$"
db {
driver = "org.mariadb.jdbc.Driver"
url = "jdbc:mysql:aurora://cluster-name.cluster-ro-xxx.us-east-1.rds.amazonaws.com/db_name?characterEncoding=utf8mb4&usePipelineAuth=false"
user = "ro_user"
password = "ro_user_pass"
numThreads = 20
queueSize = 1000000
}
}
]
我们尝试在升级 MariaDB 连接器版本后将 aurora:
部分添加到 JDBC URL 模式,但是 Reader 的连接数又开始增加了:
如果我们在只读端点上运行一个show processlist
,我们可以看到所有打开的连接处于"cleaned up"状态,并且"Sleep"命令。
我们从只读端点中删除了 aurora:
部分,只是为了稳定与它的连接数。驱动程序是否有可能在打开连接时搜索集群主机?这可以解释这种行为。
一旦您超过几十个 活动 连接,数据库就会开始绊倒自己。最好限制客户端中的连接,而不是假设您有无限带宽来接受 Aurora 中的连接。
使用 "aurora" 关键字时,驱动程序在后台创建 2 个连接:
- 与主服务器的连接,
- 与副本之一的连接(如果有)。
目标始终是节省主服务器上的资源。一般只配置一个pool。然后,驱动程序根据 [Connection.setReadOnly] [1].
使用与主/副本的连接
当您有单独的 "write" / "read" 池时,使用配置 "failover" 将解决您的问题:驱动程序将仅使用一个真实连接。
这样就不会有"wasted"连接了。
故障转移将以不同方式处理,但结果相同(例如,不在要发送到刚刚崩溃的副本的事务中的查询将不会像使用 "aurora" 配置,驱动程序将在执行查询之前重新创建到另一个副本的新连接。
我们正在使用 MariaDB JDBC 连接器 Aurora 特定功能测试故障转移行为。
我们已将 JDBC URL 设置为 the documentation suggest:
jdbc:mysql:aurora://cluster.cluster-xxxx.us-east-1.rds.amazonaws.com/db
问题是,一旦我们在 URL 模式中添加 aurora:
部分,我们就可以看到与数据库编写器的连接增加,直到我们必须回滚更改(它甚至达到 3.000 个连接)。
版本:
配置:
master {
profile = "slick.jdbc.MySQLProfile$"
db {
driver = "org.mariadb.jdbc.Driver"
url = "jdbc:mysql:aurora://cluster-name.cluster-xxx.us-east-1.rds.amazonaws.com/db_name?characterEncoding=utf8mb4&rewriteBatchedStatements=true&usePipelineAuth=false"
user = "rw_user"
password = "rw_user_pass"
numThreads = 20
queueSize = 1000000
}
}
slaves = [
{
profile = "slick.jdbc.MySQLProfile$"
db {
driver = "org.mariadb.jdbc.Driver"
url = "jdbc:mysql:aurora://cluster-name.cluster-ro-xxx.us-east-1.rds.amazonaws.com/db_name?characterEncoding=utf8mb4&usePipelineAuth=false"
user = "ro_user"
password = "ro_user_pass"
numThreads = 20
queueSize = 1000000
}
}
]
我们尝试在升级 MariaDB 连接器版本后将 aurora:
部分添加到 JDBC URL 模式,但是 Reader 的连接数又开始增加了:
如果我们在只读端点上运行一个show processlist
,我们可以看到所有打开的连接处于"cleaned up"状态,并且"Sleep"命令。
我们从只读端点中删除了 aurora:
部分,只是为了稳定与它的连接数。驱动程序是否有可能在打开连接时搜索集群主机?这可以解释这种行为。
一旦您超过几十个 活动 连接,数据库就会开始绊倒自己。最好限制客户端中的连接,而不是假设您有无限带宽来接受 Aurora 中的连接。
使用 "aurora" 关键字时,驱动程序在后台创建 2 个连接:
- 与主服务器的连接,
- 与副本之一的连接(如果有)。
目标始终是节省主服务器上的资源。一般只配置一个pool。然后,驱动程序根据 [Connection.setReadOnly] [1].
使用与主/副本的连接当您有单独的 "write" / "read" 池时,使用配置 "failover" 将解决您的问题:驱动程序将仅使用一个真实连接。 这样就不会有"wasted"连接了。
故障转移将以不同方式处理,但结果相同(例如,不在要发送到刚刚崩溃的副本的事务中的查询将不会像使用 "aurora" 配置,驱动程序将在执行查询之前重新创建到另一个副本的新连接。