问题描述
在我的应用程序(Google App Engine标准Python 2.7)中,当实例启动时(在第一个请求时),初始化全局变量中的一些标志(从memcache / Datastore读取值)。这些变量值不会经常变化,每月只发生一次或发生紧急情况时(例如,当谷歌应用程序引擎Taskqueue或Memcache服务运行不正常时,发生的情况每年不会超过GC状态报告的每年两次,但会严重影响我的应用和我的客户: ): 正如
但另一种解决方案可能是:
$ b $ 1)发送一个关机消息/命令给我的应用程序或服务的所有实例
2)向我的应用程序或服务的所有实例发送重新启动消息/命令
我只使用自动缩放 ,所以我不能发送针对特定实例的请求(我可以使用GAE管理API获取活动实例的列表)。
在Python GAE中以编程方式执行此操作?在GCP控制台中手动执行操作很简单,但对于50多个实例,这很痛苦...
可以使用Google Cloud API停止所有实例。然后他们会自动缩小到所需的水平。我的第一次尝试是这样一个过程:
- 配置项已更改
- 当前的实例列表已从API中枚举
- 实例在一段时间内关闭,允许新实例启动并替换它们,以及配置更改对时间敏感。可能每60秒关闭一次。
关于使用API,您可以使用gcloud工具():
GET https://appengine.googleapis.com/v1/{parent=apps/*/services/ * / versions / *} / instances
DELETE https://appengine.googleapis.com/v1/{name=apps/*/services/*/versions/*/instances/*}
In my app (Google App Engine Standard Python 2.7) I have some flags in global variables that are initialized (read values from memcache/Datastore) when the instance start (at the first request). That variables values doesn't change often, only once a month or in case of emergencies (i.e. when google app engine Taskqueue or Memcache service are not working well, that happened not more than twice a year as reported in GC Status but affected seriously my app and my customers: https://status.cloud.google.com/incident/appengine/15024 https://status.cloud.google.com/incident/appengine/17003).
I don't want to store these flags in memcache nor Datastore for efficiency and costs.
I'm looking for a way to send a message to all instances (see my previous post GAE send requests to all active instances ):
As stated in https://cloud.google.com/appengine/docs/standard/python/how-requests-are-routed
but another solution could be:
1) Send a shutdown message/command to all instances of my app or a service
2) Send a restart message/command to all instances of my app or service
I use only automatic scaling, so I'cant send a request targeted to a specific instance (I can get the list of active instances using GAE admin API).
it's there any way to do this programmatically in Python GAE? Manually in the GCP console it's easy when having a few instances, but for 50+ instances it's a pain...
It's possible to use the Google Cloud API to stop all the instances. They would then be automatically scaled back up to the required level. My first attempt at this would be a process where:
- The config item was changed
- The current list of instances was enumerated from the API
- The instances were shutdown over a time period that allows new instances to be spun up and replace them, and how time sensitive the config change is. Perhaps close on instance per 60s.
In terms of using the API you can use the gcloud tool (https://cloud.google.com/sdk/gcloud/reference/app/instances/):
gcloud app instances list
Then delete the instances with:gcloud app instances delete instanceid --service=s1 --version=v1
There is also a REST API (https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions.instances/list):
GET https://appengine.googleapis.com/v1/{parent=apps/*/services/*/versions/*}/instances
DELETE https://appengine.googleapis.com/v1/{name=apps/*/services/*/versions/*/instances/*}
这篇关于GAE关闭或重新启动服务/应用程序的所有活动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!