简体   繁体   English

executeBatch在Prepared Statement上的效果如何?

[英]How effective is executeBatch on a Prepared Statement?

Subject to this question, asks it all:How effective is executeBatch method? 根据这个问题,问一切:executeBatch方法有效吗? Is there a performance benchmark, that says.. 'if you have 1000 records to be inserted, using a executeBatch instead of executeUpdate saves you x amount of database cycles?' 是否有一个性能基准,即...如果要插入1000条记录,使用executeBatch而不是executeUpdate可以节省x个数据库周期数量?

Or Is this just a convention? 或者这只是一个惯例?

EDIT: Here is what I am working with: a DB2 V 8.1 hosted on Z/OS, a web app that would be inserting 80,000 records at one go in it's worst case scenario execution. 编辑:以下是我正在使用的内容:Z / OS上托管的DB2 V 8.1,这是一个Web应用程序,它将在最糟糕的情况下一次性插入80,000条记录。

Not sure what database you are using. 不确定您使用的数据库。 When I ran a test on this using db2 this is what I saw: 当我使用db2对此进行测试时,这就是我所看到的:

To write to the database: 要写入数据库:

1 insert it took 2500 microseconds. 1插入需要2500微秒。

10 inserts it took 6000 microseconds. 10次​​插入需要6000微秒。 (600 microseconds per write) (每次写入600微秒)

10000 inserts it took about 1 million microseconds. 10000次插入需要大约100万微秒。 ( 100 microseconds per write) (每次写入100微秒)

Performance maxed out there. 性能最大化。 All this means is that there is a huge overhead in sending messages, and using a batch method minimizes this. 所有这些意味着发送消息会产生巨大的开销,并且使用批处理方法可以最大限度地减少这种情况。 Of course, sending inserts/updates in huge batches runs the risk of losing them if the application crashes. 当然,如果应用程序崩溃,以大批量发送插入/更新可能会丢失它们。

Also of note: Exact numbers will vary depending on your DB and settings. 另请注意:确切的数字会因您的数据库和设置而异。 So you will have to find your own "sweet spot." 所以你必须找到自己的“甜蜜点”。 But this gives you an idea. 但这给了你一个想法。

I'm not sure what you're asking, but for inserting many thousands of rows, a batched statement is hugely faster. 我不知道你在问什么,但对于插入的行数千年,成批的语句是巨大的更快。 I can't give you numbers, though. 不过,我不能给你数字。

In my experience, it is significantly faster - even if you are inserting/updating just a few records at a time. 根据我的经验,即使您一次只插入/更新几条记录,它也要快得多。 If you are doing more than one update, I would almost always recommend batching them if it makes sense. 如果您正在进行多次更新,我几乎总是建议在有意义的情况下对它们进行批处理。

That said, you'd have to do some actual testing to figure out the performance improvement for your particular situation. 也就是说,您必须进行一些实际测试才能找出适合您特定情况的性能改进。

JDBC规范第14章说,提交多个SQL语句而不是单独提交可以大大提高性能

在batchExecute()更新语句花费更多时间然后插入语句我正在使用5001插入和更新语句性能的比例是15:84

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

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