Starting a VM instance automatically when a user attempts to connect

51 views
Skip to first unread message

Kevin Monagle

unread,
Apr 13, 2016, 2:21:40 PM4/13/16
to Google App Engine
Looking for a high level approach to this problem...

Let's say I created 10 VMs. In order to minimize costs, I'd like to observe those VMs and shut them down when no one is connected to them. This part is easy...I can ping the machine and use the Google API to simply shut the machine down if no one is connected.

On the flip side, I'd like to automatically start the machine up when a user attempts to connect. I don't want this to be a manual process.

Users will always connect to my app on the VM via http on a particular port. Would it be possible to put some kind of proxy in front of my 10 VMs that would intercept incoming connections and start the target VM if it was shut down? And then forward the connection to the target once it's running?

Does anybody have any experience with this? Or does Google offer this functionality in any form?   

I'm using NodeJS in my app implementation. Any feedback/ideas would be appreciated. Thanks!  

Nick (Cloud Platform Support)

unread,
Apr 13, 2016, 7:40:33 PM4/13/16
to Google App Engine
Hey Kevin,

This is essentially how autoscaling for vanilla App Engine works. In order for it to work with VMs, you'll need to do exactly as you said, have a front-end proxy which i) accepts the user request ii) tells a VM to spin up iii) serves a waiting page to the user which will periodically check back through the proxy to see if the VM is ready iv) redirect to the VM once it's up. If an available VM exists, you won't need to spin one up and can immediately redirect the user.

This is a pretty common pattern generally, although even with Managed VMs, you can use auto-scaling with a minimum of 2 instances, which should cover pretty much any scenario. Finally, Compute Engine also has an autoscaler.

Hope this was helpful!

Nick

Cloud Platform Community Support
Reply all
Reply to author
Forward
0 new messages