Creating an Instance with a Custom Machine Type

Compute Engine offers predefined machine types that you can use when you create an instance. A predefined machine type has a preset number of vCPUs and amount of memory, and are charged at a set price, described in the pricing page.

If predefined machine types do not meet your needs, you can create an instance with custom virtualized hardware settings. Specifically, you can create an instance with a custom number of vCPUs and amount of memory, effectively using a custom machine type.

Custom machine types are ideal for the following scenarios:

  • Workloads that are not a good fit for the predefined machine types that are available to you.
  • Workloads that require more processing power or more memory, but don't need all of the upgrades that are provided by the next machine type level.

Before you begin

Specifications

  • The maximum number of vCPUs allowed for a custom machine type is determined by the zone where the instance will be hosted:

    • Some zones, but not all zones, that support the Skylake CPU platform can support custom machine types with up to 96 vCPUs.
    • Some zones, but not all zones, that support the Broadwell, Haswell, or Ivy Bridge CPU platforms can support custom machine types with up to 64 vCPUs.
    • All zones that support the Sandy Bridge CPU platform can support custom machine types with up to 16 vCPUs.

    To see which platforms are available in each zone, read the regions & zones table.

  • Above 1, the instance vCPU count must be even, such as 2, 4, 6, 8, 10, and so on.

  • The memory per vCPU of a custom machine type must be between 0.9 GB and 6.5 GB per vCPU, inclusive.

  • The total memory for a custom machine type must be a multiple of 256 MB. For example, 6.9 GB is not acceptable, but 6.75 GB and 7 GB are acceptable.

  • Instances with custom machine types have the same persistent disk capacity limitations as instances with predefined machine types. However, custom machine types are still limited to 16 individual persistent disk volumes.

For examples of valid and invalid machine types, read the Create an instance section.

Pricing

Google charges for custom machine types based on the number of vCPUs and memory hours that the instance uses. This is different than how predefined machine types are charged, so we recommend you review the pricing page before you create a custom machine type.

Instances running a custom machine type are subject to the same 10-minute minimum charge, but sustained use discounts for custom machine types are calculated differently. For more information, read sustained use discounts for custom machine types.

Creating an instance with a custom machine type

Before you create an instance, make sure you have read and understood the Specifications for creating a custom machine type. In summary:

  • Only machine types with 1 vCPU or an even number of vCPUs can be created.
  • Memory must be between 0.9 GB per vCPU, up to 6.5 GB per vCPU.
  • The total memory of the instance must be a multiple of 256 MB.
  • The maximum number of vCPUs allowed depends on the zone. Zones supporting Haswell and Broadwell processors can support machine types up to 64 vCPUs, while Ivy Bridge processors can support machine types with up to 32. Zones with Sandy Bridge processors can support machine types up to 16 vCPUs.

Examples of invalid machine types

  • 1 vCPU, 0.6 GB of total memory — Invalid because the total memory is less than the minimum 0.9 GB.
  • 1 vCPU, 0.9 GB of total memory — Invalid because the total memory must be a multiple of 256 MB. For 1 vCPU, use a minimum of 1024 MB memory.

Examples of valid machine types

  • 32 vCPUs, 29 GB of total memory — Valid because the total number of vCPUs is even and the total memory is a multiple of 256 MB. The amount of memory per vCPU is 0.9 GB, which satisfies the minimum requirement.
  • 1 vCPU, 1 GB of total memory — Valid because it has one vCPU, which is the minimum value, and the total memory is a multiple of 256 MB. The amount of memory per vCPU is also between the acceptable range of 0.9 GB to 6.5 GB per vCPU.

Expressing memory in GB or MB

Machine type memory is calculated in gigabytes (GB), where 1GB is 230 bytes. This unit of measurement is also known as a gibibyte (GiB) . When converting memory from GB to MB, 1 GB = 1024 MB.

In the API, you must always provide memory in MB units. If you use the gcloud command line tool, it is possible to provide the total memory for an instance in GB or MB units. However, the gcloud tool expects the memory value to be an integer, so you cannot provide a float value. For example, to express 5.75 GB, convert 5.75 GB into MB instead. In this case, 5.75 GB would be 5888 MB.

Creating the instance

Console

  1. Go to the Create instance page

    Go to the Create instance page

  2. Under Machine type, click Customize.
  3. Drag the sliders to choose the number of vCPUs and the amount of memory for the instance. The console displays an estimated cost for the instance as you change the number of vCPUs and memory.
  4. Save your changes and continue with the rest of the creation process.

gcloud

Using the gcloud command-line tool, use the instances create subcommand, followed by the --custom-cpu and --custom-memory flags. Specify the total amount of memory in GB or in MB. The property must be an integer, so if you want to specify increments of 0.25 GB for memory, convert that value to MB instead.

For example, the following command would create an instance with 4 vCPUs and 5 GB of total memory:

gcloud compute instances create example-instance --custom-cpu 4 --custom-memory 5

To specify an incremental value, such as 5.25 GB of memory, convert the value to MB and supply the value followed by the MB suffix:

gcloud compute instances create example-instance --custom-cpu 4 --custom-memory 5376MB

API

In the API, create your instance creation request as you would normally, but when specifying a machineType value, use the following format. Replace NUMBER_OF_CPUS with the number of CPUs and AMOUNT_OF_MEMORY with the amount of memory you want. Provide memory in MB units:

zones/[ZONE]/machineTypes/custom-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY

For example, the following URL would create an instance with 4 vCPUs and 5 GB (5120 MB) of memory:

