首次运行后,JDBC MySql变慢

时间:2017-11-21 17:38:33

标签: java mysql sql jdbc

我正在尝试记录整合工作,但面临一个奇怪的问题。表有近10M行。表格中只有7个字段,长度为50个字符(只有一个字段,最多500个varchar)。它的引擎是InnoDB。第一次,它运行得很好,但从第二批开始,DB速度慢,我可以在MySql进程列表中看到查询花费了太多时间。 log4j输出下方将显示第一批和第二批之间的差异:

17:05:00.119 [PartialCDRService:165] [] Going to fetch records from DB
17:05:39.710 [PartialCDRService:168] [] Fetched records from DB. Total: 150000
17:06:55.614 [PartialCDRService:217] [] Record Arrays (recordsToAssembleAll) to consolidate size: 31135
17:06:56.303 [PartialCDRService:334] [] Record Arrays 6 Hrs Split to consolidate size: 31135
17:08:02.567 [PartialCDRService:1105] [] CDR Files Size going to be saved in Kafka: 11
17:08:03.321 [PartialCDRService:1134] [] Going to insert records in buff table :: 149995
17:08:18.729 [PartialCDRService:1136] [] Records inserted in buff table
17:08:18.729 [PartialCDRService:1139] [] Going to delete records from table :: 149995
17:08:20.747 [drDao:144] [] Deleted from partial_cdrs. Going to truncate partial_cdrs_buff
17:08:20.772 [PartialCDRService:1142] [] Records deleted from table
17:10:00.007 [PartialCDRService:165] [] Going to fetch records from DB
17:11:58.732 [PartialCDRService:168] [] Fetched records from DB. Total: 150000
17:13:02.918 [PartialCDRService:217] [] Record Arrays (recordsToAssembleAll) to consolidate size: 30826
17:13:03.572 [PartialCDRService:334] [] Record Arrays 6 Hrs Split to consolidate size: 30826
17:14:07.636 [PartialCDRService:1105] [] CDR Files Size going to be saved in Kafka: 11
17:14:08.060 [PartialCDRService:1134] [] Going to insert records in buff table :: 149999
17:25:23.316 [PartialCDRService:1136] [] Records inserted in buff table
17:25:23.316 [PartialCDRService:1139] [] Going to delete records from table :: 149999
17:27:16.408 [PartialCdrDao:144] [] Deleted from partial_cdrs. Going to truncate partial_cdrs_buff
17:27:16.653 [PartialCDRService:1142] [] Records deleted from table
17:27:16.655 [PartialCDRService:165] [] Going to fetch records from DB

PS:partial_cdrs_buff是一个临时表

我正在关闭连接,正确陈述并尽可能使用批次。不想用Java代码发布详细信息。真的卡住了可能出错的地方。我已经尝试了好几次,第一次运行很好,但是DB命中率变慢了,这从MySql' show processlist'命令。有关这方面的任何建议,请

0 个答案:

没有答案