Auto VM Selection

When you pin a job to a specific machine type using the workerMachineType pipeline option, you risk experiencing delays or job failures due to resource stockouts. Auto VM Selection addresses this problem by automatically choosing workers from a pool of compatible and available machine types using Compute Engine instance flexibility. This helps to ensure that your Dataflow pipelines acquire capacity reliably, helping you maintain consistent performance and avoid interruptions.

Unsupported configurations

Auto VM Selection is turned off if your pipeline is configured with any of the following:

  • Dataflow Prime is enabled.
  • The min_cpu_platform pipeline option is set.
  • Hyperdisk Balanced disks or custom provisioned performance (IOPS and throughput) are used. Jobs started with these configurations will fail.
  • Confidential VM is enabled.
  • Accelerators (GPUs or TPUs) are required.
  • Jobs that don't use Dataflow Shuffle or Streaming Engine.

Enable Auto VM Selection

Auto VM Selection is enabled automatically in any of the following scenarios:

  • If you set min_ram or cpu_count resource hints for pipeline steps that don't require accelerators (GPUs or TPUs). For information about how to use resource hints with template-based jobs, see Pipeline resource hints.

Auto VM Selection behavior

Configure min_ram and cpu_count resource hints either in isolation or in combination. For example:

  1. A job with only cpu_count=2 may provision instances with n4-standard-2 (2 vCPUs, 8 GB RAM), c4-standard-2 (2 vCPUs, 7 GB RAM) and other machine types.
  2. A job with both cpu_count=4 and min_ram=16GB may provision instances with n4-standard-4 (4 vCPUs, 16 GB RAM), c4-highmem-4 (4 vCPUs, 31 GB RAM) and other machine types.

Auto VM Selection optimizes VM selection for resource obtainability. This means that you might experience reduced performance while using Auto VM Selection to improve the obtainability of some of your highly-tuned jobs. We recommend that you test Auto VM Selection on a subset of your existing jobs before gradually deploying them more broadly. For more information about obtainability, see Improve resource obtainability for jobs in the Batch documentation.

Dataflow attempts to use 4th generation machine families first (for example, N4 or C4) to offer better efficiency. If 4th generation machines are unavailable in your region, lack sufficient quota, or are incompatible with your configurations, Dataflow automatically falls back to widely available 2nd generation machine families (for example, N2 or E2) to ensure your job can start without capacity delays.

By default, Dataflow chooses one machine generation for the entire worker pool when the job starts, and the worker pool can't switch generations later. To let a batch job use multiple generations in the same worker pool, see Cross-generation Auto VM Selection.

If you specify a disk type such as pd-ssd or pd-standard when enabling Auto VM Selection using resource hints (right fitting), Dataflow only provisions compatible 2nd generation machine families. To ensure maximum compatibility and allow the use of newer machine generations, don't assign a disk type.

View selected machine types

Because Auto VM Selection chooses machine types when it creates worker VMs, the workers of a job can use different machine types. To see which machine types your jobs use, query worker VM metrics with the Cloud Monitoring API. Cloud Monitoring records the machine type of each worker VM in the machine_type system metadata label. Dataflow adds a dataflow_job_id label to each worker VM.

To run the following command, you need the Google Cloud CLI and curl. To get the permission that you need to query metrics, ask your administrator to grant you the Monitoring Viewer (roles/monitoring.viewer) role on the project.

The following command lists the machine types that the workers of a Dataflow job used. The command calls the projects.timeSeries.list method and formats the response as a table by using only built-in shell commands:

PROJECT_ID="PROJECT_ID"
JOB_ID="JOB_ID"
START_TIME="${JOB_ID%%_*}T00:00:00Z"
END_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"

