Search code examples
google-app-engineautoscaling

How to instruct AppEngine to keep 1 instance alive in standard environment


I have a web and mobile Flutter app with low traffic which uses a AppEngine service as backend. I noticed from the logs that the instances get shut down automatically and the app requests start to fail. For some weird reason, if I start to query the app from desktop browser, the AppEngine instance starts again and everything works fine.

I tried to play with scaling settings using

runtime: python39
env: standard
instance_class: F1
automatic_scaling:
  max_instances: 1
  min_instances: 1

I would expect with these settings the number of instances to always be 1 but I still see the same behaviour: the app goes down when inactive.

I inspected the app and the environment I am using is standard.

How can I achieve a simple deployment with 1 active instance all the time?

I don't want to use any fancy scaling feature for now. The app is pretty simple and 1 instance is enough.


Solution

  • Did you enable warmup requests? The documentation says

    Warning: For this feature to function properly, you must make sure that warmup requests are enabled and that your application handles warmup requests.

    Also, try to see if you can reduce the startup time when your App receives a new instance request by only importing libraries/initializing stuff when they're needed and not at the beginning of your module .e.g. if you're storing stuff in cloud storage, only import the cloud storage library and initialize it when you actually need to store stuff and not whenever the python file is loaded