{"result":"nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
### The error may exist in class path resource [META-INF/sqlmap/update/UpdateDOMapper.xml]
### The error may involve com.snbc.ssms.db.mysql.operation.DAO.update.UpdateDOMapper.queryUpdateByCabinCode
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.","code":1}
1、mysql的wait-timeout 都已經設置比較長的時間。
interactive-timeout = 388000
wait-timeout = 388000
排除此原因
2、在連接配置url 設置 &autoReconnect=true
重新嘗試報錯如下:
java.net.NoRouteToHostException: Cannot assign requested address.
並報錯 can't create conntion to database after retry i 3 times , give up
是由於linux分配的客戶端連接端口用盡, 無法建立socket連接所致,雖然socket正常關閉,但是端口不是立即釋放, 而是處於TIME_WAIT狀態, 默認等待60s後才釋放。
查看linux支持的客戶端連接端口範圍, 也就是28232個端口:
cat /proc/sys/net/ipv4/ip_local_port_range
32768 - 61000
解決方法:
1. 調低端口釋放後的等待時間, 默認爲60s, 修改爲15~30s
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
2. 修改tcp/ip協議配置, 通過配置/proc/sys/net/ipv4/tcp_tw_resue, 默認爲0, 修改爲1, 釋放TIME_WAIT端口給新連接使用。
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
3. 修改tcp/ip協議配置,快速回收socket資源, 默認爲0, 修改爲1.
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
通過上面3項調整, 壓力測試運行正常。