最近負責(zé)的項目需要數(shù)據(jù)同步入庫MySQL,為了測速那種入庫方式效率比較高,為此進行了以下的對比實驗,在此記錄一下
實驗表單數(shù)據(jù)格式
實驗代碼
共三種方法對比
mutiSqlInsert:
一條一條插入,最后一次提交
singleSqlInsert:
用for循環(huán)拼接好插入sql,一次執(zhí)行
executeBatchInsert:
使用MySQL提供的方法executeBatch(),同樣使用一次提交
實驗結(jié)果
1W條數(shù)據(jù)插入
mutiSqlInsert
singleSqlInsert
executeBatchInsert
10W條數(shù)據(jù)插入
mutiSqlInsert
singleSqlInsert
executeBatchInsert
2000條數(shù)據(jù)插入(當(dāng)前kafka設(shè)置的單次最大拉取數(shù)為2000)
Kafka配置截圖
mutiSqlInsert
singleSqlInsert
executeBatchInsert
結(jié)論
在一次性拉取數(shù)據(jù)較少時,mutiSqlInsert和executeBatchInsert的性能相差不大
當(dāng)一次性插入數(shù)據(jù)非常多時,比如10W條,singleSqlInsert的性能會急劇下降,甚至不如mutiSqlInsert
關(guān)于10W條數(shù)據(jù)插入時singleSqlInsert的性能會急劇下降的原因,參考此文
https://blog.csdn.net/Tom_sensen/article/details/127922964文章來源:http://www.zghlxwxcb.cn/news/detail-815078.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-815078.html
到了這里,關(guān)于MySQL不同插入方式性能對比實驗的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!