Google App Engine automatic scaling not keeping instance alive - google-app-engine

I am struggling to understand the scaling for my NodeJS app running on Google App Engine (Standard). I'm trying to use automatic_scaling but would always like to have 1 instance ready to serve. Reading through all docs this should be easily possible by using the min_instances property as below. I have tried the blow with F1 and F2 instances.
runtime: nodejs10
instance_class: F2
automatic_scaling:
min_instances: 1
max_instances: 10
min_idle_instances: 1
max_concurrent_requests: 70
target_throughput_utilization: 0.8
I can still monitor my instances going down to 0 instances though. The first request then takes a few seconds until the instance is back up and running. Am I missing something here?

Related

Google App Engine - Frequently getting logged out of the deployed .NET application

Frequently getting logged out from the deployed application, session is not working/timing out too soon in the deployed .net 5 application in the App Engine flex.
Below are the warning logs which i'm getting, not sure are they related to session issue or not.
Logged warnings
Are there any session settings which needs to be done within GCP console which i'm unaware of?
I've found similar configuration for Java applications but nothing for .NET.
Reference:- https://developers.google.com/appengine/docs/java/config/appconfig?csw=1#Java_appengine_web_xml_Enabling_sessions
Apparently, I found the issue and fixed it as mentioned below
app.yml file is to be modified with custom env instead of the default which Google App Engine flex provides with 2 instances, like below -
Modified app.yml -
runtime: custom
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Here we are explicitly mentioning the instances and power required to run our app.
The default deployment uses multiple instances, and the sessions seem to be stored privately per instance. If you reload the page a few times, you will see your session exists sometimes and does not exist other times as you toggle between instances.
Hence by providing 1 instance we are restricting our session to be then and there hence resolving the above issue with it.

Google App Engine Manual Scaling Prevents Restart

I have a python app engine that handles api results and it's stateful. However it seems that after a few hours of inactivity (no requests), the server shuts off, resetting all states, and when a new request is made, it's listening again.
But the states are reset. I want the server to actively remain unchanged 24/7 and not reset/restart as I want to maintain states.
I have configured as per documentation but it's still restarting, I am not sure what's wrong
Here is my app.yaml:
runtime: python37
entrypoint: python main.py
manual_scaling:
instances: 1
In App Engine the general recomendation is to create stateless applications as mentioned on the documentation
Your app should be "stateless" so that nothing is stored on the instance.
As an alternative for the application not to get restarted you can deploy it on Compute Engine, As that service is a Virtual Machine you can have total control of the states.

Google App Engine Node application: prevent downscaling to 0 instances

I've deployed a Node.js application on Google App Engine (standard environment).
I've noticed that after 10 minutes of inactivity, the app is undeployed and the number of instances goes to 0.
So the first request I make takes 4-5 seconds to reply.
This is my app.yaml
runtime: nodejs10
service: backend
automatic_scaling:
min_instances: 1
I added also min_idle_instances, but the issue seems not solved:
You can use ‘min_idle_instances’ instead of ‘min_instances’.
When using ‘min_instances’, you define how many instances you would like spun up when your app receives traffic.
When you use ‘min_idle_instances’, you define how many instances you want to keep alive. These instances are kept idle and running in the background in order to receive traffic.
Do note that it may increase your monthly invoice as those instances are live, whether or not they are receiving traffic.
I switched from standard to flexible environment, and it seems really better

Use App Engine Modules to run cron job in F1 instance class

I have a frequent cron job in my app on google app engine standard, and it's using tons of instance hours to perform a quick task. I find that the instance hours problem goes away if I switch the app to F1 in app.yaml, but the web front-end needs more power (been using F4_1G).
It seems like a simple solution would be to use App Engine Modules to run the cron job on F1 while keeping the rest of the app on F4_1G, but the documentation is short on actual code. Can somebody please show how this can be accomplished?
This doesn't actually require code changes, it's controlled by your projects configuration (yaml) files.
You create a service (formerly module) by specifying it in a separate .yaml file, deploying the service, and then telling your cron job to run on that service.
Let's assume you want to create a service called "lightweight".
Start by copying your existing app.yaml to lightweight.yaml,
add (or modify) the "service" line to read "service: lightweight", and update the application instance to f1.
Optionally, clean up the handlers so that only the ones you need for your cron instance are present
eg, lightweight.yaml:
application: yourapp
service: lightweight
version: 0-4
runtime: python27
api_version: 1
threadsafe: true
instance_class: F1
handlers:
- url: /mycronjob
script: main.app
login: admin
Then, in your cron.yaml, specify the service as your target.
cron:
- description: example
url: /mycronjob
schedule: every 5 minutes
target: lightweight
Once that is done, deploy lightweight.yaml and cron using gcloud or appcfg.
Once deployed, your cron job will run on the lightweight service, using an f1 instance. You can also access the lightweight service directly in your browser lightweight.yourapp.appspot.com

is possible to share VM or groups of VM with several services in App Engine?

I'm working with a project that will use Microservice architecture, I'm using App Engine, each service of my project is deployed as a service in App Engine, each service in App Engine uses one or more VM Machine.
I'm using the App Engine Flexible Environment because I use nodejs and Python 3.4
https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
I know I can limit the number of instance for each service using the follow settings for app.yaml
automatic_scaling:
min_num_instances: 1
max_num_instances: 10
cool_down_period_sec: 120 # default value
cpu_utilization:
target_utilization: 0.5
resources:
cpu: .1
memory_gb: 0.18
disk_size_gb: 10
I know there is Standard Environment that we have some free quota and will be charged after the app consumes more than of the free quota, this is really useful and is what I need but I can't use Nodejs and Python3.4 with that environment.
Can I set which VM or group of VM the apps will use? my goal is try to save money about the instances because maybe we will have several services, it can be expensive mainly at the beginning !
It's not possible at the moment. Even if each app runs in a container it uses a separate virtual machine(which kinda makes no sense). You can't even define the containers of the same app to run on a specific VM or a specific group of VMs.
I'm confident that this will change in the future but based on the records this may take 1 - 2 more years or even more so don't hold your breath .
I assume you are already aware that flexible/managed VM environment require at least one instance to be always on and it's not covered by a free quota.
It's worth to note that Amazon Beanstalk allows you run multiple containers on a single instance.

Resources