Google App Engine - 始终在实例上自动扩展? [英] Google App Engine - automatic-scaling with always on instance?

查看:27
本文介绍了Google App Engine - 始终在实例上自动扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 GAE 用于全新应用程序的最令人恼火的事情之一是,如果 15 分钟内没有人访问您的服务器,则必须处理被重新启动的实例.由于应用程序是新的,或者用户很少,对于一些不知道实例正在启动"的用户来说,会有一段很长的延迟时间

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"

据我所知,您有这些基于 docs 的选项:

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

使用manual-scaling并将实例数设置为1.

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

当您使用 manual-scaling 时,无论您将其设置为多少实例,您都将拥有 - 不多也不少.这显然是低效的,因为您可能需要为未使用的实例付费,而且实例不会随着流量的增加/减少而自动添加/删除

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

使用 basic-scaling 并将 idle-timeout 设置为 24 小时或 48 小时之类的时间.

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

只要有人在该时间段内至少查询您的 API 一次,这将使您的实例保持运行.

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

使用 automatic-scaling 并启用 min-idle-instances 和预热请求.

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

这不符合预期.根据这些docs:

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.

我想要的预期效果是始终运行一个实例,然后在流量增加时从那里扩展(当然要缩减但永远不要低于一个实例).这就像自动扩展,但始终运行 1 个实例.

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.

这在 GAE 中可行吗?还是我遗漏了什么?

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

目前,我的临时解决方案是使用 1 个实例将我的应用设置为 manual-scaling,这样至少我的应用对新用户可用.

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.

推荐答案

我尝试过并有效的一个解决方案是使用自动缩放并发出一个仅执行任何公共静态 api 方法的 cron 作业(它可以只需要零参数并每 5 分钟左右在 servlet 中返回 null).

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.

请参阅此处了解如何设置:https://cloud.google.com/appengine/docs/java/config/cron#creating_a_cron_job

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

与使用手动扩展的 8 小时相比,这为您提供了 28 小时的免费实例时间

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

这篇关于Google App Engine - 始终在实例上自动扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