Google has a massive infrastructure distributed throughout the globe and a dynamic mix of workloads, which implies that some of its infrastructure capacity may remain idle. Spot VMs are Compute Engine VMs that utilize this idle capacity whenever it is accessible. Spot VMs are extremely cost-effective compute instances appropriate for batch tasks and fault-tolerant workloads.
● Same machine types as standard VMs
● Offered at 60-91% discount
● No performance differences compared to standard VMs (refer to Performance comparison (on-demand vs Spot) section of this article).
● Useful for stateless, fault tolerant or batch workloads
● Spot VMs have no expiration time. Only terminated when Compute Engine needs resources for standard VMs
● Spot VMs are idle capacity, therefore they might not always be available.
● Not covered by any other SLA and are not included in the Compute Engine Service Level Agreement (SLA).
● Cannot be used with Google Cloud Free Tier credits for Spot VMs.
Customers who run workloads at a drastically reduced rate can choose to do so profitably thanks to GCP Spot pricing. These prices change over time, up to once every 30 days. Spot VMs provide at least a 60% discount and up to a 91% discount on the price of standard VMs with the same machine types.
Below are the screenshots of the pricing comparison between Standard VM and Spot VM using VM of type “n1-standard-4” with 4 vCPUs and 15GB of RAM running for 300 hours a month.
Note: As mentioned above, Spot pricing can change over time up to once every 30 days.
The Preemptible VM can be terminated on or before 24 hours after it has been created. The Spot VM has no such restriction. However, both VMs can be reclaimed after a 30-second notification. Preemptible and Spot VMs use the same pricing model as mentioned above.
The actions taken by Compute Engine to preempt Spot VMs are as follows:
1. The VM receives a preemption notification from Compute Engine in the form of an ACPI G2 Soft Off signal. Before the VM shuts down, you can handle the preemption notice and perform cleanup tasks using a shutdown script.
2. After 30 seconds, if the VM is still running, Compute Engine notifies the operating system with an ACPI G3 Mechanical Off signal.
3. Depending on the termination action you set for each VM, the final state of Spot VMs varies: ○ The VM is stopped by the Compute Engine and moves into the TERMINATED state if the termination action is set to STOP or not specified.
○ The virtual machine is deleted by Compute Engine if the termination action is set to DELETE.
Spot VMs can be used in a managed instance group specifying the options for creating Spot VMs in an instance template before you create or update the group.
Managed instance groups will create or add new spot VMs when additional compute engine resources are available. This means that managed instance groups do not guarantee Spot capacity.
1. Specify the option for creating Spot VMs in an instance template.
gcloud beta compute instance-templates create spot-vm-instance-template --project=project_id --machine-type=e2-standard --provisioning-model=SPOT
2. Create instance group.
gcloud compute instance-groups managed create spot-vms-mig --base-instance-name=spot-vms-mig --size=2 --template=spot-vm-instance-template --region=us-central1
3. If spot instances are preempted, the MIG will continue to attempt to create them.
Spot VMs can be used in GKE clusters and node pools to run stateless, batch or fault-tolerant workloads that can tolerate disruptions caused by the ephemeral nature of Spot VMs.
When a GKE cluster or node pool with Spot VMs are created, GKE creates underlying compute engine Spot VMs that behave like a managed instance group. Spot VMs using nodes operate similarly to regular GKE nodes, however there is no availability guarantee.
1. Use the following commands to create a GKE cluster with 2 node pools: one with Spot VMs and the other with Standard VMs.
gcloud beta container clusters create "spot-cluster" --project project_id --zone "us-central1-c" --machine-type "n1-standard-1" gcloud beta container node-pools create "spot-vm-pool" --project project_id --cluster
2. GKE automatically adds the “cloud.google.com/gke-spot=true” label to nodes that use Spot VMs. Specific pods can be scheduled on nodes that use Spot VMs using the nodeselector field in pod spec. Add the appropriate nodeSelector field for both the pod definition files.
apiVersion: v1 kind: Pod metadata: name: "spot-vm-pod" spec: containers: - name: "nginx" image: "nginx:latest" nodeSelector: cloud.google.com/gke-spot: "true"
apiVersion: v1 kind: Pod metadata: name: "standard-vm-pod" spec: containers: - name: "nginx" image: "nginx:latest" nodeSelector: cloud.google.com/gke-nodepool: standard-vm-pool
There is no performance difference between on-demand VMs and Spot VMs. In order to test this, we created two Compute Engine VMs: a Spot VM and a Standard VM, both with the machine type n1-standard2. On both of these VMs, we installed Apache Web Server. Next, we used a tool called Siege, which is an open-source tool for HTTP load testing and benchmarking, to create some load on these VMs. With 25 concurrent requests, we generated load on the VMs for 30 minutes. The performance of the 2 VMs was then compared using a few sample metrics on monitoring dashboards. These are the outcomes:
From the above images, it is clear that there are no differences between the Spot VM and Standard VM in terms of CPU, network and disk performance.
Spot VMs come with various restrictions. They cannot be used if you are utilizing Google Cloud’s free tier credits or for live migration and are not covered by the Compute Engine Service Level Agreement (SLA). As said previously, the resources are finitely available and can be redistributed at any time. This Compute Engine VM is just one of the many advanced technologies offered in the Cloud and you don’t have to begin your Cloud journey alone. Contact the Google Cloud experts at 66degrees. With over 50 Google Cloud Specializations and Expertises and 250+ Google Cloud Certifications, 66degrees will meet you where you are and get you to where you want to be.