簡體   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