在服务 Y 请求总数后,X MB 超过了 128 MB 的软私有内存限制

Exceeded soft private memory limit of 128 MB with X MB after servicing Y requests total

我的 App Engine 应用程序出现了可怕的超出内存错误,该应用程序有一个 Cron 作业将多个小任务推送到一个队列。

我认为任何单个任务都不会触发严重错误,所以我猜测它们之间存在某种关联;分享缺少的记忆。 我是 运行 我的队列,最大速率为 4/s,桶大小为 5。

我如何确定 can/should 我做什么?

Exceeded soft private memory limit of 128 MB with 131 MB after servicing 18 requests total
Exceeded soft private memory limit of 128 MB with 128 MB after servicing 1933 requests total
Exceeded soft private memory limit of 128 MB with 153 MB after servicing 3697 requests total

您可以像这样监视内存实例使用情况(我假设 Python):

from google.appengine.api.runtime import memory_usage
logging.warn("Memory usage:  %d MB" % (memory_usage().current()))

您可以执行以下操作:

  1. 降低任务​​率。
  2. 使用内存更大的实例。
  3. 修改您的代码以提高效率。我最近在任务队列中遇到了这个问题,所以我把每个任务都变小了,然后用菊花链连接了一个新任务来继续工作。任务完成后,垃圾收集器应立即为您清理。

当一个任务已经执行了10分钟,它就会终止。此错误消息可能有些令人困惑。