我在Mybatis-plus提升批量插入性能20倍

最近尝试使用MySql,建了一个表40列,每次通过Entity List的方式写入1000条数据。

saveBatch(list);
通过StopWatch一查看,区区1000行数据竟然用时10S,简直不能忍。
开始以为是MybatisPlus的问题,查看了源码,人家的确是批量写入的,没啥毛病。
一番搜索,网友给出了如下方案
数据库连接参数配置了  rewriteBatchedStatements=true 最终得以解决!
master.jdbc.url=jdbc:mysql://xxx.xx.xxx.xx:3306/outreach_platform?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&rewriteBatchedStatements=true

经修改及测试,我的1000条数据写入时间稳定在500ms,在不修改代码,不调整数据库的情况下性能提升高达20倍。

参考:

Mybatis-plus批量插入、批量修改数据saveBatch等速度缓慢

MySQL之rewriteBatchedStatements

批处理 rewriteBatchedStatements=true

介绍MySQL Jdbc驱动的rewriteBatchedStatements参数

MySQL之rewriteBatchedStatements

原文地址:https://www.cnblogs.com/huanghongbo/p/13538589.html