1
votes

Looking at the Google-App-Engine's two environments, standard and flex, most of the features offered by standard seem more appropriate for my use case.

According to https://cloud.google.com/appengine/docs/the-appengine-environments, both standard and flex environment support automatic scaling while standard can scale to 0 instances and flex can scale to 1 instance.

According to https://cloud.google.com/appengine/docs/standard/nodejs/config/appref, an option for automatic scaling is specifying the min/max number of instances running at any given moment. I would have thought that this would 'override' standard environment's ability to scale to zero, but after my service had seen no traffic in 15 hours, it still closed the last remaining instance.

I have the following config-settings in my app.yaml file.

runtime: nodejs10
automatic_scaling:
   min_instances: 1
   max_instances: 1 # Increase in production
   target_cpu_utilization: 0.95

I was trying to force GAE to have 1 running instance at any time while in testing. I realize that having a static number of instances running is not the point of automatic scaling, but I plan to increase the maximum number of instances when moving to production. I have also tried adding min_idle_instances: 1 to the settings without any difference.

Can standard environment be forced to have a minimum of 1 running instance at any time?

1

1 Answers

2
votes

A way to ensure that your instance is ready to serve is to configure warm up request.

Bear in mind that even with Warm up request, you might encounter loading request. If your app has no traffic, the first request will always be a loading request and not a warm up. Thus, in my opinion the best way to approach a situation like this is to set 2 min_instances.

  • Example of an express.js handler:

    js
    const express = require('express');
    const app = express();
    
    app.get('/_ah/warmup', (req, res) => {
    // Handle your warmup logic. Initiate db connection, etc.
    });
    
    // Rest of your application handlers.
    app.get('/', handler);
    app.listen(8080);
    
  • Example of app.yaml addition:

      inbound_services:
      - warmup
    

A workaround it could be to use cron job that triggers every minute, so your instance it will be available to serve you. However, even with this approach 2 min_instance is a better solution.