GAE关闭或重新启动服务/应用程序的所有活动实例 [英] GAE shutdown or restart all the active instances of a service/app
问题描述
在我的应用程序(Google App Engine标准Python 2.7)中,当实例启动时(在第一个请求时),初始化全局变量中的一些标志(从memcache / Datastore读取值)。这些变量值不会经常变化,每月只发生一次或发生紧急情况时(例如,当谷歌应用程序引擎Taskqueue或Memcache服务运行不正常时,发生的情况每年不会超过GC状态报告的每年两次,但会严重影响我的应用和我的客户: https://status.cloud.google.com/incident/appengine / 15024 https://status.cloud.google.com/incident/ 我不希望将这些标记存储在memcache中,也不希望将数据存储在数据存储中以提高效率和成本。 我正在寻找一种将消息发送到所有实例的方法(请参阅我以前的帖子 GAE向所有活动实例发送请求): 正如 https://cloud.google.com/appengine/docs/standard/python / how-requests-are-routed 注意:配置自动缩放的服务不支持定位实例或基本缩放。实例ID必须是0范围内的整数,直到运行的实例总数。无论您的缩放类型或实例类如何,都无法向特定实例发送请求,而无需在该实例中定位服务或版本。 但另一种解决方案可能是: 2)向我的应用程序或服务的所有实例发送重新启动消息/命令 我只使用自动缩放 ,所以我不能发送针对特定实例的请求(我可以使用GAE管理API获取活动实例的列表)。 在Python GAE中以编程方式执行此操作?在GCP控制台中手动执行操作很简单,但对于50多个实例,这很痛苦... 可以使用Google Cloud API停止所有实例。然后他们会自动缩小到所需的水平。我的第一次尝试是这样一个过程: 然后删除这些实例: 还有一个REST API( https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions.instances/list ): 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 Note: Targeting an instance is not supported in services that are configured for auto scaling or basic scaling. The instance ID must be an integer in the range from 0, up to the total number of instances running. Regardless of your scaling type or instance class, it is not possible to send a request to a specific instance without targeting a service or version within that instance. 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: In terms of using the API you can use the gcloud tool (https://cloud.google.com/sdk/gcloud/reference/app/instances/): Then delete the instances with:
There is also a REST API (https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions.instances/list):
这篇关于GAE关闭或重新启动服务/应用程序的所有活动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $ 1)发送一个关机消息/命令给我的应用程序或服务的所有实例
gcloud应用程序实例列表
gcloud app instances delete instanceid --service = s1 --version = v1
GET https://appengine.googleapis.com/v1/{parent=apps/*/services/ * / versions / *} / instances
DELETE https://appengine.googleapis.com/v1/{name=apps/*/services/*/versions/*/instances/*}
gcloud app instances list
gcloud app instances delete instanceid --service=s1 --version=v1
GET https://appengine.googleapis.com/v1/{parent=apps/*/services/*/versions/*}/instances
DELETE https://appengine.googleapis.com/v1/{name=apps/*/services/*/versions/*/instances/*}