19

One of the most irritating things about using GAE for a brand new app is having to deal with instances being fired back up if no one has hit your servers in 15 minutes. Since the app is new, or just has few users, there will be periods of great latency for some users who have no clue that instances are being "spun up"

As far as I see it you have these options based on the docs:

Use manual-scaling and set the number of instances to 1.

When you use manual-scaling, whatever number of instances you set it to is what you will have - no more, no less. This is clearly inefficient as you may be paying for unused instances and instances are not automatically added/removed as traffic increases/decreases

Use basic-scaling and set idle-timeout to something like 24hrs or 48hrs.

This would keep your instance running as long as someone queries your API at least once within that time period.

Use automatic-scaling with min-idle-instances and warm-up requests enabled.

This does not work as intended. According to these docs:

if your app is serving no traffic, the first request to the app will always be a loading request, not a warmup request.

This does not solve our problem because if zero instances are running, then there is nothing to warm-up in the first place. Thus you still get latency on the first request.


The desired effect I would like to have is to always have an instance running and then scale up from there if traffic is increased (and of course scale down but never go below one instance). It would be like automatic-scaling but with 1 instance always running.

Is this possible in GAE? Or am I missing something?

For now, my temporary solution is to set my app to manual-scaling with 1 instance so at least my app is useable to new users.

Micro
  • 10,303
  • 14
  • 82
  • 120
  • 3
    A bit hackish but: Configure a health check via stackdriver. Free request every few minutes to keep you instance alive – zapl Jun 13 '16 at 00:12
  • @zapl could you provide more information on how you set this up exactly? – Micro Jun 13 '16 at 02:17
  • https://cloud.google.com/monitoring/quickstart-lamp#gs-checks (or any other uptime check that issues simple http(s) requests periodically) – zapl Jun 13 '16 at 10:08
  • @zapl I have found that your stackdriver method does not keep an instance on... – Micro Jun 29 '16 at 19:14
  • seems to work for me, took a while but checks started an idle gae app and keeps it running so far. – zapl Jun 29 '16 at 22:09
  • @zapl For me it did not even start an instance - despite the logs showing that checks with stackdriver are being made. – Micro Jun 29 '16 at 22:22
  • @zapl on a side note.. any clue who to remove an app from stackdriver - i can't for the life of me figure it out. – Micro Jun 29 '16 at 23:50
  • Hrm, it seems you cannot for the initial project because it is the ["parent"](https://cloud.google.com/monitoring/accounts/#account-project) account of the stackdriver account and I've not seen a way to close the stackdriver account either. – zapl Jun 30 '16 at 08:50

1 Answers1

14

One solution that I tried and works is to use automatic-scaling and issue a cron job that just executes any public static api method (it can just take zero params and return null) in a servlet every 5 minutes or so.

See here for how to set that up: https://cloud.google.com/appengine/docs/java/config/cron#creating_a_cron_job

This gives you the benefit of 28 free instance hours vs using manual scaling's 8 hours

Micro
  • 10,303
  • 14
  • 82
  • 120
  • Can you share the relevant contents of your appengine-web.{xml|yaml} file that you're using to accomplish this? I'm curiosu. – Cyde Weys Dec 22 '16 at 18:55
  • @CydeWeys There really isn't anything in there that is relevant to this. Just look at the link on how to set up a cron job - it's all there. – Micro Dec 22 '16 at 21:16
  • 3
    is this seriously the only way to do this? It can't be done in configurations? thanks for sharing your answer – ahong Apr 30 '19 at 08:12
  • 1
    I just want to keep this thread alive because in all honesty this is crazy. I mean we've also set up a service pinging our sites every 5 minutes to avoid cold booting instances but i mean, that's an insane solution. It's bizarre that Google, a company that lives off of fast response times is selling a service that their own Lighthouse complains about if the site has been unvisited for 15 minutes.. – lowkey Dec 13 '21 at 23:46
  • Won't this only send a single request to the given endpoint, but only on _one_ instance in the pool? If you, say, set min_instances to 2, then you're really only keeping 1 of those two instances "warm", right? – RavenHursT Mar 01 '22 at 08:09