0

I was trying to find out a way to schedule stop/start the latest version of app engine in google cloud, but couldn't find any way for that. I just found gcloud command for stopping/starting a specific version, but don't know how can I schedule gcloud command.

We have manual scaling standard app engine , and I want to stop it every night at specific time, and re-start it again in morning. What is the best way to do that?

My implemented solution is separate python cloud function for stopping and starting the app engine, then scheduling those functions at the specific time

https://cloud.google.com/appengine/docs/standard/python3/runtime#environment_variables

Thanks,

mary
  • 369
  • 1
  • 5
  • 16
  • You can stop app engine versions if the scaling is set to `manual`. Also you can use Cloud Scheduler to call the App Engine API and stop/start versions as needed. Keep in mind that asking recommendations is off-topic so please try something and investigate on your own and comeback with any specific question you may have – Puteri Apr 20 '23 at 03:12
  • Thanks for your response, I have created a cloud function for stopping/starting the app engine, then I want to schedule calling that cloud function at the specific time, but first I am not sure is it the best and easiest solution or not – mary Apr 20 '23 at 04:55

2 Answers2

1

Finally I could disable/serving the app engine in cloud function, instead of stopping a specific version.

1- Creating a cloud function which is triggered by pub/sub

import os
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials


def disableEnable(event, context):
   credentials = GoogleCredentials.get_application_default()
   appengine = discovery.build('appengine', 'v1', 
     credentials=credentials)
   apps = appengine.apps()
   APP_NAME = os.getenv("APP_NAME")
   messageServingStatus = event['message']

   # Get the target app's serving status
   target_app = apps.get(appsId=APP_NAME).execute()
   current_status = target_app['servingStatus']

   # Disable target app, if necessary
   if current_status == 'SERVING' and messageServingStatus == 'STOPPED':
     print(f'Attempting to disable app {APP_NAME}...')
     body = {'servingStatus': 'USER_DISABLED'}
   if current_status == 'USER_DISABLED' and messageServingStatus == 
     'SERVING':
     print(f'Attempting to enable app {APP_NAME}...')
     body = {'servingStatus': 'SERVING'}   
   apps.patch(appsId=APP_NAME, updateMask='serving_status', body=body).execute()

2-create two scheduler with specific frequency (FOR ENABLING/DISABLING appengine) Target Type= Pub/Sub Select created Pub/sub topic name

mary
  • 369
  • 1
  • 5
  • 16
0

App Engine Standard is a serverless product managed by Google. It scales up and down (up to 0) automatically (in automatic and basic mode). In manual mode, the scaling is not so elastic, and you set the number of instances that you want, it's flat.

The power of App Engine is that elasticity. I use it only in automatic mode. There are some trade off like the start up time when you scale from 0 (also called cold start), and the instance live duration (that you don't manage, after a while with no request handling, the instance is offloaded).

But it also means you have nothing to manage to scale up and down. If there is traffic, you have instances. If you have nothing (the night) all the instance are shut down automatically and you pay nothing.


There are some counterpart, like the max duration of request processing, the incapacity to perform background processing and stuff like that.

Let us now more about your app constraint to review with you if app engine is the best fit for you.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Thanks for comprehensive response, We used to use automatic scaling app engine, but there was a timeout error after 10 minutes for some requests, so we had to change it to manual . But manual scaling continuously runs the numbers of instances, for decreasing the cost, we need to stop start instance – mary Apr 20 '23 at 08:21
  • In terms of using cloud function for stop/starting latest version of app engine, I am using app engine patches(apps.services().versions().patch(....), , is there any way to fetch the latest running version of app engine instance from cloud function? – mary Apr 20 '23 at 08:25
  • Have a look at this [Stackoverflow Link](https://stackoverflow.com/a/66467473/18265702) and the [Documentatiom](https://cloud.google.com/scheduler/docs/tut-pub-sub). – Sandeep Vokkareni Apr 20 '23 at 11:57
  • I tested by os.environ['GAE_VERSION'], but cloud function couldn't find GAE_VERSION key and raised an error. I assume this solution would work in an app running inside appengine, but won't fetch the latest version of instance from cloud function . – mary Apr 20 '23 at 12:10
  • @guillaume blaquiere , would you please let me know how manual scaling with the specific numbers of instances behaves if requests increase? Does it create a queue for processing the requests? Does it just cause the performance issue and slowness in the busy days? Doesn't it support background processing? – mary Apr 20 '23 at 23:17
  • Manual scaling does not scale with the traffic, it's manual. However, because you ask for keeping a certain number of instance up, yes you can perform background process because you pay for it (for the CPU). You have a similar feature with the min instance parameter, to keep a certain number of instance up, but scale above if required (automatic scaling, or Min Instance with Cloud Run) – guillaume blaquiere Apr 21 '23 at 10:25