GCP Cloud Run 503 Error: Service Unavailable for long running request

GCP Cloud Run 503 Error: Service Unavailable for long running request

我在 NodeJS 中构建了 4 个 API 端点,并使用 docker 应用程序图像部署在 GCP Cloud 中:

我的应用程序,点击单独的 APIs,returns 响应并将数据保存在云端 SQL。

FROM node:12

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --only=production

# Copy local code to the container image.
COPY . ./

# Run the web service on container startup.
CMD [ "node", "app.js" ]

1 API 大约需要 1 分钟 到 return 响应,当我尝试从邮递员那里尝试并点击云端时,我得到了成功的响应 运行 URL

其他 3 APIs 需要 2 分钟和其他 20 分钟,每个 return 回复,直到那个时候我从 Cloud 运行

收到错误
503 Service Unavailable 
takes: 2 m 1.02 s 
478 B

以下是给出的配置:

Memory allocated: 8 GB
CPU allocated: 4 
Maximum request per container: 20
Request timeout: 3600 seconds

NOTE: I am only hitting one request at a time 

可能是什么问题? 我增加了并发性,但这没有用。 我在 Cloud Function 服务中的应用程序将无法工作,因为超时为 9 分钟。

我可以在 GCP 中使用哪种服务来完成此类工作?

我发现问题出在 NodeJS 请求超时,默认为 120 秒,在下面的帮助下 link 我解决了我的问题。

https://github.com/GoogleCloudPlatform/esp-v2/issues/438

所以我必须在我的代码中执行以下操作:

我可以为整个服务器设置超时:

var server = app.listen();
server.setTimeout(500000); // In milliseconds

或仅针对特定路线:

app.post('/xxx', function (req, res) {
   req.setTimeout(500000);
});

这解决了问题。