zones/us-central1-f/machineTypes/custom-4-5120

You can also create preemptible instances with a custom machine type, or create groups of instances with a custom machine type by specifying a custom machine type in the formats described above.

Adding extended memory to a machine type

By default, a custom machine can have up to 6.5 GB of memory per vCPU. However, this might not be enough memory for your workload. At an additional cost, you can get more memory per vCPU beyond the 6.5 GB limit. This is referred to as extended memory.

With extended memory, you can add additional memory to a machine type with no limitations per vCPU. Regardless of the CPU platform, you can add extended memory up to a total of 455 GB per VM. For instances using the Skylake CPU Platform in zones where 96 vCPU machine types are available, you can add extended memory up to a total of 624 GB per VM.

Determining if you need extended memory

Certain workloads need more than 6.5 GB memory per vCPU to deliver optimum results. Workloads that are based on in-memory analytics, high performance databases, including relational and NoSQL databases such as MS SQL Server, MongoDB and MemcacheD/Redis, fall in this category. vCPU-based licensing of operating systems and software stacks also make selecting an optimal VM memory configuration much harder with predefined machine types. By using extended memory, you can add as much memory as you need to reach the best price and performance for your VM instances.

Pricing

When using a custom machine type, any memory up to and including 6.5 GB of memory per vCPU is charged at the standard custom machine type pricing. For memory above the 6.5 GB per vCPU threshold, Compute Engine charges the for extended memory based on the Extended Memory Pricing. Note that the price for extended memory is different than the price for memory below the 6.5 GB per vCPU threshold.

Extended memory prices differ depending on the region. Instances running with extended memory are subject to the same 10-minute minimum charge as any other instance. Extended memory also qualifies for sustained use discounts. For more information, read about Sustained use discounts for custom machine types

For pricing information, see Extended Memory Pricing.

Limitations

  • You can only add extended memory to custom machine types. Predefined machine types are not supported.
  • There is no limit of memory per vCPU that you can add, but there is a maximum amount of memory you can add to each VM instance. Regardless of the CPU platform, you can add extended memory up to a total of 455 GB per VM. For instances using the Skylake CPU Platform in zones where 96 vCPU machine types are available, you can add extended memory up to a total of 624 GB per VM.
  • You must specify memory in 256 MB increments.
  • Extended memory does not qualify for Committed Use Discounts.

Adding extended memory during instance creation

To create a VM instance with extended memory, follow the instructions below.

Console

  1. Go to the Create an instance page in the Google Cloud Platform Console.

    Go to the Create an instance page

  2. Under Machine type, click Customize.
  3. Select the vCPUs you want for the VM instance.
  4. Select the amount of memory you want. To add extended memory, check the Extend memory option. The range of selectable memory will expand.
  5. Continue with the instance creation process.

gcloud

Using the gcloud tool, use the instances create subcommand, followed by the --custom-extensions flag to enable extended memory. Then, specify the total memory that you want with the --custom-memory parameter.

For example, the following command would create a 2 vCPU, 15 GB memory instance (including an extended memory of 2 GB):

gcloud compute instances create example-instance --custom-cpu 2 --custom-memory 15 --custom-extensions

API

In the API, construct your instance creation request as you would normally, but when specifying a machineType value, use the following format:

zones/[ZONE]/machineTypes/custom-[NUMBER_OF_CPUS]-[AMOUNT_OF_MEMORY]-ext

Replace:

  • [NUMBER_OF_CPUS] with the number of vCPUs
  • [AMOUNT_OF_MEMORY] with the amount of memory you want. Provide the amount of memory in MB units.

For example, the following specifies a machine type with 2 vCPUs and 15 GB of memory:

zones/[ZONE]/machineTypes/custom-2-15360-ext

Adding extended memory to an existing VM instance

To add more memory to an existing instance, you must first stop the instance. After the instance stops, follow the instructions below to add more memory to the VM.

Console

  1. Go to the VM instances page.

    Go to the VM instances page

  2. Choose the stopped instance you want to modify from the instance list.
  3. Click Edit at the top of the page.
  4. Under Machine type, click Customize.
  5. Select the amount of vCPU you want.
  6. Select the amount of memory you want. To add extended memory, check the Extend memory option. The range of selectable memory with expand.
  7. Save your changes.

gcloud

Using the gcloud command-line tool, use the instances set-machine-type subcommand, followed by the --custom-extensions flag paired with the existing --custom-memory parameter.

For example, to add 2GB more memory to an instance named example-instance, which currently has 2 vCPU, 13GB, in us-central1-b zone, use the following command:

gcloud compute instances set-machine-type example-instance \
   --zone us-central1-b --custom-cpu 2 \
   --custom-memory 15 --custom-extensions

API

In the API, make a POST request to the setMachineType method with the desired machine type in the request body. Use the following format when specifying a new machine type:

zones/[ZONE]/machineTypes/custom-[NUMBER_OF_CPUS]-[AMOUNT_OF_MEMORY]-ext

Replace:

  • [NUMBER_OF_CPUS] with the number of vCPUs.
  • [AMOUNT_OF_MEMORY] with the amount of memory you want. Provide the amount of memory in MB units.

For example, the following uses a machine type with 2 vCPUs and 15GB of memory:

zones/[ZONE]/machineTypes/custom-2-15360-ext

For example:

POST https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]/setMachineType

{
    machineType: "zones/us-central1-f/machineTypes/custom-2-15360-ext"
}

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Compute Engine Documentation