【发布时间】:2016-01-03 21:34:22
【问题描述】:
我编写了一个脚本,它使用 MyBatis 向多个数据库执行大量插入操作。之前的脚本没有使用 MyBatis,而或多或少,快了两倍(100 万条记录需要 25 分钟,使用 MyBatis 需要 1 小时 10 分钟)。我尝试了不同的方法,但我不知道如何配置 MyBatis 以提高其性能。关于我的问题和解决方案的一些具体考虑:
- 数据库位于 VPC 中,因此网络时间很重要。
- 我使用 guice 为每个数据库绑定映射器。连接信息以编程方式设置。当我需要执行插入时,就会得到映射器。
- 需要插入的行没有排序,所以被数据库排队。当队列达到给定大小时,将执行 multirow insert。我可以通过注入的映射器使用更好的东西吗?
- 我使用 pooled 连接。这是否意味着第一次使用映射器然后重用时打开了3个连接?如果给定的映射器每隔几分钟才使用一次,那么这些空闲连接会被关闭吗?
-
有时我会随机收到此错误:
org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 4,030,088 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
我可以做些什么来提高性能并避免通信错误?
【问题讨论】:
-
一个明显的问题:如果以前的解决方案快得多,为什么还要使用 mybatisat?
标签: java mysql database guice mybatis