Google Cloud sql java hibernate 中的数据库连接错误

Google Cloud sql database connection error in java hibernate

我正在使用 Google 云 SQL 使用机器类型 db-f1-micro 部署在 Google App Engine 上的项目在标准环境中(JAVA)。有时,我在连接数据库时遇到以下错误。当同时在多个选项卡中打开同一页面时会发生这种情况(load/performance 测试)。

项目中使用的源代码来自 https://github.com/GoogleCloudPlatform/appengine-cloudsql-native-mysql-hibernate-jpa-demo-java

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. at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)

来自 App Engine 日志的错误指标和 mysql 使用情况。 您可以轻松地看到 mysql 活动连接使用率低于 100%。

请指出我做错了什么?

来自https://cloud.google.com/appengine/docs/standard/java/cloud-sql/pricing-access-limits

"Each App Engine instance cannot have more than 12 concurrent connections to a Google Cloud SQL instance."

有多少请求发送到 App Engine,应用程序实例为每个请求打开了多少连接?

看起来这个线程是旧的,但我们在测试环境中遇到了这个问题。在我们的GAE测试系统一段时间不使用后,它会频繁重复出现。第一次有人尝试访问该应用程序时,我们会得到其中的一两个。

我认为它与 GAE 提升服务器实例有关。虽然我不确定为什么数据库会发生这种情况。我不认为我们有任何连接池(特别是因为 GAE 可以让我们的应用程序进入休眠状态)。

应用刚刚启动,我们不能超过任何连接限制。