Compute volatility configuration (preemptible vs. standard)

  1. Home
  2. Compute volatility configuration (preemptible vs. standard)

Go back to GCP Tutorials

In this tutorial we will learn and understand about Compute volatility configuration (preemptible vs. standard).

Creating and starting a preemptible VM instance

A preemptible instance is an instance you can create and run at a much lower price than normal instances. However, Compute Engine might stop (preempt) these instances if it requires access to those resources for other tasks. Preemptible instances are recommended only for fault-tolerant applications that can withstand instance preemptions.

Creating a preemptible instance

Create a preemptible instance through the Google Cloud Console, the gcloud tool, or the API.

Creating a preemptible instance is the same as creating a normal instance, but you enable the preemptible property.

  • Firstly, in the Cloud Console, go to the VM instances page.
  • Secondly, click Create instance.
  • Next, on the Create a new instance page, fill in the properties for your instance.
  • Then, click Management, security, disks, networking, sole tenancy.
  • After that, under Availability policy, set the Preemptibility option to On. This setting disables automatic restart for the instance, and sets the host maintenance action to Terminate.
  • Lastly, click Create to create the instance.

Preemptible CPU quotas

Preemptible instances require available CPU quotas like regular instances. To avoid preemptible instances consuming the CPU quotas for your regular instances, you can request a special “Preemptible CPU” quota. After Compute Engine grants you preemptible CPU quota in that region, all preemptible instances will count against that quota. All regular instances will continue to count against the regular CPU quota.

Checking if an instance is preemptible

You can check if an instance is configured to be preemptible using the Cloud Console, the gcloud tool, or the API. Check if an instance is preemptible by viewing the instance properties.

  • Firstly, Go to the VM instances page.
  • Secondly, select your project and click Continue.
    Thirdly, click the name of the instance that you want to check. This opens the instance details page.
    Lastly, the preemptible status is specified in the Availability policies section of the instance details.

Alternatively, you can determine if an instance is preemptible from inside the instance itself. Simply check the metadata server for the scheduling/preemptible value in your instance’s default instance metadata.

Detecting if an instance was preempted

Determine if an instance was preempted with the Google Cloud Console, the gcloud tool, or the API. You can check if an instance was preempted by checking the system activity logs.

  • Firstly, go to the Logs page.
  • Secondly, select your project and click Continue.
  • Thirdly, add compute.instances.preempted to the filter by label or text search field.
  • Optionally, you can also enter an instance name if you want to see preemption operations for a specific instance.
  • After that, press enter to apply the specified filters. The Cloud Console updates the list of logs to show only the operations where an instance was preempted.
  • Lastly, select an operation in the list to see details about the instance that was preempted.

Alternatively, you can determine if an instance was preempted from inside the instance itself. This is useful if you want to handle a shutdown due to a Compute Engine preeemption differently from a normal shutdown in a shutdown script. To do this, simply check the metadata server for the preempted value in your instance’s default instance metadata.

Preemptible VM instances

A preemptible VM is an instance that you can create and run at a much lower price than normal instances. However, Compute Engine might stop (preempt) these instances if it requires access to those resources for other tasks. Preemptible instances are excess Compute Engine capacity, so their availability varies with usage.

Preemptible instance limitations

  • Firstly, compute Engine might stop preemptible instances at any time due to system events. The probability that Compute Engine will stop a preemptible instance for a system event is generally low, but might vary from day to day and from zone to zone depending on current conditions.
  • Secondly, compute Engine always stops preemptible instances after they run for 24 hours. Certain actions reset this 24-hour counter.
  • Thirdly, preemptible instances are finite Compute Engine resources, so they might not always be available.
  • Next, preemptible instances can’t live migrate to a regular VM instance, or be set to automatically restart when there is a maintenance event.
gcp cloud architect practice tests

Preemption process

Compute Engine performs the following steps to preempt an instance:

  • Firstly, compute Engine sends a preemption notice to the instance in the form of an ACPI G2 Soft Off signal. You can use a shutdown script to handle the preemption notice and complete cleanup actions before the instance stops.
  • Secondly, if the instance does not stop after 30 seconds, Compute Engine sends an ACPI G3 Mechanical Off signal to the operating system.
  • Lastly, compute Engine transitions the instance to a TERMINATED state.

Preemption selection

Generally, Compute Engine avoids preempting instances. Compute Engine does not use an instance’s CPU usage or other behavior to determine whether or not to preempt it. However, larger instances are more likely to be preempted, since they take up more space. However, certain actions will reset the 24-hour counter for preemptible instances. Specifically, if you stop and start an instance, Compute Engine will reset the counter because the instance transitions into a TERMINATED state. However, other actions, where the instance remains in RUNNING state, do not reset the counter, for example, resetting an instance or running sudo reboot from within the VM.

Testing preemption settings

  • Firstly, you can run simulated maintenance events on your instances to force them to preempt. Use this feature to test how your apps handle preemptible instances.
  • Secondly, you can also simulate an instance preemption by stopping the instance, which can be used instead of simulating a maintenance event and which avoids quota limits.
Compute volatility configuration (preemptible vs. standard) GCP cloud architect  online course

Reference: Google Documentation, Doc 2

Go back to GCP Tutorials

Menu