> ## Documentation Index
> Fetch the complete documentation index at: https://help.nops.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Spot VMs for Non-Production Compute Engine Instances

> Run non-production Compute Engine VMs as Spot VMs, which list 60-91% below on-demand.

Spot VMs run the same machine types as on-demand VMs at a much lower price, but Compute Engine can stop them at any time when it needs the capacity back. nOps finds single on-demand VMs (not GKE nodes) whose instance or project names mark them as non-production, and estimates the saving from running them as Spot VMs.

| | |
| - | - |
| **Cloud** | Google Cloud |
| **Category** | Compute |
| **Service** | Compute Engine |
| **Action** | Modify |
| **Effort** | Medium |
| **Restart needed** | Yes |
| **Can be rolled back** | Yes |
| **Analysis window** | Last 7 days |
| **Source** | nOps |

## Why it matters

Development and test VMs rarely need guaranteed capacity. Running them as Spot cuts their compute cost by more than half without changing their size.

## How nOps finds it

nOps reads on-demand Compute Engine vCPU and memory billing for each VM over the last 7 complete days. A VM is flagged when it was billed on all 7 days and at least 90% of its cost carries a non-production word (such as dev, test, staging or sandbox) in its instance or project name, with no production word. VMs named like a database (for example mysql, postgres, mongo, redis, kafka or db), VMs with more than 10% GPU or sole-tenant cost, VMs already on Spot and VMs where committed-use discounts cover more than half the cost are left out. The saving assumes Spot costs 40% of the on-demand list price (the low end of Google's published 60-91% discount): it is the VM's current cost after credits minus 40% of its list cost, scaled to a month, and must be at least \$25 a month. Projects whose spend on the service is at least 90% paid by credits or promotions are left out.

## Before you start

The VM must tolerate being stopped at any time, and you need permission to stop and edit it.

## How to implement

1. Confirm the VM can be stopped without warning (no local state that would be lost, no long-running job that cannot restart).
2. Stop the VM, change its provisioning model to Spot with the termination action set to **Stop** (`gcloud compute instances set-scheduling VM_NAME --provisioning-model=SPOT --instance-termination-action=STOP --zone=ZONE`), then start it. You can also recreate the VM as a Spot VM.
3. For a managed instance group, set the provisioning model to Spot in a new instance template and roll it out.
4. Update Terraform so the next deployment does not change it back.

## Risks and considerations

* Compute Engine can stop a Spot VM at any time with about 30 seconds' notice, and may not have Spot capacity to restart it right away.
* This and an off-hours schedule are alternatives for the same VM. Apply one or the other, not both.
* To roll back, stop the VM and set its provisioning model back to standard.

## FAQs

> [accordion] Why are VMs named like databases left out?
>
> A database that is stopped without warning can lose writes or need recovery, so nOps does not recommend Spot for VMs whose names suggest one.

## Related

* [Schedule Non-Production Compute Engine Instances](https://help.nops.io/inform/supported-recommendations/schedule-non-production-compute-engine-instances)
* [Use Spot Node Pools for Non-Production GKE Clusters](https://help.nops.io/inform/supported-recommendations/use-spot-node-pools-for-non-production-gke-clusters)
* [Move N1 Instances to E2 Machine Types](https://help.nops.io/inform/supported-recommendations/move-n1-instances-to-e2-machine-types)
* [Supported recommendations](https://help.nops.io/inform/supported-recommendations.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.