Spring Boot应用在Google Cloud App Engine上部署时由于内存限制而无法启动。

huangapple go评论80阅读模式
英文:

Spring Boot app deployed in Google Cloud App Engine not starting up because of memory limit

问题

我在Google Cloud App Engine中部署的Spring Boot应用程序遇到了问题。该应用程序是一个使用JPA和JWT的API,连接到存储在Google Cloud SQL中的MySQL数据库。

问题在于应用程序因内存限制而卡住了。在每个请求之后,日志中会出现以下消息:

  • 在处理0个请求后,内存软限制已超过256 MB,达到了298 MB。考虑在app.yaml中设置更大的实例类。
  • 此请求导致启动了一个新进程来运行您的应用程序,从而首次加载了您的应用程序代码。因此,此请求可能比您的应用程序的典型请求需要更长时间并使用更多CPU。
  • 在处理此请求时,发现处理此请求的进程使用了过多的内存并被终止。这可能会导致下一个请求使用新的进程。如果经常看到此消息,可能存在内存泄漏或使用内存不足的实例。考虑在app.yaml中设置更大的实例类。

我尝试修改src/main/appengine/app.yaml文件以设置不同的配置(更多内存),但在每次更改后都看不到任何区别。就像这个文件被忽略了一样。

这是我的当前app.yaml

runtime: java
env: flex
runtime_config:
  jdk: openjdk8
env_variables:
  SPRING_PROFILES_ACTIVE: "gcp,mysql"

handlers:
- url: /.*
  script: this field is required, but ignored
beta_settings:
  cloud_sql_instances: guitar-tab-manager-api:europe-west3:guitar-tab-manager-db

instance_class: F2

我尝试应用不同的配置,但似乎没有任何效果。也许有人可以提供帮助。提前感谢。

英文:

I'm having a problem with a Spring Boot application deployed in Google Cloud App Engine. The app is an API that uses JPA and JWT and is connected to a MySQL database stored in Google Cloud SQL.

The problem is that the applicacion gets stuck because of memory limit. After every request, I get this messages in the log:

  • Exceeded soft memory limit of 256 MB with 298 MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml.
  • This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
  • While handling this request, the process that handled this request was found to be using too much memory and was terminated. This is likely to cause a new process to be used for the next request to your application. If you see this message frequently, you may have a memory leak in your application or may be using an instance with insufficient memory. Consider setting a larger instance class in app.yaml.

I tried to modify the file src/main/appengine/app.yaml file in order to set a different configuration (with more memory) but I don't see any difference after every change. It's like this file was ignored.

This is my current app.yaml:

runtime: java
env: flex
runtime_config:
  jdk: openjdk8
env_variables:
  SPRING_PROFILES_ACTIVE: "gcp,mysql"
  # JAVA_GC_OPTS: -XX:+UseSerialGC
  # JAVA_USER_OPTS: -XX:MaxRAM=200m

# With -XX:+UseSerialGC This will perform garbage collection inline with the thread allocating the heap memory instead of a dedicated GC thread(s)
# With -Xss512k This will limit each threads stack memory to 512KB instead of the default 1MB
# With -XX:MaxRAM=72m

handlers:
- url: /.*
  script: this field is required, but ignored
beta_settings:
  cloud_sql_instances: guitar-tab-manager-api:europe-west3:guitar-tab-manager-db

# manual_scaling:
#   instances: 1

# instance_class: F4
# manual_scaling:
#   instances: 1

# instance_class: F2
# basic_scaling:
#   max_instances: 5
#   idle_timeout: 10m

instance_class: F2
# automatic_scaling:
#   target_cpu_utilization: 0.65
#   min_instances: 5
#   max_instances: 100
#   min_pending_latency: 30ms  # default value
#   max_pending_latency: automatic
#   max_concurrent_requests: 50

I tried to apply different configurations but nothing seems to work. Maybe someone can help. Thanks in advance.

答案1

得分: 2

对于任何来到这里的人:

我已经通过使用不同的环境使其正常运行。我将环境从 flex 更改为标准环境,并使用 java8 遵循这里解释的配置进行了更改(链接:https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/springboot-appengine-standard)。奇怪的是,现在应用程序消耗的内存比以前多(大约 300Mb),但是现在它可以正常工作了。请注意,不再使用 app.yaml,现在应用程序部署为 WAR 包。

谢谢

英文:

For anyone coming here:

I got it working using a different environment. Instead of flex, I changed the environment to standard with java8 following the configuration explained here. The weird thing is that now the app consumes more memory than before (about 300Mb), but now it's working without issues. Note that app.yaml is not used anymore, and now the application is deployed as a WAR.

Thanks

huangapple
  • 本文由 发表于 2020年5月5日 00:37:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/61597180.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定