简体   繁体   English

SQLServer jdbc批量执行性能

[英]SQLServer jdbc batch execute performance

I am using following pattern to execute jdbc batch on the SQLServer 2008 R2. 我正在使用以下模式在SQLServer 2008 R2上执行jdbc批处理。 The batch execute is simple MERGE statement on one table with proper indexes as per MERGE join clause. 批处理执行是一个表上的简单MERGE语句,具有根据MERGE join子句的适当索引。

batchSize = 50;
for(.....){
...
...
...

    //add to batch
    ps.addBatch();
    if (count >= batchSize) {
        result = ps.executeBatch();
        count = 0;
    }
}
if (count > 0) {
    result = ps.executeBatch();
    count = 0;
}

I have very large data pumping into for-loop. 我有非常大的数据泵入for循环。 What i have observed is initially execution of batch of size 50 takes approx. 我所观察到的是,最初执行大小为50的批次需要大约。 150 msec, and then it increases exponentially to 2.5 miunutes when reaches to counts of 400k records! 150毫秒,然后当达到400k记录时,它会指数增加到2.5分钟!

Is there some sqlserver specific tunning needed? 是否需要一些sqlserver特定的调整?

I got it to @30 minutes time for Insert data volume of 400k!!! 我得到了@ 30分钟时间插入数据量400k !!! I have to do following: 我必须做以下事情:

  • Change MERGE to DELETE/INSERT (If kept MERGE it takes 1.5 hrs) 将MERGE更改为DELETE / INSERT(如果保持MERGE需要1.5小时)
  • Increase batch size to 1k 将批量大小增加到1k
  • Commit after every batch execute 每批次执行后提交
  • Call ps.clearBatch() after batch execute 批量执行后调用ps.clearBatch()

That is it... :) 这就对了... :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM