我有几个 Spring Boot 服务可以在本地完美运行,但它们会在 Google App Engine Flexible 上随机重启。这些服务在 Spring Boot 库的帮助下使用 Google Cloud SQL 和 Pub/Sub。
当我部署服务时,它们工作正常,但过了一段时间后,它们会被 App Engine 重新启动。我将它们连接到 Spring Boot admin 的一个实例,我在堆或磁盘空间或其中任何一个中都看不到任何奇怪的东西。有时他们会在几个小时后重新启动,有时会更快。
我尝试将日志记录添加到跟踪日志记录中,似乎服务重启得更快。
我还注意到健康检查被调用了很多次,尽管健康检查的默认配置说它应该是 5 分钟,并且有几次连续健康检查失败 google app yaml config .但我从未在日志中看到任何失败的健康检查。
我看到的是健康检查进展顺利(200 条回复),然后突然停止记录,几分钟后我看到
Start command: java -showversion -agentpath:/opt/cdbg/cdbg_java_agent.so=--log_dir
这意味着应用引擎正在尝试再次启动该应用。
app.yaml 看起来像:
运行时:Java
环境:弹性
服务:x服务
资源:
内存_gb:1.0
自动缩放:
min_num_instances:1
max_num_instances:2
环境变量:
SPRING_PROFILES_ACTIVE:“开发”
liveness_check:
路径:“/执行器/健康”
就绪检查:
路径:“/执行器/健康”
最佳答案
所以在做了一些研究之后,我可能会对你的问题有所帮助。
I also noticed that the healthcheck gets called a lot, even though the default configuration of the healthcheck says it should be 5 mins and a couple of failed consecutive healthchecks google app yaml config. But I never see any failed healthchecks in the logs.
这是正常行为,因为 Google 有多余的健康检查器:
"健康检查频率
为确保高可用性,App Engine 为每个运行状况检查器创建了冗余副本。如果健康检查器失败,冗余的检查器可以立即接管。
如果您检查应用程序的 nginx.health_check 日志,您可能会发现运行状况检查轮询发生的频率比您配置的要高,这是因为冗余的运行状况检查程序也遵循您的设置。这些冗余健康检查程序是自动创建的,您无法配置它们。”
I have a couple of Spring Boot services that work perfectly locally but they restart after random time on Google App Engine Flexible. These services use google Cloud SQL and Pub/Sub with help of the Spring Boot libraries.
When I deploy the services they work fine, but after a while they get restarted by App Engine. I hooked them up to an instance of Spring Boot admin and I can't see anything strange in the heap or disk space or any of these. Sometimes they reboot after a few hours, sometimes faster.
看看 GAE 管理实例的方式,只要您的应用程序持续响应请求,这可能是一种正常行为。通过使用 automatic_scaling
,您可以定义动态实例。动态实例根据它们接收的负载打开/关闭。所以,您可能会看到自动缩放在起作用。转到 2 个实例,然后返回到一个实例,依此类推。
我会邀请您通过将 target_utilization
的默认阈值增加到类似 0.9
的值来测试它,看看它是否经常扩展。或者只是使用 manual_scaling
所以你只有常驻实例。进行测试的原因是,您看到的日志可能是应用引擎实例管理的预期行为。由于您的应用程序对健康检查和准备情况的响应正常,并且您提到内存利用率没有显示出任何异常,那么除了自动缩放功能之外,我想不出任何其他可能导致这种情况的原因。
希望对您有所帮助!
来源:
https://cloud.google.com/appengine/docs/flexible/java/reference/app-yaml https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml https://cloud.google.com/appengine/docs/flexible/java/how-instances-are-managed
关于spring-boot - Spring Boot 应用程序在 App Engine Flexible 上不断重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53190776/