GCP App Engine:处理信号:term + Worker 在每个请求后退出

问题描述 投票:0回答:1

我正在 GCP App Engine 上部署一个小型 Flask 应用程序,但似乎 Gunicorn 在每次请求后都会立即关闭。我正在使用用户会话和 API (atproto) 连接,但我无法保持登录状态,因为它总是断开用户连接。

我读到一些类似的问题是由于发送大文件、执行长请求或其他原因引起的,但这里的情况并非如此,当我在计算机上运行应用程序时,一切都是即时的。

这是我进入主页后第一次请求后得到的日志。 “/”和下面的行是 python 函数的打印结果。 2秒后,工人退出。

2023-09-25 12:15:42 default[20230925t120108]  [2023-09-25 12:15:42 +0000] [11] [INFO] Starting gunicorn 20.1.0
2023-09-25 12:15:42 default[20230925t120108]  [2023-09-25 12:15:42 +0000] [11] [INFO] Listening at: http://0.0.0.0:8081 (11)
2023-09-25 12:15:42 default[20230925t120108]  [2023-09-25 12:15:42 +0000] [11] [INFO] Using worker: gthread
2023-09-25 12:15:43 default[20230925t120108]  [2023-09-25 12:15:42 +0000] [19] [INFO] Booting worker with pid: 19
2023-09-25 12:15:43 default[20230925t120108]  [2023-09-25 12:15:43 +0000] [22] [INFO] Booting worker with pid: 22
2023-09-25 12:15:43 default[20230925t120108]  [2023-09-25 12:15:43 +0000] [23] [INFO] Booting worker with pid: 23
2023-09-25 12:15:43 default[20230925t120108]  [2023-09-25 12:15:43 +0000] [24] [INFO] Booting worker with pid: 24
2023-09-25 12:15:52 default[20230925t120108]  / 
2023-09-25 12:15:52 default[20230925t120108]  Utilisateur non connecté, chargement de la page de connexion
2023-09-25 12:15:54 default[20230925t120108]  [2023-09-25 12:15:54 +0000] [11] [INFO] Handling signal: term
2023-09-25 12:15:54 default[20230925t120108]  [2023-09-25 12:15:54 +0000] [22] [INFO] Worker exiting (pid: 22)
2023-09-25 12:15:54 default[20230925t120108]  [2023-09-25 12:15:54 +0000] [23] [INFO] Worker exiting (pid: 23)
2023-09-25 12:15:54 default[20230925t120108]  [2023-09-25 12:15:54 +0000] [24] [INFO] Worker exiting (pid: 24)
2023-09-25 12:15:54 default[20230925t120108]  [2023-09-25 12:15:54 +0000] [19] [INFO] Worker exiting (pid: 19)
2023-09-25 12:15:55 default[20230925t120108]  [2023-09-25 12:15:55 +0000] [11] [INFO] Shutting down: Master

可能是什么原因造成的?我必须配置gunicorn 以及如何配置?谢谢

python flask google-cloud-platform google-app-engine gunicorn
1个回答
0
投票

由于多种原因,Gunicorn 可能会在 GCP App Engine 上发出每个请求后自行终止:

  • 将 App Engine 实例缩减至零。

  • Gunicorn 设置为在每次请求后终止自身。

  • 由于您的程序或

    gunicorn
    中的缺陷而崩溃。

您可以通过查看 App Engine 日志、

gunicorn
配置或调试应用程序来调查问题。

以下建议可用于在 GCP App Engine 上配置

gunicorn

  • 使用

    --preload
    标志可以改善 App Engine 实例的启动时间并减少对第一个请求的响应延迟。

  • 使用

    --daemon
    标志使 Gunicorn 在后台运行。这有助于防止 App Engine 实例缩小到零。

  • 使用

    --workers
    标志指定要创建的工作进程数。您可以根据应用程序的预期流量负载调整此设置。

  • 使用

    --timeout
    标志指定工作进程处理请求应花费的最长时间。如果请求完成时间超过此时间,工作进程将重新启动。

© www.soinside.com 2019 - 2024. All rights reserved.