简体   繁体   English

Java Hibernate中的Google Cloud SQL数据库连接错误

[英]Google Cloud sql database connection error in java hibernate

I am using Google Cloud SQL using machine type of db-f1-micro for a project deployed on Google App Engine in Standard Environment(JAVA). 我将db-f1-micro机器类型的Google Cloud SQL用于在标准环境(JAVA)中部署在Google App Engine上的项目。 Sometimes, I got below error while connecting with database. 有时,我在连接数据库时遇到错误。 This scenario happens when open same page in multiple tabs at the same time(load/performance testing). 当在多个选项卡中同时打开同一页面(负载/性能测试)时,会发生这种情况。

Source code used in project from https://github.com/GoogleCloudPlatform/appengine-cloudsql-native-mysql-hibernate-jpa-demo-java 项目中使用的源代码来自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)

The metrics from app engine log for error and mysql usage. 应用引擎日志中的指标用于错误和mysql使用情况。 You can easily see that mysql active connection usage is below 100%. 您可以轻松地看到mysql活动连接使用率低于100%。

在此处输入图片说明

在此处输入图片说明

Please suggest what wrong I am doing? 请指出我在做什么错?

From https://cloud.google.com/appengine/docs/standard/java/cloud-sql/pricing-access-limits 来自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实例与Google Cloud SQL实例的并发连接不能超过12个。”

How many requests are sending to App Engine and how many connections does the app instance open for each of those requests ? 向App Engine发送了多少个请求,并且针对每个请求打开了多少实例连接?

Looks like this thread is old but we have this problem in our test environment. 看起来这个线程很旧,但是我们的测试环境中存在这个问题。 It happens frequently and repeatedly after our GAE test system is not used for a while. 在一段时间不使用我们的GAE测试系统后,它经常重复发生。 The first time someone tries to access the app we get one or two of these. 有人第一次尝试访问该应用程序时,我们会获得其中的一两个。

I assume it has something to do with GAE ramping up a server instance. 我认为这与GAE增加服务器实例有关。 Although I'm not sure why this happens with the db. 虽然我不确定为什么在数据库中会发生这种情况。 I don't think we have any connection pooling (specifically because GAE can make our app go dormant). 我认为我们没有任何连接池(特别是因为GAE可以使我们的应用进入休眠状态)。

And with the app just starting up, we can't be exceeding any connection limits. 随着应用程序的启动,我们不能超过任何连接限制。

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

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