在过去的一周里,我发现我的 GAE 灵活环境中的实例数量降至 0,并且没有新实例启动。我对灵活环境的理解是,这不应该是可能的......(https://cloud.google.com/appengine/docs/the-appengine-environments https://cloud.google.com/appengine/docs/the-appengine-environments)
我想知道是否有其他人看到过这些问题,或者他们之前是否已经解决过这个问题。我的一个假设是,这可能是我的健康监控端点的问题,但当我检查代码时,没有发现任何问题。
直到上周,这对我来说才成为问题,现在看来我必须每隔几天重新部署我的环境(没有任何更改),只是为了“重置”实例。值得注意的是,我在同一个 App Engine 项目下有两个服务,都运行灵活的版本。但我似乎只对其中一项服务(我称之为工作人员服务)有这个问题。
App Engine UI 的屏幕截图:
日志 UI 的屏幕截图显示了正在发送的 SIGTERM:
PS - 这是否与最近出现的 Google 计算问题有关......https://news.ycombinator.com/item?id=18436187 https://news.ycombinator.com/item?id=18436187
编辑:添加“worker”服务的 yaml 文件。请注意,我使用 Honcho 添加端点以通过 Flask 监控工作线程服务的运行状况。我也添加了这些代码示例。
yaml 文件
service: worker
runtime: python
threadsafe: yes
env: flex
entrypoint: honcho start -f /app/procfile worker monitor
runtime_config:
python_version: 3
resources:
cpu: 1
memory_gb: 4
disk_size_gb: 10
automatic_scaling:
min_num_instances: 1
max_num_instances: 20
cool_down_period_sec: 120
cpu_utilization:
target_utilization: 0.7
Honcho 的 Procfile
default: gunicorn -b :$PORT main:app
worker: python tasks.py
monitor: python monitor.py /tmp/psq.pid
监视器.py
import os
import sys
from flask import Flask
# The app checks this file for the PID of the process to monitor.
PID_FILE = None
# Create app to handle health checks and monitor the queue worker. This will
# run alongside the worker, see procfile.
monitor_app = Flask(__name__)
@monitor_app.route('/_ah/health')
def health():
"""
The health check reads the PID file created by tasks.py main and checks the proc
filesystem to see if the worker is running.
"""
if not os.path.exists(PID_FILE):
return 'Worker pid not found', 503
with open(PID_FILE, 'r') as pidfile:
pid = pidfile.read()
if not os.path.exists('/proc/{}'.format(pid)):
return 'Worker not running', 503
return 'healthy', 200
@monitor_app.route('/')
def index():
return health()
if __name__ == '__main__':
PID_FILE = sys.argv[1]
monitor_app.run('0.0.0.0', 8080)