TOKEN="$(gcloud auth print-access-token)" &&
RESPONSE="$(curl -fsS --get \
    "https://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/timeSeries" \
    -H "Authorization: Bearer ${TOKEN}" \
    --data-urlencode "filter=metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\" metadata.user_labels.\"dataflow_job_id\"=\"${JOB_ID}\"" \
    --data-urlencode "interval.startTime=${START_TIME}" \
    --data-urlencode "interval.endTime=${END_TIME}" \
    --data-urlencode "aggregation.alignmentPeriod=60s" \
    --data-urlencode "aggregation.perSeriesAligner=ALIGN_MEAN" \
    --data-urlencode "aggregation.crossSeriesReducer=REDUCE_COUNT" \
    --data-urlencode 'aggregation.groupByFields=metadata.system_labels."machine_type"' \
    --data-urlencode "view=FULL" \
    --data-urlencode "prettyPrint=true" \
    --data-urlencode "fields=timeSeries.metadata,timeSeries.points.value,nextPageToken")" &&
printf '%s\n' "$RESPONSE" | {
  printf '%-22s%s\n' MACHINE_TYPE PEAK_INSTANCES
  type= peak=0
  while IFS= read -r line; do
    case $line in
      *'"int64Value": "'*)
        v=${line#*'"int64Value": "'}; v=${v%%'"'*}
        [ "$v" -gt "$peak" ] && peak=$v ;;
      *'"machine_type": "'*)
        type=${line#*'"machine_type": "'}; type=${type%%'"'*} ;;
      '    }' | '    },')
        [ -n "$type" ] && printf '%-22s%s\n' "$type" "$peak"
        type= peak=0 ;;
      *'"nextPageToken":'*)
        printf 'Warning: output is incomplete; use a shorter time range.\n' >&2 ;;
    esac
  done
}

Replace the following:

  • PROJECT_ID: the ID of the project that runs the job
  • JOB_ID: the ID of the Dataflow job

The output has a row for each machine type that the job's workers used. The PEAK_INSTANCES column shows the maximum number of workers of that machine type that ran at the same time. The output is similar to the following:

MACHINE_TYPE          PEAK_INSTANCES
c4-standard-2         1
n4-standard-2         4

The command counts the job's VMs of each machine type in each minute, based on the compute.googleapis.com/instance/cpu/utilization metric, which every running VM reports. Metric data can take up to 4 minutes to appear in Monitoring, and the command might not count VMs that run for less than 1 minute.

A job ID starts with the job's creation date in Pacific Time. By default, START_TIME is midnight UTC on that date, which is always before the job started, and END_TIME is the current time. To query a different time range, set START_TIME and END_TIME to UTC timestamps in RFC 3339 format. For example, START_TIME="2026-11-04T18:00:00Z" and END_TIME="2026-11-05T18:00:00Z".

If the command prints a warning that the output is incomplete, run the command for shorter time ranges. This warning can appear for jobs that run for several weeks.

Monitoring stores data that's older than 6 weeks at 10-minute intervals. To query that data, change aggregation.alignmentPeriod to 600s.

Limitations

When using Auto VM Selection, Portable Runner container image updates are disabled for streaming jobs that use the Portable Runner.

Compute Engine reservations

If you use Compute Engine reservations with Auto VM Selection, note the following:

Cross-generation Auto VM Selection

Cross-generation Auto VM Selection lets batch jobs use capacity from 4th generation and 2nd generation Compute Engine machines in the same worker pool. Dataflow prioritizes 4th generation machines and uses 2nd generation machines when 4th generation machines are unavailable (or have insufficient quota).

Requirements and limitations

