Python - Google App Engine 部署期间超出内存限制

My *_*Car 5 python google-app-engine limit google-cloud-platform google-app-engine-python

我正在创建一个 Python 项目并将其部署到 Google App Engine。

当我在另一个项目中使用部署的链接时,我在 Google Cloud Logging 中收到以下错误消息:

Exceeded hard memory limit of 256 MB with 667 MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml.
Run Code Online (Sandbox Code Playgroud)

所以,我查看了这个这个链接,以下是要点:

  • 实例类 内存限制 CPU限制 支持的缩放类型
    F1(默认) 256MB 600兆赫 自动的
    F2 512MB 1.2GHz 自动的
    F4 1024MB 2.4GHz 自动的
    F4_1G 2048MB 2.4GHz 自动的
  • instance_class: F2

该错误表明限制为 256 MB,但记录了 667 MB。F1 的内存限制和 F2 的内存限制均小于 667 MB。所以我添加instance_class: F2app.yaml更改F2F4.

当我执行上述操作时,我在 Google Cloud Logging 中收到以下错误:

Exceeded hard memory limit of 1024 MB with 1358 MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml.
Run Code Online (Sandbox Code Playgroud)

这有点奇怪,因为记录的内存是从 667 MB 到 1358 MB。

F4_1G的内存限制超过1358MB,所以我instance_class: F4改为instance_class: F4_1G. 但它在 Google Cloud Logging 中显示以下错误:

Exceeded hard memory limit of 2048 MB with 2194 MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml.
Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为记录的内存从 667 MB 变为 1358 MB,再到 2194 MB。

更新:

我在没有额外实例类的情况下重现了这个问题。

请参考下面的错误日志:

0: {
logMessage: "Exceeded soft memory limit of 256 MB with 924 MB after servicing 0 requests total. Consider setting a larger instance class in app.yaml."
severity: "CRITICAL"
time: "2022-10-19T06:00:39.747954Z"
}
1: {
logMessage: "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."
severity: "INFO"
time: "2022-10-19T06:00:39.748029Z"
}
2: {
logMessage: "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."
severity: "WARNING"
time: "2022-10-19T06:00:39.748031Z"
}
Run Code Online (Sandbox Code Playgroud)

另一个发现:

当应用程序在本地终端运行时,它会消耗 1 GB - 3 GB 内存来运行应用程序完全加载,大约需要 30 秒。同时,空闲状态下的内存使用量为 700 MB - 750 MB,服务单个请求时的内存使用量为 750 MB - 800 MB。

谁能向我解释为什么会发生这种情况?如何修复此错误并成功使用部署的链接?如果有人能帮助我解决这个问题,我将不胜感激。先感谢您!

My *_*Car 1

首先,我将较大的文件从本地存储到云端。然后我成功地将代码部署到 Google App Engine,没有任何错误。