3

Over the past week I've been seeing the number of instances on my GAE Flexible Environment fall to 0, with no new instance spinning up. My understanding of the Flexible environment is that this shouldn't be possible... (https://cloud.google.com/appengine/docs/the-appengine-environments)

I was wondering if anyone else has been seeing these issues, or if they've solved the problem on their end before. My one hypothesis is that this might be an issue with my health monitoring endpoints, but haven't seen anything that jumps out as a problem when I review the code.

This hasn't been a problem for me until last week, and now it seems like I have to redeploy my environment (with no changes) every couple of days just to "reset" the instances. It's worth noting that I have two services under this same App Engine project, both running flexible versions. But I only seem to have this issue with one of the services (what I call the worker service).

Screenshot from App Engine UI:

Screenshot from App Engine UI

Screenshot from Logs UI that shows the SIGTERM being sent:

Screenshot from Logs UI that shows the SIGTERM being sent

PS - Could this have anything to do with the recent Google Compute issues that have been coming up... https://news.ycombinator.com/item?id=18436187

Edit: Adding the yaml file for "worker" service. Note that I'm using Honcho to add an endpoint to monitor health of the worker service via Flask. I added those code examples as well.

yaml File

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

Procfile for Honcho

default: gunicorn -b :$PORT main:app
worker: python tasks.py
monitor: python monitor.py /tmp/psq.pid

monitor.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)
vrk7bp
  • 75
  • 1
  • 6
  • Can you show the `app.yaml` scaling configuration for that service? What do you see if you're trying to access the service? – Dan Cornilescu Nov 14 '18 at 12:15
  • @DanCornilescu, just added more details. When I try to access the service with 0 instances, I see something along the lines of "The service is down, please try again in 30 seconds". This seems like a default page that GAE shows if a service is down... once I redeploy I get the 'healthy' result based on my Flask endpoint. – vrk7bp Nov 14 '18 at 23:34
  • Yep, sounds like a problem with the GAE instance management, there really should have been at least one instance running as you have auto scaling with `min_num_instances: 1`. True, during unexpected outages or during the periodic (weekly I believe) instance restarts I'm not certain if the requirement is still met, but even if it's not - it should only be for a brief, transitory moment, there should be no extended periods with no instances running. – Dan Cornilescu Nov 15 '18 at 03:34
  • Thanks @DanCornilescu... do you have any suggestions on the best way to reach out to the Google Cloud folks about this? – vrk7bp Nov 19 '18 at 16:23
  • Check the open issue list at https://issuetracker.google.com/issues?q=status:open%20componentid:187250 and maybe open a new one if nothing appears to be matching, mentioning this SO post. – Dan Cornilescu Nov 19 '18 at 18:02
  • @vrk7bp did you get an answer for them or did you come by a resolution to this? I have the same happening to me even though it clearly states in the docs that flexible environments cannot scale to 0 instances, and the application logs in stackdriver simply run silent when this happens, no info that anything could have gone wrong. – Vee6 Mar 04 '20 at 09:58

0 Answers0