Search code examples
javagoogle-app-enginegoogle-compute-enginetask-queue

How do I create a short-lived, single task Google Compute Engine instance?


Question: How to create a lightweight on-demand instance, preconfigured w/ Java8 and my code, pull a task from a task queue, execute the memory-intensive tasks, and shut itself down. (on-demand, high memory, medium cpu, single task executors)

History: I was successfully using Google App Engine Task Queue in Java for "bursty" processing of relatively rare events - maybe once a week someone would submit a form, the form creates ~10 tasks, the system would chew up some memory and CPU cycles thinking about the tasks for a few minutes, save the results, and the webpage would be polling the backend for completion. It worked great within Google App Engine - Auto scaling would remove all idle instances, Task Queues would handle getting the processing done, I'd make sure not to overload things by setting the max-concurrent-requests=1, and life was good!

But then my tasks got too memory intensive for instance-class: F4_1G 😢 I'd love to pick something with more memory, but that isn't an option. So I need to figure something out.

I think my best bet is to spin up a generic instance using the API com.google.api.services.compute.model.Instance but get stopped there. I'm so spoiled with how easy the Task Queue was to build that I'd hate to get lost in the weeds just to get the higher memory instance - I don't need a cluster, and don't need any sort of reliability!

  1. Is this a docker container thing?
  2. Is it going to be hard auth-wise to pull from the Pull Queue outside of GAE?
  3. Is it crazy to spin up/down an instance (container?) for each task if a task is ~10 minutes?

I found some similar questions, but no answers that quite fit:


Solution

  • I would have a read about GAE modules. These can be set to use basic scaling so an instance gets created on demand, then expires some time later, set by you in your appengine-web.xml using something such as:

    <basic-scaling>
     <max-instances>2</max-instances>
     <idle-timeout>5m</idle-timeout>
    </basic-scaling>
    

    If the module processes requests from a task queue then is has 10 minutes to get its job done, which is probably ample for many tasks.