Google云SQL+Hikari CP+通讯link失败

Google Cloud SQL + Hikari CP + Communications link failure

我遇到 Spring 启动应用程序与 D1 Google CloudSQL Server 通信的间歇性连接错误,配置设置在此处描述 HikariCP MySQL settings

我想知道以前是否有人遇到过这种情况。

我已阅读此处发布的常见问题解答Hikari FAQ,我想知道我的默认 idleTimeout 和 maxLifeTime(30 分钟)设置是否有问题;服务器上的 wait_timeout 和 interactive_timeout 都设置为默认 28800s(8 小时)。

常见问题解答说这两个设置应该比服务器设置少一分钟左右,但是如果我在 30 分钟后失去连接,我不太明白将 maxLifeTime 提高到 7 小时 59 分钟会有什么改善情况。

有没有人有什么建议?

已编辑的堆栈跟踪:

不时获取这些

org.springframework.security.authentication.InternalAuthenticationServiceException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Timeout after 30018ms of waiting for a connection.
    at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:110)
    at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:132)
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:177)
...
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Timeout after 30023ms of waiting for a connection.
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
 ....
 Caused by: java.sql.SQLException: Timeout after 30023ms of waiting for a connection.
    at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:208)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:108)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ... 59 common frames omitted

    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:630)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:695)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:727)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:737)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:787)

休眠搜索:

2015-02-17 10:34:17.090  INFO 1 --- [ entityloader-2] o.h.s.i.SimpleIndexingProgressMonitor    : HSEARCH000030: 31050 documents indexed in 1147865 ms
2015-02-17 10:34:17.090  INFO 1 --- [ entityloader-2] o.h.s.i.SimpleIndexingProgressMonitor    : HSEARCH000031: Indexing speed: 27.050219 documents/second; progress: 99.89%
2015-02-17 10:41:59.917  WARN 1 --- [ntifierloader-1] com.zaxxer.hikari.proxy.ConnectionProxy  : Connection com.mysql.jdbc.JDBC4Connection@372f2018 (HikariPool-0) marked as broken because of SQLSTATE(08S01), ErrorCode(0).

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,611,087 milliseconds ago.  The last packet sent successfully to the server was 927,899 milliseconds ago.

我认为目前索引不是特别快,因为我没有使用投影。该过程大约需要 30 分钟才能执行。

谢谢

这里可能有几件事。首先,无论 MySql 设置如何,应用程序层和数据库层之间的网络基础设施(防火墙、负载平衡器等)都可以施加自己的连接超时。

索引失败表示连接在池外约 27 分钟,并且在发生失败时没有 SQL activity。

其次,具体关于"Could not get JDBC Connection"错误,你可能会运行变成Cloud SQL connection limits

我推荐三样东西。第一,确保您使用的是最新的 HikariCP (2.3.2) 和最新的 MySql Connector/J 驱动程序 (5.1.34)。第二,为 com.zaxxer.hikari 包启用 DEBUG 级别的日志记录。 HikariCP 调试日志记录不是 "chatty",而是每 30 秒记录一次池统计信息(有时在失败情况下会更详细)。最后,尝试将 maxPoolSize 设置为更小的值(除非已经是默认值),并将 maxLifeTime 设置为 15 或 20 分钟(1200000 毫秒)。

如果错误再次发生,post 更新了包含失败前后 HikariCP 调试日志的日志。另外,请随意在 Github 上打开一个跟踪问题,因为更大的日志等在那里更容易。