Controlling costs

168 views
Skip to first unread message

Joshua Smith

unread,
Dec 20, 2019, 9:47:55 AM12/20/19
to Google App Engine
I have a not-for-profit site that I run for a variety of local governments. Over the past year, my costs have been increasing and I’m looking for ways to lower them.

I’ve had some luck with robots.txt and the firewall (damn there are a lot of non-robot-compliant crawlers running from Azure IP addresses). But the bottom line hasn’t changed much.

A big cost driver has been Instances. Looking at my dashboard I see that auto-scaling seems to like to leave around a lot of idle instances:


Looking at the docs, I was pleased to see that at some point, apps got more control over auto-scaling. Accordingly, I tried adding this to app.yaml:

automatic_scaling:
  max_instances: 3
  max_idle_instances: 1
  max_pending_latency: 100ms
  max_concurrent_requests: 20

Alas, if I try to deploy (I’m still using python 2.7 and the Launcher), I get this error:

appcfg.py: error: Error parsing app.yaml: Unexpected attribute 'max_instances' for object of type AutomaticScaling.
  in "app.yaml", line 8, column 18.

Launcher says it’s up-to-date, but I’m sure it isn’t. Is this simply a matter of finding and installing the latest Launcher app? I’ve been avoiding that because I know google wants me to stop using it, so I have been in “if it ain’t broke, don’t fix it” mode.

-Joshua


Vitaly Bogomolov

unread,
Dec 20, 2019, 2:09:09 PM12/20/19
to Google App Engine
Hi, Joshua.

try to change automatic_scaling section to:

automatic_scaling:
  max_idle_instances: 1
  min_idle_instances: 1
  max_concurrent_requests: 20

BTW, I have the apps, that three times more load, that I see at your image. These apps fit to free quota.

WBR, Vitaly

Kaan Soral

unread,
Dec 20, 2019, 2:10:09 PM12/20/19
to Google App Engine
Try removing: max_instances: 3
You can set: max_idle_instances: 0
Then: min_pending_latency: 200ms
Or even more
This way, instances will only fire up when they have to

Joshua Smith

unread,
Dec 20, 2019, 2:22:00 PM12/20/19
to Google App Engine
Thank you both!

I love when the documentation is wrong :)

I’m trying:

automatic_scaling:
max_idle_instances: 0
max_pending_latency: 200ms
max_concurrent_requests: 20

So far, the site is still quite responsive, and there are not a bunch of idle instances lying around. So yay!

-Joshua

Joshua Smith

unread,
Dec 30, 2019, 3:31:13 PM12/30/19
to Google App Engine
Seems I celebrated too soon. Looking at the logs for the past few days, it seems I have a pretty consistent 2 idle instance, despite my max_idle_instances set to zero.

My app.yaml has:

runtime: python27
api_version: 1
threadsafe: yes

automatic_scaling:
  max_idle_instances: 0
  max_pending_latency: 200ms
  max_concurrent_requests: 20

If I’m not being charged for these idle instance, then that’s fine, but I can’t figure out how to tell if that’s the case.

Any advice?

Vitaly Bogomolov

unread,
Dec 30, 2019, 4:41:33 PM12/30/19
to Google App Engine
my advice is the same.

Joshua Smith

unread,
Dec 30, 2019, 4:55:13 PM12/30/19
to Google App Engine
So the theory is that if you set max_idle_instances to 0 it gets ignored, but at 1 it is obeyed?

That’s plausible.

I wish google would document this.

Anyway, I’ll try this and report back…

-Joshua

Kaan Soral

unread,
Dec 31, 2019, 12:30:45 AM12/31/19
to Google App Engine
No, don't report it just yet, also I don't agree with Vitaly's advice of always keeping an idle instance - in addition to your setting, if you set a "min_pending_latency" and DON'T set a "max_pending_latency" - you'll get the minimal costs, "max_pending_latency" is like saying "Oh my god there's q request spin up an idle instance fast!" while with a "min_pending_latency" - it might make someone wait a bit with a low %, people wait a bit anyway, since consequent requests are fast, they won't notice it anyway

Now, actually what happens, find a graph that clearly shows billed instances, there being idle instances doesn't mean that you are billed for them! they are free

Pierre-Yves Blain

unread,
Jan 1, 2020, 12:55:48 PM1/1/20
to Google App Engine
A few things worth mentioning:

1- The "max_instances" element under "automatic_scaling" is a parameter that cannot be set in app.yaml if using 'appcfg'. This is why you were getting the deployment error, and is documented here [1]. You should instead set this specific parameter in the API explorer [2] or the Admin API [3].

2- Setting "max_idle_instances: 0" is invalid, as the accepted range for the value is between 1 and 1,000 which is explained here [4]. Part of the auto_scaling process requires to have instances in an idling state at some point, so setting it to 0 doesn't make sense. You may set this value to a lower value than what would be enforced by the default value "automatic", which will lower costs but can degrade performance in the face of volatile load levels. The goal is to strike a balance between costs and acceptable performance per your own standards.

3- The "min_idle_instances" [5] is a value you may be interested in reading more about as well, as this is one way to reduce costs but also necessitate tuning to make sure the desired performance is also met, as is the case with the "max_idle_instances" setting. For example, if there are long stretches of time where there are no requests, the number of idle instances could go to zero which would incur no costs. Doing so will generate a cold start from the next loading request [6], which will have a higher latency. If you prefer to always have an idle instance ready to serve request, this reduces latency by eliminating the loading requests but incur higher costs. You could also look into warmup requests [7].

4- Idle instances are not free as mentioned here [4], and explained more specifically here [8].

Reply all
Reply to author
Forward
0 new messages