如何防止GAE抛出ERROR 502?

How to prevent GAE from throwing ERROR 502?

对于我的情况,这是错误的原因,因为我的应用程序需要很长时间才能发送响应。我只想知道我应该将哪些参数添加到我的 app.yaml 文件中,以便 deadline 从 30 秒更改为大约 120 秒。
我的 app.yaml 代码

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT app:app

runtime_config:
    python_version: 3

resources:
    cpu: 4
    memory_gb: 8

根据官方文档,App Engine Standard 针对具有短期请求的应用程序进行了优化,几百毫秒

但是,一个请求可能需要长达 60 秒的时间才能得到响应。在此时间段之后,请求处理程序将被中断。

How Requests are Handled.

An app that doesn't will not scale well with App Engine's infrastructure.

我建议使用 Google Stackdriver Trace 来查找您的应用程序请求执行时间大于 60 秒的原因。

编辑

所提供的答案适用于 Google App Engine 标准。我注意到您正在使用 Google App Engine Flex。 60 秒限制不适用于 Google App Engine Flex,因为

Application instances run within Docker containers on Compute Engine virtual machines (VM).

App Engine Flex 推荐用于:

Applications that receive consistent traffic, experience regular traffic fluctuations, or meet the parameters for scaling up and down gradually.

Choosing an App Engine environment

30 秒错误超时可能是 gunicorn 服务器超时。

更改您的 app.yaml,添加 -t 120(超时 120 秒):

      runtime: python
      env: flex 
      entrypoint: gunicorn -t 120 -b :$PORT main:app

在这里你可以找到一个相关的 SO 问题