简体   繁体   English

当批处理大小很高时,JDBC应用程序会挂起批量插入

[英]JDBC application hangs for bulk insert, when batch size is high

I am trying to do bulk insert from linux server(say server X) using simple JDBC application. 我试图使用简单的JDBC应用程序从Linux服务器(比如服务器X)进行批量插入。

When I try the application with batch size of 5, it is working fine. 当我尝试批量大小为5的应用程序时,它工作正常。

But when I try it with batch size of 500, it is hanging. 但是当我尝试批量大小为500时,它就悬挂了。 I am not getting any error or exception. 我没有收到任何错误或异常。 When I query the database, I could see the 500 rows are inserted but the java application just hangs. 当我查询数据库时,我可以看到插入了500行,但java应用程序只是挂起。 The java application is not exiting. java应用程序没有退出。

The application just hangs at the following method call 应用程序只挂起以下方法调用

try{
// register driver

// establish connection

// create statement
// add insert commands from inputFile to the batch
statemnt.executeBatch();  //---------------application hangs here
}
//catch block followed by finally block to close resources

I tried the same application in different linux server, I was able to successfully execute the application for batch size of 500, the application ran fine and exited normally. 我在不同的linux服务器上尝试了相同的应用程序,我能够成功执行批量大小为500的应用程序,应用程序运行正常并正常退出。

The application is hanging only in server X and only when the batch size is high. 应用程序仅在服务器X中挂起,并且仅在批处理大小较高时才挂起。

Then I checked the strace of the hung process in server X. I found that it is looping in the following system calls 然后我检查了服务器X中挂起进程的strace。我发现它在以下系统调用中循环

$ strace -f -p [hung-java-process-id] $ strace -f -p [hung-java-process-id]

[pid 104273] futex(0x7ffe78013728, FUTEX_WAKE_PRIVATE, 1) = 0
[pid 104273] clock_gettime(CLOCK_MONOTONIC, {9635863, 882169546}) = 0
[pid 104273] clock_gettime(CLOCK_MONOTONIC, {9635863, 882258933}) = 0
[pid 104273] clock_gettime(CLOCK_REALTIME, {1417787058, 859159155}) = 0
[pid 104273] futex(0x7ffe78013754, FUTEX_WAIT_PRIVATE, 1, {0, 49972845}) = -1 ETIMEDOUT (Connection timed out)
[pid 104273] futex(0x7ffe78013728, FUTEX_WAKE_PRIVATE, 1) = 0
[pid 104273] clock_gettime(CLOCK_MONOTONIC, {9635863, 932601035}) = 0
[pid 104273] clock_gettime(CLOCK_MONOTONIC, {9635863, 932677888}) = 0
[pid 104273] clock_gettime(CLOCK_REALTIME, {1417787058, 909571241}) = 0
[pid 104273] futex(0x7ffe78013754, FUTEX_WAIT_PRIVATE, 1, {0, 49977759}) = -1 ETIMEDOUT (Connection timed out)
[pid 104273] futex(0x7ffe78013728, FUTEX_WAKE_PRIVATE, 1) = 0

I checked the list of open files opened by the hung java process and got the following output, which showed the db connection is still open. 我检查了挂起的java进程打开的打开文件列表,得到了以下输出,显示数据库连接仍然打开。

$ lsof -p [hung-java-process-id] | $ lsof -p [hung-java-process-id] | grep TCP grep TCP

COMMAND   PID       USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
java    104273 userid   14u  IPv6 1674188639      0t0  TCP serverX:55744->dbServer:blackjack (ESTABLISHED)

I also tried by setting connection AutoCommit property to false and then called commit after the executeBatch method. 我还尝试将连接AutoCommit属性设置为false,然后在executeBatch方法之后调用commit。 But still I am facing the same issue. 但我仍面临同样的问题。

I also tried by splitting the batch with smaller batch size. 我也试过用较小的批量分割批次。 The application is working fine upto batch size of 29 but when I increase the batch size to 30, it simply hangs without any error or exception. 应用程序工作正常,批量大小为29但是当我将批量大小增加到30时,它只是挂起而没有任何错误或异常。

I could not find the cause of the issue. 我找不到问题的原因。 If strace is showing the cause of the issue, then please let me know, what exactly does it mean and how to resolve it? 如果strace显示问题的原因,那么请告诉我,它究竟是什么意思以及如何解决它? Any help would be much useful. 任何帮助都会非常有用。 Thanks in advance. 提前致谢。

Please note I am using Java 7 . 请注意我使用的是Java 7

I suppose the issue could be caused by some configuration in the linux machine(server X) as the same application is working fine in other machines for large batch size. 我想这个问题可能是由linux机器(服务器X)中的某些配置引起的,因为同一个应用程序在其他机器上工作正常,批量大。 Any insights related to the machine configuration would be very useful for me. 任何与机器配置相关的见解对我来说都非常有用。

which database is it? 它是哪个数据库? I saw some mentions of problems with postgresql drivers, I have no idea whether similar issues happen on other providers. 我看到一些提到postgresql驱动程序的问题,我不知道其他提供商是否会发生类似的问题。

See in GitHub and PostGreSql 请参阅GitHubPostGreSql

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

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