Maximizing Cost Efficiency with Preemptible VMs in GCP
Preemptible VM instances exist to provide a cost-effective solution for workloads that can tolerate interruptions. With discounts of up to 91% compared to standard VMs, they are ideal for batch processing, testing, and other non-critical tasks. However, their low cost comes with the caveat of potential preemption, which can disrupt your operations if not managed properly.
When a preemptible VM is at risk of being terminated, Compute Engine sends a preemption notice in the form of an ACPI G2 Soft Off signal. This notice gives you a brief window—up to 30 seconds—to execute a shutdown script and perform any necessary cleanup before the instance is forcibly stopped. If the instance does not stop within this period, it receives an ACPI G3 Mechanical Off signal, transitioning it to a TERMINATED state. It's crucial to design your applications to handle this preemption gracefully to avoid data loss or incomplete tasks.
In production, you need to be aware of several limitations. Preemptible instances cannot live migrate to regular VMs, nor can they automatically restart during maintenance events. They are also not covered by any Service Level Agreement (SLA), meaning you cannot rely on them for critical workloads. If a preemptible instance is stopped less than one minute after creation, you won't be billed for it, which can be a silver lining for testing. Additionally, you won't incur charges for Local SSD disk usage or GPUs if the instance is preempted shortly after starting. Understanding these nuances will help you leverage preemptible VMs effectively while avoiding pitfalls.
Key takeaways
- →Leverage preemptible VMs for cost savings of up to 91% compared to standard instances.
- →Implement shutdown scripts to manage preemption notices and ensure proper cleanup.
- →Be aware that preemptible instances cannot be live migrated or automatically restarted.
- →Remember that preemptible instances are not covered by any SLA, making them unsuitable for critical workloads.
- →Take advantage of billing exemptions if instances are preempted within the first minute.
Why it matters
In production, using preemptible VMs can significantly reduce costs, allowing you to allocate resources more efficiently. However, understanding their limitations is crucial to avoid disruptions that could impact your applications.
When NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsSimple, affordable cloud — VMs, Kubernetes, and managed databases in minutes. Trusted by 600,000+ developers. Spin up a Droplet in 60 seconds.
Try DigitalOcean →Mastering Cloud Run Functions: Best Practices for Production
Cloud Run functions can simplify your serverless architecture, but only if you design them correctly. Learn why idempotent functions are crucial and how to manage temporary files effectively. This article dives into the best practices that ensure your functions run smoothly in production.
Mastering Cloud Run Functions: Runtime Support You Can't Ignore
Cloud Run functions offer a robust way to deploy serverless applications, but understanding runtime support is crucial. With regular updates for security and bug fixes, knowing how these runtimes work can save you from future headaches.
Mastering Pub/Sub Subscriptions with Filters: A Practical Guide
Filtering messages in Pub/Sub subscriptions can drastically reduce unnecessary processing and costs. By using attributes for filtering, you can ensure that only relevant messages reach your subscribers. Dive in to learn how to implement this effectively in your projects.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.