Applying instance sizing recommendations for MIGs

Compute Engine provides machine type recommendations to help you use the resources in your managed instance groups (MIGs) more efficiently. Stackdriver Monitoring generates these recommendations based on system metrics that it gathers or metrics gathered by Stackdriver. Use these recommendations to determine whether you should resize the machine type of your instances to add or remove vCPU and memory resources.

To learn more about the different sizing options available to VM instances, read the machine types documentation.

Sizing recommendations are also known as rightsizing recommendations.

Before you begin


Recommendations are available for managed instance groups that are in a single zone and aren't autoscaled or load balanced.


During beta, sizing recommendations are available free of charge. However, we might charge for this feature in future releases.

Use cases

You can take advantage of sizing recommendations if you have the following workload conditions:

  • Workloads with periodic increases and decreases in traffic, such as workloads susceptible to seasonal traffic.
  • Workloads that are underutilized in CPU and RAM because they are bounded by other limitations, such as read/write throughput.
  • Workloads that run software that requires individual software licenses and that can't add more instances; in this case, you might rely on sizing recommendations to scale your machine types while keeping the number of VM instances constant.
  • Workloads that are unable to dynamically adapt to a changing number of instances, such as workloads that aren't a good fit for autoscaling.

You might not want to use sizing recommendations if you have varied workloads:

  • Your workloads have very brief CPU spikes. Because sizing recommendations are based on average CPU utilization over 60-second intervals, recommendations might not be generated quickly enough to capture shorter spikes. Apps with short usage spikes might need to run on a larger machine type than the recommended one, or you can enable autoscaling to accommodate these spikes.
  • You have managed instance groups where each instance handles a drastically different workload. The sizing recommendations for such a situation would oversize most VM instances in the group.

How sizing recommendations work

Compute Engine monitors the CPU and memory utilization of running virtual machines and makes recommendations using the last 8 days of data. To recommend the best single machine type for all instances in a managed instance group, Compute Engine generates a standard sizing recommendation for individual instances and, after adjusting for outliers, chooses a machine type that does not undersize any single VM instance. Any instances that aren't running, such as stopped or restarting VM instances, aren't included in the calculation.

Compute Engine might make recommendations similar to the following:

  • If your instance group has had low CPU utilization most of the time, Compute Engine recommends a machine type with fewer virtual CPUs.
  • If your instance group has had high CPU utilization most of the time, Compute Engine recommends a machine type with more virtual CPUs.
  • If your instance group hasn't used a large fraction of its memory, Compute Engine recommends a machine type with less memory.
  • If your instance group has actively been using a large fraction of its memory most of the time. Compute Engine recommends a machine type with more memory.

Compute Engine might make recommendations to use either a standard or custom machine type. Note that there are some limitations in the amount of memory and vCPU available to a machine. In particular, increasing one resource might require increasing the other at the same time to follow the specifications of a valid machine type. Also, Compute Engine only recommends machine types that are available in the zone where the instance is running.

For more information, see Custom machine type specifications.

If the workload for the managed instance group is very different across individual instances, some instances might be oversized so that the fully utilized instances have enough resources according to the recommendation. For example, Compute Engine might make the following recommendation to support the workload of instance 4 even though instances 1, 2, 3, and 5 might be oversized and underutilized:

Recommendations made for a managed instance group
Example of oversizing due to different workloads across managed instances

For this reason, recommendations for a managed instance group work best when the instances have a reasonably distributed workload.

For cost difference estimations, the cost of an instance group is based on the previous week's usage (before sustained use discount) and is extrapolated to 30 days. This is then compared to the recommended machine type monthly cost (before sustained use discount). For accurate pricing and details, read the pricing documentation.

Viewing sizing recommendations

Compute Engine makes recommendations available through the Google Cloud Platform Console. Recommendations are also available through the beta Recommender using the gcloud tool or the API.


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

    Go to the Instance groups page

  2. Select your project and click Continue.
  3. Look at the Recommendation column to review recommendations for individual managed instance groups. You can also sort the column by amount of estimated savings. If there are no recommendations next to the instance groups, Compute Engine does not have any recommendations to make.

    Recommendations column.

  4. If your instance group has two instance templates, Compute Engine provides recommendations for each instance template. Click a recommendation to view recommendations for the respective instance template.

    Recommendations for multiple templates


Use the gcloud beta recommender recommendations list command and specify the VM managed instance group rightsizing recommender.

gcloud beta recommender recommendations list \
      --recommender=google.compute.instanceGroupManager.MachineTypeRecommender \
      --project [PROJECT_ID] \
      --location [ZONE] \

For example:

gcloud beta recommender recommendations list \
    --recommender=google.compute.instanceGroupManager.MachineTypeRecommender \
    --project my-project \
    --location us-central1-a \

