Accelerate scale out with suspended and stopped VMs


This document explains how the standby pool of suspended and stopped virtual machine (VM) instances works and how you can use the standby pool to accelerate the scale out of a managed instance group (MIG).

Before you begin

  • Review the introductory page about suspended and stopped VMs in a MIG.
  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. Set a default region and zone.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init

Use MIG API for autoscaling

We recommend that you use Compute Engine autoscaler for autoscaling your MIG. However, if for some reason you prefer to use a different autoscaler, use the endpoints of the MIG API to handle suspended and stopped VMs.

With the MIG API, you can connect your autoscaler, for example GKE autoscaler, and leverage the standby pool of VMs for quicker scale out.

Choose between suspended and stopped pools

Choosing between suspended and stopped pools depends on your specific use case. For best performances, you should experiment with different standby pool types for your scale out scenarios to determine which one best suits your needs. Different workloads might show shorter time to serve with different options. In some cases, the operation of copying the memory state from storage to the VM might take more time than restarting the VM or creating a new VM from scratch.

To find the best approach, start from these guidelines:

  • Use suspended VMs if your VMs require a time-consuming memory initialization, because suspended VMs preserve the memory state. Make sure that your application can be suspended and resumed. Keeping the memory state requires additional storage and might incur extra costs.
  • Use stopped VMs if your VM initialization focuses mainly on the initialization of data stored in the persistent disks.

Edit the standby policy in a MIG

This section describes how to set the initial delay and how to set the standby pool mode to scale out pool.

Console

  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Under the Name column of the list, click the name of the instance group where you want to edit the standby policy.

  3. Click Edit to modify this managed instance group.

  4. Click Show advanced configuration.

  5. In the Standby pool section, under Mode, select Scale-out.

  6. In the Initial delay field, enter the number of seconds that the MIG should wait before suspending or stopping a VM. The initial delay gives the initialization script the time to prepare your VM for quick scale out.

  7. Click Save.

gcloud

Use the beta instance-groups managed update command and specify the operation mode and the initial delay.

gcloud beta compute instance-groups managed update MIG_NAME \
  --standby-policy-mode=scale-out-pool \
  --standby-policy-initial-delay=DELAY \
  [--region=REGION | --zone=ZONE]

Replace the following:

  • MIG_NAME: the name of the MIG.
  • DELAY: the number of seconds that the MIG should wait before suspending or stopping a VM. The initial delay gives the initialization script the time to prepare your VM for quick scale out.
  • REGION: for a regional MIG, the region where the MIG is located.
  • ZONE: for a zonal MIG, the zone where the MIG is located.

API

Use the instanceGroupManager.update method and specify the operation mode and initial delay in the request body. For regional MIGs, use the regionInstanceGroupManager.update method.

PUT https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME

{
// ...
"standbyPolicy": {
  "mode": "SCALE_OUT_POOL",
  "initialDelaySec": DELAY
}
// ...
}

Replace the following:

  • PROJECT_ID: the ID of your project.
  • MIG_NAME: the name of the MIG.
  • DELAY: the number of seconds that the MIG should wait before suspending or stopping a VM. The initial delay gives the initialization script the time to prepare your VM for quick scale out.
  • REGION: for a regional MIG, the region where the MIG is located.
  • ZONE: for a zonal MIG, the zone where the MIG is located.

Resize the standby pool in a MIG

This section describes how to resize pools of suspended and stopped VMs in a MIG.

Console

  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Under the Name column of the list, click the name of the instance group where you want to edit the standby pool sizes.

  3. Click Edit to modify this managed instance group.

  4. Click Show advanced configuration.

  5. In the Standby pool section, enter the new sizes in the Suspended VMs and Stopped VMs fields.

  6. Click Save.

gcloud

Use the instance-groups managed resize beta command with the --suspended-size and --stopped-size flags.

gcloud beta compute instance-groups managed resize MIG_NAME \
--suspended-size=SUSPENDED_SIZE \
--stopped-size=STOPPED_SIZE \
[--region=REGION | --zone=ZONE]

Replace the following:

  • MIG_NAME: the name of the MIG in which to suspend an instance
  • SUSPENDED_SIZE: the number of suspended VMs that the MIG should maintain at any given time
  • STOPPED_SIZE: the number of stopped VMs that the MIG should maintain at any given time
  • REGION: for a regional MIG, the region where the MIG is located
  • ZONE: for a zonal MIG, the zone where the MIG is located

API

Use the instanceGroupManager.update method and specify the sizes of pools of suspended and stopped VMs in the request body. For regional MIGs, use the regionInstanceGroupManager.update method.

PUT https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME

{
// ...
"targetSuspendedSize": SUSPENDED_SIZE,
"targetStoppedSize": STOPPED_SIZE
// ...
}

Replace the following:

  • PROJECT_ID: the project ID for the request
  • ZONE: for a zonal MIG, the zone where the MIG is located
    • For a regional MIG, replace zones/ZONE with regions/REGION and specify the region of the MIG
  • MIG_NAME: the name of the MIG in which to stop an instance
  • SUSPENDED_SIZE: the number of suspended VMs that the MIG should maintain at any given time
  • STOPPED_SIZE: the number of stopped VMs that the MIG should maintain at any given time

What's next