Cross-generation Auto VM Selection has the following requirements and limitations:

  • Batch jobs only: Streaming jobs aren't supported. If you enable cross-generation Auto VM Selection for a streaming job, the job will be rejected by Dataflow.
  • Auto VM Selection required: The job must use Auto VM Selection. If Auto VM Selection is turned off for the job, for example because you set a worker machine type or use one of the unsupported configurations, the job can't use cross-generation Auto VM Selection.
  • No worker disk type: Don't set the workerDiskType (Java), worker_disk_type (Python), or disk_type (Go) pipeline option. If you set the pd-standard or pd-ssd disk type, Dataflow uses only 2nd generation machines. If you set the hyperdisk-balanced disk type, the job fails shortly after launch because Hyperdisk Balanced disks aren't compatible with Auto VM Selection.
  • 4th generation availability: Your job can only use 4th generation machines if they're offered in the job's region, they aren't stocked out, and your project has sufficient quota for them.
  • Autoscaling with heterogeneous workers: When a job uses both 4th generation and 2nd generation machines, worker performance can vary significantly, which could affect autoscaling responsiveness. We recommend that you verify the performance of your pipeline with Cross-generation Auto VM Selection before you use it in production.

Pricing

When a job runs 4th generation and 2nd generation workers at the same time, Dataflow bills the boot disk of each worker according to the disk type that the worker uses:

  • 4th generation workers are billed for Hyperdisk Balanced disks.
  • 2nd generation workers are billed for Standard Persistent Disk disks.

As a result, the billing data for a single job can include both Persistent Disk and Hyperdisk Balanced SKUs. The proportion of each disk type depends on how many workers of each generation the job uses and how long they run. For more information, see Dataflow pricing.

Enable cross-generation Auto VM Selection

To enable cross-generation Auto VM Selection, do the following when you launch a new batch job:

  1. Make sure that the job uses Auto VM Selection. For example, set min_ram or cpu_count resource hints, and don't set a worker machine type or a worker disk type.
  2. Set the enable_cross_gen_auto_vm service option.

    Java

    --dataflowServiceOptions=enable_cross_gen_auto_vm
    

    Python

    --dataflow_service_options=enable_cross_gen_auto_vm
    

    Go

    --dataflow_service_options=enable_cross_gen_auto_vm
    

    gcloud

    When you run a template using the gcloud dataflow jobs run command or a Flex Template using the gcloud dataflow flex-template run command, include the --additional-experiments flag:

    --additional-experiments=enable_cross_gen_auto_vm
    

When Dataflow must use 2nd generation machines, the job logs might show resource availability errors or quota errors for 4th generation machine types. These errors are expected and don't indicate a problem with the job. To confirm that the job is still getting workers, check the Autoscaling section of the Job metrics tab. If the number of workers keeps up with the target number of workers, you can ignore these errors.

Disable cross-generation Auto VM Selection

Dataflow might enable cross-generation Auto VM Selection for some batch jobs that use Auto VM Selection, even if you don't set the enable_cross_gen_auto_vm service option. To prevent a batch job from using cross-generation Auto VM Selection, set the enable_cross_gen_auto_vm service option to false when you launch the job:

Java

--dataflowServiceOptions=enable_cross_gen_auto_vm=false

Python

--dataflow_service_options=enable_cross_gen_auto_vm=false

Go

--dataflow_service_options=enable_cross_gen_auto_vm=false

gcloud

When you run a template using the gcloud dataflow jobs run command or a Flex Template using the gcloud dataflow flex-template run command, include the --additional-experiments flag:

--additional-experiments=enable_cross_gen_auto_vm=false

When cross-generation Auto VM Selection is disabled, Dataflow chooses one machine generation for the entire worker pool when the job starts, as described in Auto VM Selection behavior.

Known issues

When using Auto VM Selection, be aware of the following known issues:

Unexpected parallelism

If you observe low CPU utilization or unexpected parallelism on worker VMs when using Auto VM Selection with right fitting, check the following settings.

Horizontal Autoscaling

If you disable Horizontal Autoscaling, your job might run with lower parallelism than expected. To avoid this issue, keep Horizontal Autoscaling enabled. For more information, see Right fitting support and limitations.

Worker harness threads

By default, Dataflow sets the number of threads per worker based on the vCPU count of the selected machine type. If you still observe low CPU utilization or unexpected parallelism, you can override the default by setting the numberOfWorkerHarnessThreads or number_of_worker_harness_threads pipeline option. This option applies globally to all worker pools in the pipeline.