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, then 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 by selecting one of the following options:
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
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- 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
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
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.
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
In the Google Cloud console, go to the Instance groups page.
Under the Name column of the list, click the name of the instance group where you want to edit the standby policy.
Click Edit to modify this managed instance group.
Click Show advanced configuration.
In the Standby pool section, under Mode, select Scale-out.
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.
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://compute.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.ZONE
: for a zonal MIG, the zone where the MIG is located.- For a regional MIG, replace
zones/ZONE
withregions/REGION
and specify the region of the MIG.
- For a regional MIG, replace
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.
Resize the standby pool in a MIG
This section describes how to resize pools of suspended and stopped VMs in a MIG.
Console
In the Google Cloud console, go to the Instance groups page.
Under the Name column of the list, click the name of the instance group where you want to edit the standby pool sizes.
Click Edit to modify this managed instance group.
Click Show advanced configuration.
In the Standby pool section, enter the new sizes in the Suspended VMs and Stopped VMs fields.
Click Save.
gcloud
Use the
instance-groups managed update
beta command
with the --suspended-size
and --stopped-size
flags.
gcloud beta compute instance-groups managed update 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://compute.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
withregions/REGION
and specify the region of the MIG.
- For a regional MIG, replace
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
- Learn how to manually suspend or stop VMs in a MIG.
- Learn more about updates for suspended and stopped VMs in a MIG.