google-cloud-sql – Google Cloud SQL Hikari CP通信链接失败

我遇到来自Spring Boot应用程序与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)

Hibernate搜索:

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活动.

其次,特别是关于“无法获取JDBC连接”错误,您可能会遇到Cloud SQL connection limits.

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

如果再次发生错误,请在发生故障时发布包含HikariCP调试日志的更新日志.此外,随时可以在Github上打开跟踪问题,因为更大的日志等更容易.

转载注明原文:google-cloud-sql – Google Cloud SQL Hikari CP通信链接失败 - 代码日志