参考了:http://blog.csdn.net/tolcf/article/details/52102849
后来根据自己情况测试一次,结果如下。
1、mysql insert
####第一种测试情况
batchSize = 5000;
connection.setAutoCommit(false);
prepStatement.addBatch();
##----测试结果如下----
2016-09-1014:53:31:----insert data begin
2016-09-1014:53:32:Start to writedata 'mysql insert' into mysql
!!!!---1-main-mysqlinsert
2016-09-1014:53:52:Finish writing 'mysql insert' data into mysql
2016-09-1014:53:52:----insert data end
----insert 100000data duration=21s
####第二种测试情况:添加了rewriteBatchedStatements=true
db.url=jdbc:mysql://localhost:3306/signaldb?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8
batchSize = 5000;
connection.setAutoCommit(false);
prepStatement.addBatch();
##----测试结果如下----
2016-09-1014:52:42:----insert data begin
2016-09-1014:52:43:Start to writedata 'mysql insert' into mysql
!!!!---1-main-mysqlinsert
2016-09-1014:52:48:Finish writing 'mysql insert' data into mysql
2016-09-1014:52:48:----insert data end
----insert 100000data duration=6s
####基于第二种情况分析下不同的batchSize对性能的影响
插入500万数据
batchSize =5000;----insert 5000000 data duration=250s
batchSize= 50000;----insert 5000000 dataduration=168s
batchSize=100000;----insert 5000000 data duration=181s
插入200万数据
batchSize=8000;----insert 2000000 dataduration=74s
batchSize=10000;----insert 2000000 dataduration=70s
batchSize=15000;----insert 2000000 dataduration=66s
batchSize=20000;----insert 2000000 dataduration=62s
batchSize=30000;----insert 2000000 dataduration=62s
batchSize=50000;----insert 2000000 dataduration=64s
batchSize=100000;----insert 2000000data duration=68s
总结:如果插入数据达到百万级别的话,batchSize设置为记录数/100为最优