MySQL 中有大量 "SET autocommit=0/1" 查询
Massive number of "SET autocommit=0/1" queries in MySQL
我正在 运行 对我们的系统进行一些负载测试,我注意到正在执行大量 "SET autocommit=0" 和 "SET autocommit=1" 查询。 1分钟内大约有25,000。我正在尝试找出造成这种情况的原因以及如何摆脱它。
我们使用以下技术:
MySQL
休眠
光
Spring
Tomcat
我尝试了以下方法,但似乎没有帮助:
"SET autocommit = 0" 在 MySQL
在数据库连接 URL 中添加了 elideSetAutoCommits 属性。 "jdbc:mysql://localhost/db_name?useUniCode=true&characterEncoding=UTF-8&pinGlobalTxToPhysicalConnection=true&elideSetAutoCommits=true"
有人可以指出可能导致这些查询的原因吗?
Could someone point me towards what might be causing these queries?
您的查询是 Connection#setAutoCommit(boolean)
的结果,它用于从默认模式 自动提交模式 切换到 事务模式 为了 insert/update/delete/read
事务中的数据。
常用密码为:
// Switch to transactional mode which actually triggers a SET autocommit = 0
con.setAutoCommit(false);
try {
// Some operations on the db
con.commit();
} finally {
// Switch back to auto-commit mode which actually triggers a SET autocommit = 1
con.setAutoCommit(true);
}
这是一个很好的 link 解释 how transactions work in JDBC
。
如果您知道您的连接池将始终用于以事务模式获取连接,您可以在 Hikari
的配置中设置默认模式,感谢参数 autoCommit
来设置false
这样连接就已经处于事务模式,因此不再需要修改模式。
This property controls the default auto-commit behavior of connections
returned from the pool. It is a boolean value. Default: true
有关 Hikari
here.
配置的更多详细信息
我正在 运行 对我们的系统进行一些负载测试,我注意到正在执行大量 "SET autocommit=0" 和 "SET autocommit=1" 查询。 1分钟内大约有25,000。我正在尝试找出造成这种情况的原因以及如何摆脱它。
我们使用以下技术:
MySQL
休眠
光
Spring
Tomcat
我尝试了以下方法,但似乎没有帮助:
"SET autocommit = 0" 在 MySQL
在数据库连接 URL 中添加了 elideSetAutoCommits 属性。 "jdbc:mysql://localhost/db_name?useUniCode=true&characterEncoding=UTF-8&pinGlobalTxToPhysicalConnection=true&elideSetAutoCommits=true"
有人可以指出可能导致这些查询的原因吗?
Could someone point me towards what might be causing these queries?
您的查询是 Connection#setAutoCommit(boolean)
的结果,它用于从默认模式 自动提交模式 切换到 事务模式 为了 insert/update/delete/read
事务中的数据。
常用密码为:
// Switch to transactional mode which actually triggers a SET autocommit = 0
con.setAutoCommit(false);
try {
// Some operations on the db
con.commit();
} finally {
// Switch back to auto-commit mode which actually triggers a SET autocommit = 1
con.setAutoCommit(true);
}
这是一个很好的 link 解释 how transactions work in JDBC
。
如果您知道您的连接池将始终用于以事务模式获取连接,您可以在 Hikari
的配置中设置默认模式,感谢参数 autoCommit
来设置false
这样连接就已经处于事务模式,因此不再需要修改模式。
This property controls the default auto-commit behavior of connections returned from the pool. It is a boolean value. Default:
true
有关 Hikari
here.