Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Auto-suspend Compute Engine VM upon idle?

It appears that a Compute Engine VM cannot be configured to auto-suspend if the VM is idle for X minutes. 

This would be a very useful feature to reduce VM costs, so why doesn't it exist?

Cynically, I'm guessing that this feature does not exist because GCP likely makes a lot of money from users who forget to suspend/stop their VMs. 

1 8 3,654
8 REPLIES 8

You can detect and take action on idle vms with this:

https://cloud.google.com/compute/docs/instances/idle-vm-recommendations-overview

 

Thanks nestors! Are there any plans on adding "suspend VM after idle for X minutes" to the Compute Engine VM console? It would be helpful to have that option when setting up new VMs. 

While the "Idle VM recommendations" docs are helpful, they are buried in the docs (Compute Engine => Optimize => Resource Utilization => Manage Idle VM Recommendations). 

Also,  it appears that the "idle VM recommendations" is an active process, where the user must run `gcloud recommender recommendations` and then interpret the output and act upon the interpretation. The passive approach of setting auto-suspend when creating VMs would be ideal in many use cases.

Lastly, running `gcloud recommender recommendations` and then `gcloud compute instances stop VM_NAME --zone=ZONE` for *each* VM is very cumbersome. More automated solutions could be quite useful.

 

I'm not aware of any other way to check for idle instances unless you decide to create an alert with cloud monitoring checking for CPU usage (or any method you consider to decide an instance is idle).
Anyway, I guess it all depends on the scenario you are looking for. If you have several VMs processing requests and you want to avoid having many idle instances when there are no requests, I think you should re architect your app to use Managed Instance Groups and autoscaling. If you have a container processing requests, just go with Cloud Run, you can downscale to 0 with that.




I guess it all depends on the scenario you are looking for

I'm simply looking for a GCP Compute Engine console configuration option in which I can set the VM to auto-suspend upon idle for X minutes. This would be extremely useful for interactive data analyses (e.g., running Jupyter notebooks on a VM).

should re architect your app to use Managed Instance Groups and autoscaling

There seems to be an assumption among the GCP docs that Cloud Engine is used for running apps, but many use VMs for other tasks (e.g., ad-hoc analyses of data with Jupyter notebooks or RStudio).

Surely it will be nice to have, but that feature doesn't exist today.

You can add feature requests (or upvote existing feature requests) here:

https://cloud.google.com/support/docs/issue-trackers

 

I've implemented a cloud function that turns my analyst VMs off each night after 11:30 or so based on an "auto_off" and "auto_on" boolean label I assigned to each.   I've had a to-do list item for quite some time to check if the VMs were active and skip the "auto_off" function in case they were using them, but after a year and a half nobody's complained about their VM turning off in the middle of working...   I would be interested if anybody has figured out a reliable way of checking utilization or activity.   Only issue is that using Jupyter and saving notebooks every so often doesn't really use a lot of resources and would be pretty undetectable unless they run intensive models.

The instance scheduler feature is pretty limited... 

I've implemented a cloud function that turns my analyst VMs off each night after 11:30

Why must users go though so much hassle to suspend/stop running VMs? 

 Only issue is that using Jupyter and saving notebooks every so often doesn't really use a lot of resources and would be pretty undetectable unless they run intensive models.

An average % idle threshold could be used (e.g., <15% cpu usage for the past 15 minutes) to account for low levels of activity (e.g., auto-saving Jupyter notebooks). 

Hey there, I just randomly came across your post here. I have had the same situation where I had to pay for VMs that I forgot to stop when I finished my on-off/ad-hoc tasks. It made me go after a robust solution. I have a micro SaaS ready that does exactly what I, you, and perhaps millions more out there are looking for, to stop a VM based on common idle scenarios.

Unfortunately, I will start with support for AWS and Linux-based VMs only. If this sort of pilot project gets even small traction, I will soon follow through by adding support for Mac, Windows, and also on GCP, and Azure, at the least. The good part though, adding support for other platforms and OSes will be a lot quicker.

You can check out our LinkedIn for now. We are expecting a rollout in about a month.
https://www.linkedin.com/company/costshake