Home > Mobile >  Higher than expected number of GAE instances
Higher than expected number of GAE instances

Time:11-02

I run a nodejs backend on Google App Engine for my website app (which is hosted statically elsewhere). My QPS is very low:

enter image description here

However my number of instances regularly goes above 1, to 2 and sometimes as high as 3 or 4. This blows past the free quota and I start have to pay.

enter image description here

My cost were below $0.1 per month but now are regularly above $8 which is a worrying trend. My user base or their patterns haven't really changed significantly to explain this (and as mentioned the QPS are low IMHO).

I noticed that the memory usage is relatively high and I'm wondering if I should investigate potential memory leaks in my app.

More background on the app: it mostly handles auth and fetches and stores data into MongoDB Atlas.

CodePudding user response:

I would go with a 2 step process

  1. First 'temporarily' set your maximum_instances to 1 in your app.yaml file. This means your server will only spin up 1 instance. This comes with a risk that if you have a spike in traffic, it might be slow for some people.

app.yaml

automatic_scaling:
  max_instances: 1
  1. Then investigate if you have memory leaks in your code and see how you can optimize your code. If you discover your issues and fix it, you can remove the max_instance or raise the value.

CodePudding user response:

From the screenshots you’ve shared, I can see that your number of instances increases as your memory usage does, and decreases in the same way. Therefore, I would recommend increasing the amount of memory that is assigned to every instance to use less instances for serving your application. As this guide recommends to begin testing your application:

start with a lower machine (1 core CPU and 1 GB RAM) and increase the minimum instances that the App Engine should spawn instead

Also, the guide says that:

Since App Engine bills you on the number of Cores and RAM used per hour, you can save up to 40% of your costs by using the former setup with lower machines

From that, it is better to have more memory allocated to an instance to avoid excessive costs.

In the App Engine pricing page, it says that:

Billing for the memory resource includes the memory your app uses plus the memory that the runtime itself needs to run your app. This means your memory usage and costs can be higher than the maximum memory you request for your app.

In your app.yaml configuration file, you can set the parameter memory_gb that is set to 0.6 GB by default.

The requested memory for your application, which does not include the ~0.4 GB of memory that is required for the overhead of some processes. Each CPU core requires a total memory between 0.9 and 6.5 GB. To calculate the requested memory: ´memory_gb = cpu * [0.9 - 6.5] - 0.4´

Additionally, you should check your code for memory leaks to avoid your application consuming more memory than expected.

Finally, you can use the pricing calculator to estimate the costs for your application based on the tweaks you do on your application.

  • Related