MySQL不同插入方式性能对比实验

最近负责的项目需要数据同步入库MySQL,为了测速那种入库方式效率比较高,为此进行了以下的对比实验,在此记录一下

实验表单数据格式


实验代码

共三种方法对比

mutiSqlInsert:

一条一条插入,最后一次提交

singleSqlInsert:

用for循环拼接好插入sql,一次执行

executeBatchInsert:

使用MySQL提供的方法executeBatch(),同样使用一次提交

实验结果

1W条数据插入

mutiSqlInsert

singleSqlInsert

executeBatchInsert

10W条数据插入

mutiSqlInsert

singleSqlInsert

executeBatchInsert

2000条数据插入(当前kafka设置的单次最大拉取数为2000)

Kafka配置截图

mutiSqlInsert

singleSqlInsert

executeBatchInsert

结论

在一次性拉取数据较少时,mutiSqlInsert和executeBatchInsert的性能相差不大

当一次性插入数据非常多时,比如10W条,singleSqlInsert的性能会急剧下降,甚至不如mutiSqlInsert

关于10W条数据插入时singleSqlInsert的性能会急剧下降的原因,参考此文
https://blog.csdn.net/Tom_sensen/article/details/127922964

相关推荐
l***9147几秒前
MySQL--》如何在MySQL中打造高效优化索引
android·mysql·adb
big-seal1 分钟前
XML解释
xml·java·数据库
DeepFlow 零侵扰全栈可观测13 分钟前
DeepFlow 全栈可观测性 护航某银行核心系统全生命周期
数据库·人工智能·分布式·云原生·金融
e***582315 分钟前
C#数据库操作系列---SqlSugar完结篇
网络·数据库·c#
L***p31317 分钟前
MYSQL的第一次
数据库·mysql
Y***985118 分钟前
MySQL下载安装及配置
数据库·mysql
Y***h18720 分钟前
Redis 下载与安装 教程 windows版
数据库·windows·redis
TDengine (老段)22 分钟前
TDengine 时区函数 TIMEZONE 用户手册
java·大数据·数据库·物联网·时序数据库·tdengine·涛思数据
yeshihouhou22 分钟前
redis基本类型 5种基本类型
数据库·redis·缓存
r***934825 分钟前
PostgreSQL版本选择
数据库·postgresql