mybaits Batch ExecutorType和for_each Xml之间的性能比较 [英] Performance comparison between mybaits Batch ExecutorType and for_each Xml

查看:83
本文介绍了mybaits Batch ExecutorType和for_each Xml之间的性能比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要使用诱饵插入DB的记录列表.以前,我的代码类似于:

I have a list of records to be inserted into DB using my baits. Previously, my code is something like:

for(Item item :  items){
    sqlSession.insert("insert", item);
}

使用此方法有效,但由于项数的原因,我发现在 Mysql 服务器上有动态增量DiskIO.

Using this method works but I find there is dynamical incremental DiskIO at Mysql server, due to number of items.

由于我几乎无法访问MySql配置,并且希望解决此高磁盘io问题,因此我找到了一些可能的解决方案:

As I have little access to MySql configuration, and hope to resolve this high disk io issue, I find some possible solutions:

  1. ExecutorType.BATCH 用于 sqlSession
  2. 在单个insert语句中插入多个值,例如:插入到项目值中< foreach collection ="list" item ="item" index ="index"分隔符=,">(#{item.a},#{item.b} ...)</foreach>

有人知道哪个解决方案可以解决我的高diskIO问题,这两种解决方案之间的主要区别是什么?谢谢.

Does anyone has idea which one is suitable to solve my high diskIO problem and what the main difference between these two solution? thanks.

推荐答案

尽管很难预测对服务器磁盘I/O的影响,方法1(使用 ExecutorType.BATCH )是推荐的方法.
它基本上一次插入一定数量的项目.
由于它在内部使用JDBC的批处理操作API(该批处理操作API旨在处理许多行),因此您可以从驱动程序的优化中受益.

Although it is difficult to predict the effect on the disk I/O of your server, method 1 (using ExecutorType.BATCH) is the recommended way.
It basically inserts a certain number of items at a time.
As it internally uses JDBC's batch operation API which is designed to handle many rows, you could benefit from optimizations by the driver.

注意:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