AppEngine Flexible instances constantly respawning

520 views Asked by At

I am deploying a Go application using AppEngine flexible. Below is my app.yaml. Sometimes after I deploy it stabilizes at 1 instance (it's a very low load application), but most of the time it constantly respawns upwards of 6 instances. My logs are filled with messages showing the new instances being created. There is nearly zero load on this application, why is AppEngine flexible constantly destroying and respawning instances?

Log showing constant respawning:

Log showing constant respawning.

app.yaml

runtime: go
api_version: go1
env: flex

handlers:
- url: /.*
  script: _go_app

health_check:
  enable_health_check: True
  check_interval_sec: 10
  timeout_sec: 4
  unhealthy_threshold: 2
  healthy_threshold: 2

automatic_scaling:
  min_num_instances: 1
  max_num_instances: 10
  cool_down_period_sec: 120 # default value
  cpu_utilization:
    target_utilization: 0.5
1

There are 1 answers

0
Kevin Flanagan On BEST ANSWER

The problem was with my health check function. It originally looked like this:

func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
    return
}

I then discovered this sentence in the documentation on how instances are managed:

You can write your own custom health-checking code. It should reply to /_ah/health requests with a HTTP status code 200. The response must include a message body, however, the value of the body is ignored (it can be empty).

So I changed the health check function to write a simple "ok" in response:

func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("ok"))
    return
}

The instances now behave according to my autoscale settings! The respawning is gone.

I obviously should have read the documentation closer, but there was zero indication of a problem in the health check logs. All health checks looked like they were passing. Hopefully this info is helpful to others.