The response includes the following fields for each recommendation:

  - operations:
    - action: test
      path: /properties/machineType
      resource: //
      value: n1-standard-4
    - action: copy
      path: /
      resource: //$new-it-name
      sourcePath: /
      sourceResource: //
    - action: replace
      path: /name
      resource: //$new-it-name
      value: $new-it-name
    - action: replace
      path: /properties/machineType
      resource: //$new-it-name
      value: custom-2-5632
  - operations:
    - action: replace
      path: /versions/*/name
          matchesPattern: .*global/instanceTemplates/my-old-template
      resource: //
      value: global/instanceTemplates/$new-it-name
description: Save cost by changing machine type from n1-standard-4 to custom-2-5120.
name: projects/823742397239/locations/us-central1-a/recommenders/google.compute.instanceGroupManager.MachineTypeRecommender/recommendations/c50a1c41-7e65-417d-a32e-45248a2cb318

For more information, see the Recommender docs.


Use the beta Recommender API with the VM instance sizing for managed instance groups recommender ID.

If you aren't already familiar with the authentication prerequisites for calling GCP APIs, see the Authentication overview.

The following example bash script uses the end user authentication flow with an OAuth client credential. The script uses the Google oauth2l command-line tool to get an OAuth 2.0 access token and then makes a curl request using the token.

OAUTH_JSON=~/client_secrets.json  # credentials for service account
OAUTH_HEADER="$(oauth2l header --json $OAUTH_JSON cloud-platform)"

curl -H "$OAUTH_HEADER"$PROJECT_ID/locations/$LOCATION/recommenders/$RECOMMENDER_ID/recommendations

The response includes the following fields for each recommendation:

  • name The name of the recommendation
  • description A human-readable explanation of the recommendation.
  • operationGroups Groups of operations that you can perform in serial order to apply the recommendation.

For more information, see the Recommender docs.

When you create a new managed instance group, recommendations for the new group appear 24 hours after the group has been created.

Afterward, recommendations are refreshed at regular intervals throughout the day.

Applying recommendations to instance groups

If you want to apply the recommendations made by Compute Engine, you can resize the managed instances directly from the console. Alternatively, you can manually step through the resizing operations yourself. The Recommender API returns a series of resizing operations; see Operation groups for more information.

When you apply a recommendation to a managed instance group, you perform the following operations:

  1. Clones the instance templates being used by the managed instance group.
  2. Modifies the cloned instance templates based on the recommendations and any changes you want to make.
  3. Uses the managed instance group updater to apply the new template. If the instance group has two instance templates:

    1. You can only apply recommendations for one instance template at a time.
    2. A managed instance group can maintain at most two instance templates at a time, so it is not possible to run a recommendation while still maintaining two other instance templates. However, you could run a recommendation if your instance group only has one instance template.

To resize managed instances directly from the console:

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

    Go to the Instance groups page

    Click the recommendation text for the instance group that you want to update.

    Selecting a recommendation column.

  2. A pop-up appears with more detail and a choice to Cancel, Dismiss Recommendation, or Continue. To review and apply the recommendation, click Continue.

  3. On the next screen, the recommendation is explained in detail. If you continue with the recommendation, Compute Engine creates an instance template and updates all instances in the instance group to use the new template.

  4. (Advanced) To customize how the new template is rolled out to your instances, click Customize deployment. A screen appears.

    1. Under Template, you can choose whether to apply the new template to 100% of the instances in the instance group or to only a subset of the instances.
    2. Under Update mode, you can choose whether you want Compute Engine to actively delete and create instances using the new instance template (Proactive) or only apply the update if the instance is created by other means, such as a resize or when a new instance is added to the group (Opportunistic).
    3. Under Maximum surge, choose how many temporary extra instances to create above the managed instance group's target size. The more instances you allow, the faster your update is, at the cost of additional instances. The default is 1 additional instance.
    4. Under Maximum unavailable, you can choose how many instances can be offline at a time during this update. This number also includes any instances that are unavailable for other reasons. For example, if the instance group is in the process of being resized up, instances in the middle of being created might be unavailable; these instances would count toward this number. The default is 1 instance that can be unavailable at a time.
    5. Under Minimum wait time, you can choose how many seconds to wait before marking a new instance as updated. The time starts after a successful health check. Use this feature to control the rate at which the instance template is applied.
  5. To apply the changes, click the Save button.

  6. When you are ready to deploy the changes, click Deploy.

Dismissing recommendations

When you have finished using a recommendation, you can dismiss it from the console. Within the console, dismissing removes a recommendation from the total savings estimate and also minimizes the appearance of the recommendation by turning it grey.

Dismissing a recommendation through the console doesn't affect the list of recommendations that is returned by the Recommender API. To manage the state of recommendations returned by the Recommender API, see Using the API.

To dismiss a single recommendation from the console:

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

    Go to the Instance groups page

    Click the recommendation text you want to dismiss. A pop-up appears with more details and a Dismiss recommendation button.
  2. Click Dismiss recommendation.

To dismiss all recommendations, click the Dismiss all button on the Instance groups page.

Dismiss recommendations.

To restore a recommendation in the console:

  1. On the Instance groups page, click the grey recommendation text you want to restore.

    Dismissed recommendation.

  2. A pop-up appears with more detail and a Restore recommendation button.

  3. Click Restore recommendation.

Using the monitoring agent for more precise recommendations

Stackdriver offers a monitoring agent that collects additional disk, CPU, network, and process metrics from your VM instances. To collect this data, install the monitoring agent on your VM instances, so it can access system resources and app services.

If the Monitoring agent is installed and running on a VM instance, the CPU and memory metrics collected by the agent are automatically used to compute sizing recommendations. The agent metrics provided by the Monitoring agent give better insights into resource utilization of the instance than the default Compute Engine metrics. This lets the recommendation engine estimate resource requirements better and make more precise recommendations.

To install the agent, see Installing the Stackdriver Monitoring agent.


During beta, you can send feedback to the Sizing recommendations discussion group.

What's next

Var denne side nyttig? Giv os en anmeldelse af den:

Send feedback om...

Compute Engine Documentation