繁体   English   中英

删除后JDBC插入会降低性能

[英]JDBC Insert after Delete slows down performance

我按INSERTDELETEINSERTDELETE等顺序运行JDBC查询。我以1000个批次插入一百万条记录,然后在单个查询中删除那些百万条记录,然后再次插入。 在这种情况下,我只对插入性能感兴趣。

当我以10次迭代的循环运行时,在第一次迭代中,性能最快,即11秒,然后在插入下一个迭代之后,性能比上一次慢几秒钟。 但是,当我不在循环中运行时,插入时间非常相似。

知道为什么吗?

for(number of iterations){
      //process insert of million records here, batch size is 1000
      //prepared statement is used and clearBatch is called after every 1000     
      //inserts,
      //at the end prepared statement is closed and connection.commit() is  
      //called

      //Thread.sleep(1000) called here
      //everything is inserted now in the DB so delete what has been inserted  
      //in single query. connection.commit() called again after delete.

      //Thread.sleep(1000) and repeat the same actions until loop finishes.
}

抱歉,我没有代码。

知道为什么每次下一次迭代插入都比较慢吗?

我无法确定是否没有代码,但是我认为您会发生内存泄漏,因此多余的时间是由于垃圾回收所致。 这就可以解释为什么多次运行同一代码而不循环会更快。 运行启用了GC日志记录(-XX:+ PrintGC)的程序,然后查看会发生什么。

为了消除数据库问题,您可能需要用另一个(新)表进行测试,并用truncate表替换delete,以防万一。

暂无
暂无

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

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